-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
bootstrap: Add and use -Z absolute-file-paths #112812
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It's unfortunate that this hack is necessary. A short summary of the background here: - Rust-Analyzer uses `x check --json-output` to show red underlines in the editor. - There are several different Cargo workspaces in rust-lang/rust, including src/bootstrap and src/tools/miri. - Cargo runs each invocation of rustc relative to the *workspace*, not to the current working directory of cargo itself. - Rustc prints file paths relative to its current working directory. As a result, it would print things like `config.rs:43:14` instead of `src/bootstrap/config.rs`. This adds a new flag to rustc to print the files as an absolute path instead of a relative path. I went with this approach instead of one of the wrapping tools for the following reasons: 1. Cargo considers changing the working directory to be a breaking change: rust-lang/cargo#11007 (comment). They have open feature requests for adding a flag to print absolute paths, but none have been implemented. 2. Bootstrap would potentially be able to parse and rewrite the paths that cargo emits, but I don't want to hard-code Cargo's JSON output format in both bootstrap.py and rustbuild; unlike rustbuild, bootstrap.py can't use `cargo_metadata` as a library. 3. Rust-Analyzer could potentially rewrite this output, but that wouldn't fix ctrl+click on the relative path when someone runs `cargo check`. In addition to adding and using the new flag, this also adds `local_rebuild` detection to bootstrap.py, so that I could test the change. Before: ``` error[E0425]: cannot find value `MIRI_DEFAULT_ARGS` in crate `miri` --> src/bin/miri.rs:269:33 | 269 | args.splice(1..1, miri::MIRI_DEFAULT_ARGS.iter().map(ToString::to_string)); | ^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `MIRI_DEFLT_ARGS` | ::: src/lib.rs:128:1 | 128 | pub const MIRI_DEFLT_ARGS: &[&str] = &[ | ---------------------------------- similarly named constant `MIRI_DEFLT_ARGS` defined here ``` After: ``` error[E0425]: cannot find value `MIRI_DEFAULT_ARGS` in crate `miri` --> /home/jyn/src/rust/src/tools/miri/src/bin/miri.rs:269:33 | 269 | args.splice(1..1, miri::MIRI_DEFAULT_ARGS.iter().map(ToString::to_string)); | ^^^^^^^^^^^^^^^^^ help: a constant with a similar name exists: `MIRI_DEFLT_ARGS` | ::: /home/jyn/src/rust/src/tools/miri/src/lib.rs:128:1 | 128 | pub const MIRI_DEFLT_ARGS: &[&str] = &[ | ---------------------------------- similarly named constant `MIRI_DEFLT_ARGS` defined here ```
r? @ozkanonur (rustbot has picked a reviewer for you, use r? to override) |
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)
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Jun 19, 2023
The job Click to see the possible cause of the failure (guessed by this bot)
|
due to CI error: @rustbot author |
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
Jun 20, 2023
It seems to me like the first one is a bug in rustc wrt this feature. Also, tests may need reblessing |
i think this should be in cargo and not rustc tbh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
T-bootstrap
Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's unfortunate that this hack is necessary. A short summary of the background here:
x check --json-output
to show red underlines in the editor.config.rs:43:14
instead ofsrc/bootstrap/config.rs
.This adds a new flag to rustc to print the files as an absolute path instead of a relative path. I went with this approach instead of one of the wrapping tools for the following reasons:
Using --manifest-path, the filenames in error messages are relative to the manifest, not the current working directory cargo#11007 (comment). They have open feature
requests for adding a flag to print absolute paths, but none have been implemented.
want to hard-code Cargo's JSON output format in both bootstrap.py and rustbuild; unlike rustbuild,
bootstrap.py can't use
cargo_metadata
as a library.cargo check
.In addition to adding and using the new flag, this also adds
local_rebuild
detection to bootstrap.py, so that I could test the change.Before:
After:
Fixes #80541 and https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/missing.20errors.20for.20bootstrap.20itself.
I am not convinced this is the right approach; i could be convinced to make the change in cargo instead, but it was easier to do this than to wait the 6 weeks.