-
-
Notifications
You must be signed in to change notification settings - Fork 3k
refactor: move sysroot lookup to GlobalContext #17276
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
adamgemmell
wants to merge
2
commits into
rust-lang:master
Choose a base branch
from
adamgemmell:dev/adagem01/sysroot-path
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,6 +225,8 @@ pub struct GlobalContext { | |
| cargo_exe: OnceLock<PathBuf>, | ||
| /// The location of the rustdoc executable | ||
| rustdoc: OnceLock<PathBuf>, | ||
| /// The path to the sysroot | ||
| sysroot: OnceLock<PathBuf>, | ||
| /// Whether we are printing extra verbose messages | ||
| extra_verbose: bool, | ||
| /// `frozen` is the same as `locked`, but additionally will not access the | ||
|
|
@@ -379,6 +381,7 @@ impl GlobalContext { | |
| cli_config: None, | ||
| cargo_exe: Default::default(), | ||
| rustdoc: Default::default(), | ||
| sysroot: Default::default(), | ||
| extra_verbose: false, | ||
| frozen: false, | ||
| locked: false, | ||
|
|
@@ -610,6 +613,25 @@ impl GlobalContext { | |
| .map(AsRef::as_ref) | ||
| } | ||
|
|
||
| /// Get the sysroot path. | ||
| pub fn get_sysroot<'gctx>(&'gctx self, ws: Option<&Workspace<'gctx>>) -> CargoResult<PathBuf> { | ||
| if self.cache_rustc_info { | ||
| let cached = self.sysroot.try_borrow_with(|| { | ||
| let rustc = self.load_global_rustc(ws)?; | ||
| rustc.sysroot(self) | ||
| }); | ||
| cached.map(|sysroot| { | ||
| let mut ret = PathBuf::new(); | ||
| // clone_from avoids reallocation | ||
| ret.clone_from(sysroot); | ||
| ret | ||
|
Comment on lines
+624
to
+627
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be true if |
||
| }) | ||
| } else { | ||
| let rustc = self.load_global_rustc(ws)?; | ||
| rustc.sysroot(self) | ||
| } | ||
| } | ||
|
|
||
| /// Which package sources have been updated, used to ensure it is only done once. | ||
| pub fn updated_sources(&self) -> MutexGuard<'_, HashSet<SourceId>> { | ||
| self.updated_sources.lock().unwrap() | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ impl Rustc { | |
| .wrapped(wrapper.as_deref()); | ||
| apply_env_config(gctx, &mut cmd)?; | ||
| cmd.env(crate::CARGO_ENV, gctx.cargo_exe()?); | ||
|
|
||
| cmd.arg("-vV"); | ||
| let verbose_version = cache.cached_output(&cmd, 0)?.0; | ||
|
|
||
|
|
@@ -159,6 +160,17 @@ impl Rustc { | |
| .unwrap() | ||
| .cached_output(cmd, extra_fingerprint) | ||
| } | ||
|
|
||
| /// Use the rustc executable to fetch the sysroot path. | ||
| pub fn sysroot(&self, gctx: &GlobalContext) -> CargoResult<PathBuf> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this supposed to be in the previous commit? |
||
| let mut cmd = self.workspace_process(); | ||
| apply_env_config(gctx, &mut cmd)?; | ||
| cmd.env(crate::CARGO_ENV, gctx.cargo_exe()?); | ||
| cmd.arg("--print=sysroot"); | ||
|
|
||
| let (stdout, _) = self.cached_output(&cmd, 0)?; | ||
| Ok(stdout.trim().into()) | ||
| } | ||
| } | ||
|
|
||
| /// It is a well known fact that `rustc` is not the fastest compiler in the | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
newto derivesysroot_target_libdir.Should we remove the lookup here?
View changes since the review