Skip to content

refactor: move sysroot lookup to GlobalContext - #17276

Open
adamgemmell wants to merge 2 commits into
rust-lang:masterfrom
adamgemmell:dev/adagem01/sysroot-path
Open

refactor: move sysroot lookup to GlobalContext#17276
adamgemmell wants to merge 2 commits into
rust-lang:masterfrom
adamgemmell:dev/adagem01/sysroot-path

Conversation

@adamgemmell

@adamgemmell adamgemmell commented Jul 30, 2026

Copy link
Copy Markdown

What does this PR try to resolve?

I split this out from a refactor of #16675, as part of work on build-std=always. In this PR, and in other build-std work I have in progress, it's useful to know the sysroot path earlier than the compiler/ stage of Cargo. Because there's one rustc instance per Cargo invocation, and because the sysroot path remains fixed per rustc and isn't dependent on the target, this should be safe to move out of TargetInfo.

How to test and review this PR?

The first commit shows the logic being moved, and the second commit shows updating all the users of this logic.

Getting the sysroot is already heavily tested in Cargo, hence why I didn't add a new test for this.

@rustbot

rustbot commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @weihanglo (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @epage, @weihanglo
  • @epage, @weihanglo expanded to epage, weihanglo
  • Random selection from epage, weihanglo

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-cache-messages Area: caching of compiler messages A-cfg-expr Area: Platform cfg expressions A-configuration Area: cargo config files and env vars A-layout Area: target output directory layout, naming, and organization Command-fix S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 30, 2026
Comment thread src/context/mod.rs
Comment on lines +624 to +627
let mut ret = PathBuf::new();
// clone_from avoids reallocation
ret.clone_from(sysroot);
ret

@epage epage Jul 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This would be true if ret had existed before, but it doesn't.

View changes since the review

Comment thread src/util/rustc.rs
}

/// Use the rustc executable to fetch the sysroot path.
pub fn sysroot(&self, gctx: &GlobalContext) -> CargoResult<PathBuf> {

@epage epage Jul 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this supposed to be in the previous commit?

View changes since the review

Comment on lines -56 to -57
/// Path to the sysroot.
pub sysroot: PathBuf,

@epage epage Jul 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We aren't saving this off but we are still looking it up in new to derive sysroot_target_libdir.

Should we remove the lookup here?

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-build-execution Area: anything dealing with executing the compiler A-cache-messages Area: caching of compiler messages A-cfg-expr Area: Platform cfg expressions A-configuration Area: cargo config files and env vars A-layout Area: target output directory layout, naming, and organization Command-fix S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants