Skip to content

Remap compiler vs non-compiler sources differently (bootstrap side) #141751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented May 30, 2025

See #t-compiler/help > Span pointing to wrong file location (`rustc-dev` component).

The path remapping and unremapping for compiler sources (distributed via rustc-dev dist component) is broken because bootstrap currently remaps all sources unconditionally (if remapping is enabled) to the /rustc/{hash} form. However, the rustc-dev dist component (compiler sources) and rust-src dist component (library sources) unpacks differently:

  • rust-src unpacks sources to a path like $sysroot/lib/rustlib/src/rust, whereas
  • rustc-dev unpacks sources to a path like $sysroot/lib/rustlib/rustc-src/rust1,

meaning that the compiler need to unremap them differently. But the same remapping means that the compiler has no way to distinguish between compiler and non-compiler (esp. standard library) sources. To remedy this, this PR adopts the approach of:

  • remapping compiler sources (corresponding to rustc-dev dist component) with /rustc-dev/{hash} (this is RemapScheme::Compiler), and
  • remapping non-compiler sources (corresponding to rust-src dist component or other non-compiler sources) with /rustc/{hash} (this is RemapScheme::NonCompiler).

A different remapping allows the compiler to reverse the remapping differently.

This PR implements the bootstrap side. A follow-up compiler-side change is needed to implement the unremapping change to address the reported issue completely.

This PR introduces another env var CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR that is made available to the compiler when building compiler sources to know what the remap scheme for rustc-dev (RemapScheme::Compiler) is. Compiler sources are built with the compiler remapping scheme.

As far as I know, this change should not introduce new regressions, because the compiler source unremapping (through rustc-dev) is already broken.

Footnotes

  1. (Notice the src vs rustc-src difference.)

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label May 30, 2025
@jieyouxu jieyouxu added the A-path-remapping Area: path remapping, --remap-path-prefix, --remap-cwd-prefix, --remap-diagnostics-scope etc. label May 30, 2025
@Urgau
Copy link
Member

Urgau commented May 30, 2025

We'll also need in the compiler a different compile-time environment variable, like is currently done for /rustc/<sha> with CFG_VIRTUAL_RUST_SOURCE_BASE_DIR, otherwise we will not be able to differentiate between the two.

Be aware that both environment variables need to be set when compiling the compiler.

@jieyouxu jieyouxu changed the title [WIP] Remap compiler vs non-compiler sources differently Remap compiler vs non-compiler sources differently (bootstrap side) May 31, 2025
@jieyouxu jieyouxu marked this pull request as ready for review May 31, 2025 13:08
@rustbot
Copy link
Collaborator

rustbot commented May 31, 2025

r? @albertlarsan68

rustbot has assigned @albertlarsan68.
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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 31, 2025
@jieyouxu

This comment was marked as resolved.

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels May 31, 2025
@jieyouxu

This comment was marked as resolved.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 31, 2025
- Map compiler sources (corresponding to `rustc-dev` dist component)
  with `/rustc-dev/{hash}`.
- Map non-compiler sources (corresponding to `rust-src` dist component
  or other non-compiler sources) with `/rustc/{hash}`.

This allows the compiler to have the possibility of opportunistically
reverse the mapping. This is because

- `rust-src` unpacks sources to a path like
  `$sysroot/lib/rustlib/src/rust`, whereas
- `rustc-dev` unpacks sources to a path like
  `$sysroot/lib/rustlib/rustc-src/rust`

(Notice the `src` vs `rustc-src` difference.)
@jieyouxu
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 31, 2025
@Urgau
Copy link
Member

Urgau commented May 31, 2025

The changes looks good to me. Thanks you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-path-remapping Area: path remapping, --remap-path-prefix, --remap-cwd-prefix, --remap-diagnostics-scope etc. 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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants