Skip to content

bootstrap: Make main.rs a stub that calls into the library crate - #160829

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
Zalathar:bootstrap-main
Aug 11, 2026
Merged

bootstrap: Make main.rs a stub that calls into the library crate#160829
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
Zalathar:bootstrap-main

Conversation

@Zalathar

Copy link
Copy Markdown
Member

As with some other bootstrap tools (e.g. compiletest), bootstrap itself is built as a small binary crate (executable) that links to a larger library crate.

If there is non-trivial code in main.rs, then any items it touches need to be publicly exported from the library crate. Those public exports make it harder to identify unused code within bootstrap.

As far as I can tell, there is no compelling rule or principle that determines whether code should be in the entry point or in the library crate, other than historical inertia.

This PR therefore takes all of the code from main.rs, and moves it into a new file cli_main.rs within the bootstrap library crate. That avoids the need for any public exports other than cli_main::main itself.

There should be no change to bootstrap behaviour.


This change makes it possible to change all of bootstrap's pub items to pub(crate). That migration is left to a future PR, as it involves a fair bit of churn, and requires decisions on how to deal with pub items that are currently unused.

Prior art:

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Aug 10, 2026
@rustbot

rustbot commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

r? @clubby789

rustbot has assigned @clubby789.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789, jieyouxu

@Kobzol

Kobzol commented Aug 10, 2026

Copy link
Copy Markdown
Member

I would really like for rustc/Cargo to have a way of identifying unused pub items in libraries 😢 Marking everything with pub(crate) is annoying.

In fact, since rustc can now (AFAIK) detect unused pub in binaries, I wonder if we should do the opposite, and turn the whole of bootstrap from a library to a single binary, and reduce one Cargo compilation target 😆 Though we'd still need unit tests.

@Zalathar

Copy link
Copy Markdown
Member Author

IMO, trying to use pub as a shorthand for pub(crate) (but only if you happen to remember that you're in a binary crate) is more trouble than it's worth.

Consistently using pub(crate) for anything that doesn't strictly need to be pub is much easier to reason about.

@clubby789

Copy link
Copy Markdown
Contributor

@bors r+

@rust-bors

rust-bors Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 85b2700 has been approved by clubby789

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 10, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 10, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #158404 (trait_solver: normalize next-gen region constraints)
 - #160631 (Do not eagerly download rustfmt in bootstrap)
 - #160642 (mir: prohibit projection into scalable vec)
 - #160749 (MaybeDangling: ensure references fit inside the address space)
 - #160791 (Use recognizer functions for enums and tuple structs)
 - #160500 (Fix inaccurate description for crate and pathroot)
 - #160590 (Docs & bors: Replace mentions of libs-api with libs)
 - #160825 (Fix references to unsupported on sys::paths::unix)
 - #160852 (Use `remove_dir_all` for `./x clean`)

Failed merges:

 - #160829 (bootstrap: Make `main.rs` a stub that calls into the library crate)
@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 10, 2026
@rust-bors

This comment has been minimized.

This intermediate commit helps to preserve line history.
If there is non-trivial code in `main.rs`, then any items it touches need to be
publicly exported from the library crate. Those public exports make it harder
to identify unused code within bootstrap.
There is no need to re-export anything, so all `pub use` imports can be
simplified to `use` and merged with their siblings.
@rustbot

rustbot commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Zalathar

Copy link
Copy Markdown
Member Author

Rebased over import conflicts.

@bors r=clubby789

@rust-bors

rust-bors Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 55050c1 has been approved by clubby789

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 11, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 11, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #156338 (Implement derives for Reborrow and CoerceShared)
 - #158083 (Fix perf regression in `Read::read_to_end` on short reads due to not checking if the cursor has initialized bytes)
 - #160829 (bootstrap: Make `main.rs` a stub that calls into the library crate)
 - #159839 (point at closure return expression in non-`FnOnce` E0271 errors)
 - #160775 (interpret: treat pattern and unsafe-binder as ABI-transparent)
@rust-bors
rust-bors Bot merged commit 6a1d74f into rust-lang:main Aug 11, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Aug 11, 2026
rust-timer added a commit that referenced this pull request Aug 11, 2026
Rollup merge of #160829 - Zalathar:bootstrap-main, r=clubby789

bootstrap: Make `main.rs` a stub that calls into the library crate

As with some other bootstrap tools (e.g. compiletest), bootstrap itself is built as a small binary crate (executable) that links to a larger library crate.

If there is non-trivial code in `main.rs`, then any items it touches need to be publicly exported from the library crate. Those public exports make it harder to identify unused code within bootstrap.

As far as I can tell, there is no compelling rule or principle that determines whether code should be in the entry point or in the library crate, other than historical inertia.

This PR therefore takes all of the code from `main.rs`, and moves it into a new file `cli_main.rs` within the bootstrap library crate. That avoids the need for any public exports other than `cli_main::main` itself.

There should be no change to bootstrap behaviour.

---

This change makes it possible to change all of bootstrap's `pub` items to `pub(crate)`. That migration is left to a future PR, as it involves a fair bit of churn, and requires decisions on how to deal with pub items that are currently unused.

Prior art:
- #147506
@Zalathar
Zalathar deleted the bootstrap-main branch August 11, 2026 14:00
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Aug 11, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#158404 (trait_solver: normalize next-gen region constraints)
 - rust-lang/rust#160631 (Do not eagerly download rustfmt in bootstrap)
 - rust-lang/rust#160642 (mir: prohibit projection into scalable vec)
 - rust-lang/rust#160749 (MaybeDangling: ensure references fit inside the address space)
 - rust-lang/rust#160791 (Use recognizer functions for enums and tuple structs)
 - rust-lang/rust#160500 (Fix inaccurate description for crate and pathroot)
 - rust-lang/rust#160590 (Docs & bors: Replace mentions of libs-api with libs)
 - rust-lang/rust#160825 (Fix references to unsupported on sys::paths::unix)
 - rust-lang/rust#160852 (Use `remove_dir_all` for `./x clean`)

Failed merges:

 - rust-lang/rust#160829 (bootstrap: Make `main.rs` a stub that calls into the library crate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants