-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,8 +53,6 @@ pub struct TargetInfo { | |
| pub supports_std: Option<bool>, | ||
| /// Supported values for `-Csplit-debuginfo=` flag, queried from rustc | ||
| support_split_debuginfo: Vec<String>, | ||
| /// Path to the sysroot. | ||
| pub sysroot: PathBuf, | ||
| /// Path to the "lib" directory in the sysroot which rustc uses for linking | ||
| /// target libraries. | ||
| pub sysroot_target_libdir: PathBuf, | ||
|
|
@@ -165,6 +163,8 @@ impl TargetInfo { | |
| /// invocation is cached by [`Rustc::cached_output`]. | ||
| /// | ||
| /// Search `Tricky` to learn why querying `rustc` several times is needed. | ||
| /// | ||
| /// When a Workspace is provided, | ||
|
Member
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. Probably an unfinished comment? (noticed while reading the PR).
Contributor
Author
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. 💩 I have another small refactor PR which I'll likely ship, and I'll remove this comment in that |
||
| #[tracing::instrument(skip_all)] | ||
| pub fn new( | ||
| gctx: &GlobalContext, | ||
|
|
@@ -174,15 +174,25 @@ impl TargetInfo { | |
| ) -> CargoResult<TargetInfo> { | ||
| let mut rustflags = | ||
| extra_args(gctx, requested_kinds, &rustc.host, None, kind, Flags::Rust)?; | ||
|
|
||
| let sysroot = gctx.get_sysroot(rustc)?; | ||
| let sysroot_target_libdir = sysroot | ||
| .join("lib") | ||
| .join("rustlib") | ||
| .join(match &kind { | ||
| CompileKind::Host => rustc.host.as_str(), | ||
| CompileKind::Target(target) => target.short_name(), | ||
| }) | ||
| .join("lib"); | ||
|
|
||
| let mut turn = 0; | ||
| loop { | ||
| let extra_fingerprint = kind.fingerprint_hash(); | ||
|
|
||
| // Query rustc for several kinds of info from each line of output: | ||
| // 0) file-names (to determine output file prefix/suffix for given crate type) | ||
| // 1) sysroot | ||
| // 2) split-debuginfo | ||
| // 3) cfg | ||
| // 1) split-debuginfo | ||
| // 2) cfg | ||
| // | ||
| // Search `--print` to see what we query so far. | ||
| let mut process = rustc.workspace_process(); | ||
|
|
@@ -216,7 +226,6 @@ impl TargetInfo { | |
| process.arg("--crate-type").arg(crate_type.as_str()); | ||
| } | ||
|
|
||
| process.arg("--print=sysroot"); | ||
| process.arg("--print=split-debuginfo"); | ||
| process.arg("--print=crate-name"); // `___` as a delimiter. | ||
| process.arg("--print=cfg"); | ||
|
|
@@ -238,22 +247,6 @@ impl TargetInfo { | |
| map.insert(crate_type.clone(), out); | ||
| } | ||
|
|
||
| let Some(line) = lines.next() else { | ||
| return error_missing_print_output("sysroot", &process, &output, &error); | ||
| }; | ||
| let sysroot = PathBuf::from(line); | ||
| let sysroot_target_libdir = { | ||
| let mut libdir = sysroot.clone(); | ||
| libdir.push("lib"); | ||
| libdir.push("rustlib"); | ||
| libdir.push(match &kind { | ||
| CompileKind::Host => rustc.host.as_str(), | ||
| CompileKind::Target(target) => target.short_name(), | ||
| }); | ||
| libdir.push("lib"); | ||
| libdir | ||
| }; | ||
|
|
||
| let support_split_debuginfo = { | ||
| // HACK: abuse `--print=crate-name` to use `___` as a delimiter. | ||
| let mut res = Vec::new(); | ||
|
|
@@ -352,7 +345,6 @@ impl TargetInfo { | |
| return Ok(TargetInfo { | ||
| crate_type_process, | ||
| crate_types: RefCell::new(map), | ||
| sysroot, | ||
| sysroot_target_libdir, | ||
| rustflags: rustflags.into(), | ||
| rustdocflags: extra_args( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.