Auto merge of #115872 - ferrocene:pa-remap-cargo-home, r=clubby789
Remap Cargo dependencies to /rust/deps ⚠️ **This doesn't affect user-compiled programs, it only affects building the Rust compiler itself.** ⚠️ Right now, `rust.remap-debuginfo = true` doesn't completely remap all paths: while LLVM and rustc sources are properly remapped (respectively to `/rust/llvm` and `/rust/$commit`), Cargo dependencies still use absolute paths from the Cargo home. This never affected builds from CI much, because `CARGO_HOME=/cargo` in CI, so users see paths like this included in the precompiled binaries and libraries: ``` /cargo/registry/src/index.crates.io-6f17d22bba15001f/gimli-0.26.2/src/read/line.rs ``` Builds outside CI don't have remapping though, and it's confusing that the config flag doesn't fully do what it advertises. This PR fixes it by adding remapping for dependencies too. *All registries's* source directory are remapped to `/rust/deps`, to account for multiple registries being able to contain crates.io crates (sparse index vs git, and source replacement mirrors). This results in paths like this being included: ``` /rust/deps/gimli-0.26.2/src/read/line.rs ```
This commit is contained in:
commit
278eaf509d
@ -50,6 +50,7 @@ dependencies = [
|
|||||||
"fd-lock",
|
"fd-lock",
|
||||||
"filetime",
|
"filetime",
|
||||||
"hex",
|
"hex",
|
||||||
|
"home",
|
||||||
"ignore",
|
"ignore",
|
||||||
"junction",
|
"junction",
|
||||||
"libc",
|
"libc",
|
||||||
@ -350,6 +351,15 @@ version = "0.4.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "home"
|
||||||
|
version = "0.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ignore"
|
name = "ignore"
|
||||||
version = "0.4.18"
|
version = "0.4.18"
|
||||||
|
@ -40,6 +40,7 @@ clap_complete = "4.4.3"
|
|||||||
cmake = "0.1.38"
|
cmake = "0.1.38"
|
||||||
filetime = "0.2"
|
filetime = "0.2"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
|
home = "0.5.4"
|
||||||
ignore = "0.4.10"
|
ignore = "0.4.10"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
object = { version = "0.32.0", default-features = false, features = ["archive", "coff", "read_core", "unaligned"] }
|
object = { version = "0.32.0", default-features = false, features = ["archive", "coff", "read_core", "unaligned"] }
|
||||||
|
@ -124,6 +124,13 @@ fn main() {
|
|||||||
if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") {
|
if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") {
|
||||||
cmd.arg("--remap-path-prefix").arg(&map);
|
cmd.arg("--remap-path-prefix").arg(&map);
|
||||||
}
|
}
|
||||||
|
// The remap flags for Cargo registry sources need to be passed after the remapping for the
|
||||||
|
// Rust source code directory, to handle cases when $CARGO_HOME is inside the source directory.
|
||||||
|
if let Ok(maps) = env::var("RUSTC_CARGO_REGISTRY_SRC_TO_REMAP") {
|
||||||
|
for map in maps.split('\t') {
|
||||||
|
cmd.arg("--remap-path-prefix").arg(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Force all crates compiled by this compiler to (a) be unstable and (b)
|
// Force all crates compiled by this compiler to (a) be unstable and (b)
|
||||||
// allow the `rustc_private` feature to link to other unstable crates
|
// allow the `rustc_private` feature to link to other unstable crates
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::{OsStr, OsString};
|
||||||
use std::fmt::{Debug, Write};
|
use std::fmt::{Debug, Write};
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
@ -1767,6 +1767,20 @@ pub fn cargo(
|
|||||||
cargo.env("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR", map_to);
|
cargo.env("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR", map_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.config.rust_remap_debuginfo {
|
||||||
|
// FIXME: handle vendored sources
|
||||||
|
let registry_src = t!(home::cargo_home()).join("registry").join("src");
|
||||||
|
let mut env_var = OsString::new();
|
||||||
|
for entry in t!(std::fs::read_dir(registry_src)) {
|
||||||
|
if !env_var.is_empty() {
|
||||||
|
env_var.push("\t");
|
||||||
|
}
|
||||||
|
env_var.push(t!(entry).path());
|
||||||
|
env_var.push("=/rust/deps");
|
||||||
|
}
|
||||||
|
cargo.env("RUSTC_CARGO_REGISTRY_SRC_TO_REMAP", env_var);
|
||||||
|
}
|
||||||
|
|
||||||
// Enable usage of unstable features
|
// Enable usage of unstable features
|
||||||
cargo.env("RUSTC_BOOTSTRAP", "1");
|
cargo.env("RUSTC_BOOTSTRAP", "1");
|
||||||
self.add_rust_test_threads(&mut cargo);
|
self.add_rust_test_threads(&mut cargo);
|
||||||
|
Loading…
Reference in New Issue
Block a user