Skip to content

Commit ae022d3

Browse files
committed
remap cargo dependencies to /rust/deps
1 parent 56e1aaa commit ae022d3

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/bootstrap/Cargo.lock

+10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ dependencies = [
5050
"fd-lock",
5151
"filetime",
5252
"hex",
53+
"home",
5354
"ignore",
5455
"junction",
5556
"libc",
@@ -350,6 +351,15 @@ version = "0.4.3"
350351
source = "registry+https://github.com/rust-lang/crates.io-index"
351352
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
352353

354+
[[package]]
355+
name = "home"
356+
version = "0.5.4"
357+
source = "registry+https://github.com/rust-lang/crates.io-index"
358+
checksum = "747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408"
359+
dependencies = [
360+
"winapi",
361+
]
362+
353363
[[package]]
354364
name = "ignore"
355365
version = "0.4.18"

src/bootstrap/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ sysinfo = { version = "0.26.0", optional = true }
5757
clap = { version = "4.2.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] }
5858
clap_complete = "4.2.2"
5959
semver = "1.0.17"
60+
home = "0.5.4"
6061

6162
# Solaris doesn't support flock() and thus fd-lock is not option now
6263
[target.'cfg(not(target_os = "solaris"))'.dependencies]

src/bootstrap/bin/rustc.rs

+7
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ fn main() {
150150
if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") {
151151
cmd.arg("--remap-path-prefix").arg(&map);
152152
}
153+
// The remap flags for Cargo registry sources need to be passed after the remapping for the
154+
// Rust source code directory, to handle cases when $CARGO_HOME is inside the source directory.
155+
if let Ok(maps) = env::var("RUSTC_CARGO_REGISTRY_SRC_TO_REMAP") {
156+
for map in maps.split('\t') {
157+
cmd.arg("--remap-path-prefix").arg(map);
158+
}
159+
}
153160

154161
// Force all crates compiled by this compiler to (a) be unstable and (b)
155162
// allow the `rustc_private` feature to link to other unstable crates

src/bootstrap/builder.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::any::{type_name, Any};
22
use std::cell::{Cell, RefCell};
33
use std::collections::BTreeSet;
44
use std::env;
5-
use std::ffi::OsStr;
5+
use std::ffi::{OsStr, OsString};
66
use std::fmt::{Debug, Write};
77
use std::fs::{self, File};
88
use std::hash::Hash;
@@ -1752,6 +1752,20 @@ impl<'a> Builder<'a> {
17521752
cargo.env("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR", map_to);
17531753
}
17541754

1755+
if self.config.rust_remap_debuginfo {
1756+
// FIXME: handle vendored sources
1757+
let registry_src = t!(home::cargo_home()).join("registry").join("src");
1758+
let mut env_var = OsString::new();
1759+
for entry in t!(std::fs::read_dir(registry_src)) {
1760+
if !env_var.is_empty() {
1761+
env_var.push("\t");
1762+
}
1763+
env_var.push(t!(entry).path());
1764+
env_var.push("=/rust/deps");
1765+
}
1766+
cargo.env("RUSTC_CARGO_REGISTRY_SRC_TO_REMAP", env_var);
1767+
}
1768+
17551769
// Enable usage of unstable features
17561770
cargo.env("RUSTC_BOOTSTRAP", "1");
17571771
self.add_rust_test_threads(&mut cargo);

0 commit comments

Comments
 (0)