Skip to content

Replace all uses of sysroot_candidates with get_or_default_sysroot #142089

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

Merged
merged 3 commits into from
Jun 9, 2025

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jun 5, 2025

Before this change we had two different ways to attempt to locate the sysroot which are inconsistently used:

  • get_or_default_sysroot which tries to locate based on the 0th cli argument and if that doesn't work falls back to locating it using the librustc_driver.so location and returns a single path.,
  • sysroot_candidates which takes the former and additionally does another attempt at locating using librustc_driver.so except without linux multiarch handling and then returns both paths.,

The latter was originally introduced to be able to locate the codegen backend back when cg_llvm was dynamically linked even for a custom driver when the --sysroot passed in does not contain a copy of cg_llvm. Back then get_or_default_sysroot did not attempt to locate the sysroot based on the location of librustc_driver.so yet. Because that is now done, the only case where removing sysroot_candidates can break things is if you have a custom driver inside what looks like a sysroot including the lib/rustlib directory, but which is missing some parts of the full sysroot like eg rust-lld.

Follow up to #138404

bjorn3 added 2 commits June 5, 2025 16:53
And consistently use try_canonicalize rather than canonicalize.
Before this change we had two different ways to attempt to locate the
sysroot which are inconsistently used:
* get_or_default_sysroot which tries to locate based on the 0th cli
  argument and if that doesn't work falls back to locating it using the
  librustc_driver.so location and returns a single path.,
* sysroot_candidates which takes the former and additionally does
  another attempt at locating using librustc_driver.so except without
  linux multiarch handling and then returns both paths.,

The latter was originally introduced to be able to locate the codegen
backend back when cg_llvm was dynamically linked even for a custom
driver when the --sysroot passed in does not contain a copy of cg_llvm.
Back then get_or_default_sysroot did not attempt to locate the sysroot
based on the location of librustc_driver.so yet. Because that is now
done, the only case where removing sysroot_candidates can break things
is if you have a custom driver inside what looks like a sysroot
including the lib/rustlib directory, but which is missing some parts of
the full sysroot like eg rust-lld.
@rustbot
Copy link
Collaborator

rustbot commented Jun 5, 2025

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
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 A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 5, 2025

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @TaKO8Ki

@petrochenkov petrochenkov self-assigned this Jun 6, 2025
);
}
}
pub fn sysroot_with_fallback(sysroot: &Path) -> SmallVec<[PathBuf; 2]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an improvement, but it still feels a bit sub-optimal.
The passed sysroot here can only be --sysroot or get_or_default_sysroot(), so perhaps it makes sense to make a structure like

struct Sysroot {
  explicit: Option<PathBuf>,
  default: PathBuf,
}

with two methods for accessing either the main path or both, and then pass that structure around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Session only stores the result of materialize_sysroot(), which does maybe_sysroot.unwrap_or_else(|| get_or_default_sysroot()).

@petrochenkov petrochenkov 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 6, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 6, 2025

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@BoxyUwU BoxyUwU removed their assignment Jun 6, 2025
@bjorn3
Copy link
Member Author

bjorn3 commented Jun 7, 2025

@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 Jun 7, 2025
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 8, 2025

📌 Commit e4c4c4c has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors 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 Jun 8, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 8, 2025
…r=petrochenkov

Replace all uses of sysroot_candidates with get_or_default_sysroot

Before this change we had two different ways to attempt to locate the sysroot which are inconsistently used:
* `get_or_default_sysroot` which tries to locate based on the 0th cli argument and if that doesn't work falls back to locating it using the librustc_driver.so location and returns a single path.,
* `sysroot_candidates` which takes the former and additionally does another attempt at locating using `librustc_driver.so` except without linux multiarch handling and then returns both paths.,

The latter was originally introduced to be able to locate the codegen backend back when cg_llvm was dynamically linked even for a custom driver when the `--sysroot` passed in does not contain a copy of cg_llvm. Back then `get_or_default_sysroot` did not attempt to locate the sysroot based on the location of librustc_driver.so yet. Because that is now done, the only case where removing `sysroot_candidates` can break things is if you have a custom driver inside what looks like a sysroot including the `lib/rustlib` directory, but which is missing some parts of the full sysroot like eg rust-lld.

Follow up to rust-lang#138404
bors added a commit that referenced this pull request Jun 8, 2025
Rollup of 11 pull requests

Successful merges:

 - #140774 (Affirm `-Cforce-frame-pointers=off` does not override)
 - #141001 (Make NonZero<char> possible)
 - #141700 (Atomic intrinsics : use const generic ordering, part 2)
 - #142008 (const-eval error: always say in which item the error occurred)
 - #142053 (Add new Tier-3 targets: `loongarch32-unknown-none*`)
 - #142089 (Replace all uses of sysroot_candidates with get_or_default_sysroot)
 - #142108 (compiler: Add track_caller to AbiMapping::unwrap)
 - #142132 (`tests/ui`: A New Order [6/N])
 - #142162 (UnsafePinned: update get() docs and signature to allow shared mutation)
 - #142171 (`tests/ui`: A New Order [7/N])
 - #142179 (store `target.min_global_align` as an `Align`)

r? `@ghost`
`@rustbot` modify labels: rollup
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Jun 8, 2025
…r=petrochenkov

Replace all uses of sysroot_candidates with get_or_default_sysroot

Before this change we had two different ways to attempt to locate the sysroot which are inconsistently used:
* `get_or_default_sysroot` which tries to locate based on the 0th cli argument and if that doesn't work falls back to locating it using the librustc_driver.so location and returns a single path.,
* `sysroot_candidates` which takes the former and additionally does another attempt at locating using `librustc_driver.so` except without linux multiarch handling and then returns both paths.,

The latter was originally introduced to be able to locate the codegen backend back when cg_llvm was dynamically linked even for a custom driver when the `--sysroot` passed in does not contain a copy of cg_llvm. Back then `get_or_default_sysroot` did not attempt to locate the sysroot based on the location of librustc_driver.so yet. Because that is now done, the only case where removing `sysroot_candidates` can break things is if you have a custom driver inside what looks like a sysroot including the `lib/rustlib` directory, but which is missing some parts of the full sysroot like eg rust-lld.

Follow up to rust-lang#138404
bors added a commit that referenced this pull request Jun 9, 2025
Rollup of 12 pull requests

Successful merges:

 - #141803 (Remove rustc's notion of "preferred" alignment AKA `__alignof`)
 - #142053 (Add new Tier-3 targets: `loongarch32-unknown-none*`)
 - #142089 (Replace all uses of sysroot_candidates with get_or_default_sysroot)
 - #142108 (compiler: Add track_caller to AbiMapping::unwrap)
 - #142132 (`tests/ui`: A New Order [6/N])
 - #142162 (UnsafePinned: update get() docs and signature to allow shared mutation)
 - #142171 (`tests/ui`: A New Order [7/N])
 - #142179 (store `target.min_global_align` as an `Align`)
 - #142183 (Added test for 30904)
 - #142194 (Remove all unused feature gates from the compiler)
 - #142199 (Do not free disk space in the `mingw-check-tidy` job)
 - #142210 (Run `mingw-check-tidy` on auto builds)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 41bc5d7 into rust-lang:master Jun 9, 2025
10 checks passed
@rustbot rustbot added this to the 1.89.0 milestone Jun 9, 2025
rust-timer added a commit that referenced this pull request Jun 9, 2025
Rollup merge of #142089 - bjorn3:sysroot_handling_cleanup3, r=petrochenkov

Replace all uses of sysroot_candidates with get_or_default_sysroot

Before this change we had two different ways to attempt to locate the sysroot which are inconsistently used:
* `get_or_default_sysroot` which tries to locate based on the 0th cli argument and if that doesn't work falls back to locating it using the librustc_driver.so location and returns a single path.,
* `sysroot_candidates` which takes the former and additionally does another attempt at locating using `librustc_driver.so` except without linux multiarch handling and then returns both paths.,

The latter was originally introduced to be able to locate the codegen backend back when cg_llvm was dynamically linked even for a custom driver when the `--sysroot` passed in does not contain a copy of cg_llvm. Back then `get_or_default_sysroot` did not attempt to locate the sysroot based on the location of librustc_driver.so yet. Because that is now done, the only case where removing `sysroot_candidates` can break things is if you have a custom driver inside what looks like a sysroot including the `lib/rustlib` directory, but which is missing some parts of the full sysroot like eg rust-lld.

Follow up to #138404
@bjorn3 bjorn3 deleted the sysroot_handling_cleanup3 branch June 9, 2025 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants