Skip to content

Commit efa32de

Browse files
committed
Auto merge of #150283 - Urgau:remap-debuginfo-absolute, r=jieyouxu
Remap both absolute and relative paths when building `rustc` and `std` Turns out [#150110](#150110) didn't work as expected, because when the standard library sources are present, we [helpfully un-remap the paths](https://github.com/rust-lang/rust/blob/e951f470d76febcc6f0a5b409c509eb77450a336/compiler/rustc_metadata/src/rmeta/decoder.rs#L1656-L1702) to the local directory of the user, including when we are building the compiler and standard library it-self (duh!), and since those paths are absolute (not relative), our purely relative remapping didn't pick them up. This behavior wasn't a issue before because the un-remap logic immediately tries to remap them again, and since we had the absolute remapping we would just remap them to the the same thing. To fix that issue I've adjusted our remapping to remap both the absolute and relative paths when building `rustc` and `std`, as well as added a run-make to make sure we don't regress it again (with a new `needs-std-remap-debuginfo` directive). r? `@jieyouxu`
2 parents 5a7ad8e + 4d839da commit efa32de

14 files changed

Lines changed: 145 additions & 5 deletions

File tree

src/bootstrap/src/bin/rustc.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,11 @@ fn main() {
168168
}
169169
}
170170

171-
if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") {
172-
cmd.arg("--remap-path-prefix").arg(&map);
171+
// The remap flags for the compiler and standard library sources.
172+
if let Ok(maps) = env::var("RUSTC_DEBUGINFO_MAP") {
173+
for map in maps.split('\t') {
174+
cmd.arg("--remap-path-prefix").arg(map);
175+
}
173176
}
174177
// The remap flags for Cargo registry sources need to be passed after the remapping for the
175178
// Rust source code directory, to handle cases when $CARGO_HOME is inside the source directory.

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,10 @@ Please disable assertions with `rust.debug-assertions = false`.
22572257
cmd.arg("--with-std-debug-assertions");
22582258
}
22592259

2260+
if builder.config.rust_remap_debuginfo {
2261+
cmd.arg("--with-std-remap-debuginfo");
2262+
}
2263+
22602264
let mut llvm_components_passed = false;
22612265
let mut copts_passed = false;
22622266
if builder.config.llvm_enabled(test_compiler.host) {

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,15 +1025,26 @@ impl Builder<'_> {
10251025
if let Some(ref map_to) =
10261026
self.build.debuginfo_map_to(GitRepo::Rustc, RemapScheme::NonCompiler)
10271027
{
1028+
// Tell the compiler which prefix was used for remapping the standard library
10281029
cargo.env("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR", map_to);
10291030
}
10301031

10311032
if let Some(ref map_to) =
10321033
self.build.debuginfo_map_to(GitRepo::Rustc, RemapScheme::Compiler)
10331034
{
1034-
// When building compiler sources, we want to apply the compiler remap scheme.
1035-
cargo.env("RUSTC_DEBUGINFO_MAP", format!("compiler/={map_to}/compiler"));
1035+
// Tell the compiler which prefix was used for remapping the compiler it-self
10361036
cargo.env("CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR", map_to);
1037+
1038+
// When building compiler sources, we want to apply the compiler remap scheme.
1039+
let map = [
1040+
// Cargo use relative paths for workspace members, so let's remap those.
1041+
format!("compiler/={map_to}/compiler"),
1042+
// rustc creates absolute paths (in part bc of the `rust-src` unremap
1043+
// and for working directory) so let's remap the build directory as well.
1044+
format!("{}={map_to}", self.build.src.display()),
1045+
]
1046+
.join("\t");
1047+
cargo.env("RUSTC_DEBUGINFO_MAP", map);
10371048
}
10381049
}
10391050
Mode::Std
@@ -1044,7 +1055,16 @@ impl Builder<'_> {
10441055
if let Some(ref map_to) =
10451056
self.build.debuginfo_map_to(GitRepo::Rustc, RemapScheme::NonCompiler)
10461057
{
1047-
cargo.env("RUSTC_DEBUGINFO_MAP", format!("library/={map_to}/library"));
1058+
// When building the standard library sources, we want to apply the std remap scheme.
1059+
let map = [
1060+
// Cargo use relative paths for workspace members, so let's remap those.
1061+
format!("library/={map_to}/library"),
1062+
// rustc creates absolute paths (in part bc of the `rust-src` unremap
1063+
// and for working directory) so let's remap the build directory as well.
1064+
format!("{}={map_to}", self.build.src.display()),
1065+
]
1066+
.join("\t");
1067+
cargo.env("RUSTC_DEBUGINFO_MAP", map);
10481068
}
10491069
}
10501070
}

src/doc/rustc-dev-guide/src/tests/directives.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ settings:
189189
assertions.
190190
- `needs-std-debug-assertions` — ignores if std was not built with debug
191191
assertions.
192+
- `ignore-std-remap-debuginfo` — ignores if std was built with remapping of
193+
it's sources.
194+
- `needs-std-remap-debugino` — ignores if std was not built with remapping of
195+
it's sources.
192196
- `ignore-rustc-debug-assertions` — ignores if rustc was built with debug
193197
assertions.
194198
- `needs-rustc-debug-assertions` — ignores if rustc was not built with debug

src/tools/compiletest/src/common.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ pub struct Config {
438438
/// FIXME: make it clearer that this refers to the staged `std`, not stage 0 `std`.
439439
pub with_std_debug_assertions: bool,
440440

441+
/// Whether *staged* `std` was built with remapping of debuginfo.
442+
///
443+
/// FIXME: make it clearer that this refers to the staged `std`, not stage 0 `std`.
444+
pub with_std_remap_debuginfo: bool,
445+
441446
/// Only run tests that match these filters (using `libtest` "test name contains" filter logic).
442447
///
443448
/// FIXME(#139660): the current hand-rolled test executor intentionally mimics the `libtest`

src/tools/compiletest/src/directives/cfg.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ pub(crate) fn prepare_conditions(config: &Config) -> PreparedConditions {
202202
config.with_std_debug_assertions,
203203
"when std is built with debug assertions",
204204
);
205+
builder.cond(
206+
"std-remap-debuginfo",
207+
config.with_std_remap_debuginfo,
208+
"when std is built with remapping of debuginfo",
209+
);
205210

206211
for &debugger in Debugger::STR_VARIANTS {
207212
builder.cond(

src/tools/compiletest/src/directives/directive_names.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ pub(crate) const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
184184
"needs-sanitizer-support",
185185
"needs-sanitizer-thread",
186186
"needs-std-debug-assertions",
187+
"needs-std-remap-debuginfo",
187188
"needs-subprocess",
188189
"needs-symlink",
189190
"needs-target-has-atomic",

src/tools/compiletest/src/directives/needs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ pub(super) fn handle_needs(
181181
condition: config.with_std_debug_assertions,
182182
ignore_reason: "ignored if std wasn't built with debug assertions",
183183
},
184+
Need {
185+
name: "needs-std-remap-debuginfo",
186+
condition: config.with_std_remap_debuginfo,
187+
ignore_reason: "ignored if std wasn't built with remapping of debuginfo",
188+
},
184189
Need {
185190
name: "needs-target-std",
186191
condition: build_helper::targets::target_supports_std(&config.target),

src/tools/compiletest/src/directives/tests.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ struct ConfigBuilder {
117117
profiler_runtime: bool,
118118
rustc_debug_assertions: bool,
119119
std_debug_assertions: bool,
120+
std_remap_debuginfo: bool,
120121
}
121122

122123
impl ConfigBuilder {
@@ -185,6 +186,11 @@ impl ConfigBuilder {
185186
self
186187
}
187188

189+
fn std_remap_debuginfo(&mut self, is_enabled: bool) -> &mut Self {
190+
self.std_remap_debuginfo = is_enabled;
191+
self
192+
}
193+
188194
fn build(&mut self) -> Config {
189195
let args = &[
190196
"compiletest",
@@ -246,6 +252,9 @@ impl ConfigBuilder {
246252
if self.std_debug_assertions {
247253
args.push("--with-std-debug-assertions".to_owned());
248254
}
255+
if self.std_remap_debuginfo {
256+
args.push("--with-std-remap-debuginfo".to_owned());
257+
}
249258

250259
args.push("--rustc-path".to_string());
251260
args.push(std::env::var("TEST_RUSTC").expect("must be configured by bootstrap"));
@@ -400,6 +409,19 @@ fn std_debug_assertions() {
400409
assert!(check_ignore(&config, "//@ ignore-std-debug-assertions"));
401410
}
402411

412+
#[test]
413+
fn std_remap_debuginfo() {
414+
let config: Config = cfg().std_remap_debuginfo(false).build();
415+
416+
assert!(check_ignore(&config, "//@ needs-std-remap-debuginfo"));
417+
assert!(!check_ignore(&config, "//@ ignore-std-remap-debuginfo"));
418+
419+
let config: Config = cfg().std_remap_debuginfo(true).build();
420+
421+
assert!(!check_ignore(&config, "//@ needs-std-remap-debuginfo"));
422+
assert!(check_ignore(&config, "//@ ignore-std-remap-debuginfo"));
423+
}
424+
403425
#[test]
404426
fn stage() {
405427
let config: Config = cfg().stage(1).stage_id("stage1-x86_64-unknown-linux-gnu").build();

src/tools/compiletest/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ fn parse_config(args: Vec<String>) -> Config {
106106
.optflag("", "has-enzyme", "run tests that require enzyme")
107107
.optflag("", "with-rustc-debug-assertions", "whether rustc was built with debug assertions")
108108
.optflag("", "with-std-debug-assertions", "whether std was built with debug assertions")
109+
.optflag("", "with-std-remap-debuginfo", "whether std was built with remapping")
109110
.optmulti(
110111
"",
111112
"skip",
@@ -295,6 +296,7 @@ fn parse_config(args: Vec<String>) -> Config {
295296
let run_ignored = matches.opt_present("ignored");
296297
let with_rustc_debug_assertions = matches.opt_present("with-rustc-debug-assertions");
297298
let with_std_debug_assertions = matches.opt_present("with-std-debug-assertions");
299+
let with_std_remap_debuginfo = matches.opt_present("with-std-remap-debuginfo");
298300
let mode = matches.opt_str("mode").unwrap().parse().expect("invalid mode");
299301
let has_enzyme = matches.opt_present("has-enzyme");
300302
let filters = if mode == TestMode::RunMake {
@@ -402,6 +404,7 @@ fn parse_config(args: Vec<String>) -> Config {
402404
run_ignored,
403405
with_rustc_debug_assertions,
404406
with_std_debug_assertions,
407+
with_std_remap_debuginfo,
405408
filters,
406409
skip: matches.opt_strs("skip"),
407410
filter_exact: matches.opt_present("exact"),

0 commit comments

Comments
 (0)