Skip to content

Commit 5176945

Browse files
committed
Auto merge of #95612 - davidtwco:split-debuginfo-in-bootstrap, r=Mark-Simulacrum
bootstrap: add split-debuginfo config Replace `run-dysutil` option with more general `split-debuginfo` option that works on all platforms. r? `@Mark-Simulacrum`
2 parents 7be1da0 + 65cc0ad commit 5176945

File tree

4 files changed

+77
-21
lines changed

4 files changed

+77
-21
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
987987

988988
// On MSVC packed debug information is produced by the linker itself so
989989
// there's no need to do anything else here.
990-
SplitDebuginfo::Packed if sess.target.is_like_msvc => {}
990+
SplitDebuginfo::Packed if sess.target.is_like_windows => {}
991991

992992
// ... and otherwise we're processing a `*.dwp` packed dwarf file.
993993
//

config.toml.example

+17-7
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,23 @@ changelog-seen = 2
473473
# FIXME(#61117): Some tests fail when this option is enabled.
474474
#debuginfo-level-tests = 0
475475

476-
# Whether to run `dsymutil` on Apple platforms to gather debug info into .dSYM
477-
# bundles. `dsymutil` adds time to builds for no clear benefit, and also makes
478-
# it more difficult for debuggers to find debug info. The compiler currently
479-
# defaults to running `dsymutil` to preserve its historical default, but when
480-
# compiling the compiler itself, we skip it by default since we know it's safe
481-
# to do so in that case.
482-
#run-dsymutil = false
476+
# Should rustc be build with split debuginfo? Default is platform dependent.
477+
# Valid values are the same as those accepted by `-C split-debuginfo`
478+
# (`off`/`unpacked`/`packed`).
479+
#
480+
# On Linux, split debuginfo is disabled by default.
481+
#
482+
# On Apple platforms, unpacked split debuginfo is used by default. Unpacked
483+
# debuginfo does not run `dsymutil`, which packages debuginfo from disparate
484+
# object files into a single `.dSYM` file. `dsymutil` adds time to builds for
485+
# no clear benefit, and also makes it more difficult for debuggers to find
486+
# debug info. The compiler currently defaults to running `dsymutil` to preserve
487+
# its historical default, but when compiling the compiler itself, we skip it by
488+
# default since we know it's safe to do so in that case.
489+
#
490+
# On Windows platforms, packed debuginfo is the only supported option,
491+
# producing a `.pdb` file.
492+
#split-debuginfo = if linux { off } else if windows { packed } else if apple { unpacked }
483493

484494
# Whether or not `panic!`s generate backtraces (RUST_BACKTRACE)
485495
#backtrace = true

src/bootstrap/builder.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::time::{Duration, Instant};
1414
use crate::cache::{Cache, Interned, INTERNER};
1515
use crate::check;
1616
use crate::compile;
17-
use crate::config::TargetSelection;
17+
use crate::config::{SplitDebuginfo, TargetSelection};
1818
use crate::dist;
1919
use crate::doc;
2020
use crate::flags::{Color, Subcommand};
@@ -1390,17 +1390,17 @@ impl<'a> Builder<'a> {
13901390
},
13911391
);
13921392

1393-
// `dsymutil` adds time to builds on Apple platforms for no clear benefit, and also makes
1394-
// it more difficult for debuggers to find debug info. The compiler currently defaults to
1395-
// running `dsymutil` to preserve its historical default, but when compiling the compiler
1396-
// itself, we skip it by default since we know it's safe to do so in that case.
1397-
// See https://github.com/rust-lang/rust/issues/79361 for more info on this flag.
1398-
if target.contains("apple") {
1399-
if self.config.rust_run_dsymutil {
1400-
rustflags.arg("-Csplit-debuginfo=packed");
1401-
} else {
1402-
rustflags.arg("-Csplit-debuginfo=unpacked");
1393+
// FIXME(davidtwco): #[cfg(not(bootstrap))] - #95612 needs to be in the bootstrap compiler
1394+
// for this conditional to be removed.
1395+
if !target.contains("windows") || compiler.stage >= 1 {
1396+
if target.contains("linux") || target.contains("windows") {
1397+
rustflags.arg("-Zunstable-options");
14031398
}
1399+
match self.config.rust_split_debuginfo {
1400+
SplitDebuginfo::Packed => rustflags.arg("-Csplit-debuginfo=packed"),
1401+
SplitDebuginfo::Unpacked => rustflags.arg("-Csplit-debuginfo=unpacked"),
1402+
SplitDebuginfo::Off => rustflags.arg("-Csplit-debuginfo=off"),
1403+
};
14041404
}
14051405

14061406
if self.config.cmd.bless() {

src/bootstrap/config.rs

+48-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub struct Config {
130130
pub rust_debuginfo_level_std: u32,
131131
pub rust_debuginfo_level_tools: u32,
132132
pub rust_debuginfo_level_tests: u32,
133-
pub rust_run_dsymutil: bool,
133+
pub rust_split_debuginfo: SplitDebuginfo,
134134
pub rust_rpath: bool,
135135
pub rustc_parallel: bool,
136136
pub rustc_default_linker: Option<String>,
@@ -221,6 +221,46 @@ impl FromStr for LlvmLibunwind {
221221
}
222222
}
223223

224+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
225+
pub enum SplitDebuginfo {
226+
Packed,
227+
Unpacked,
228+
Off,
229+
}
230+
231+
impl Default for SplitDebuginfo {
232+
fn default() -> Self {
233+
SplitDebuginfo::Off
234+
}
235+
}
236+
237+
impl std::str::FromStr for SplitDebuginfo {
238+
type Err = ();
239+
240+
fn from_str(s: &str) -> Result<Self, Self::Err> {
241+
match s {
242+
"packed" => Ok(SplitDebuginfo::Packed),
243+
"unpacked" => Ok(SplitDebuginfo::Unpacked),
244+
"off" => Ok(SplitDebuginfo::Off),
245+
_ => Err(()),
246+
}
247+
}
248+
}
249+
250+
impl SplitDebuginfo {
251+
/// Returns the default `-Csplit-debuginfo` value for the current target. See the comment for
252+
/// `rust.split-debuginfo` in `config.toml.example`.
253+
fn default_for_platform(target: &str) -> Self {
254+
if target.contains("apple") {
255+
SplitDebuginfo::Unpacked
256+
} else if target.contains("windows") {
257+
SplitDebuginfo::Packed
258+
} else {
259+
SplitDebuginfo::Off
260+
}
261+
}
262+
}
263+
224264
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
225265
pub struct TargetSelection {
226266
pub triple: Interned<String>,
@@ -586,6 +626,7 @@ define_config! {
586626
debuginfo_level_std: Option<u32> = "debuginfo-level-std",
587627
debuginfo_level_tools: Option<u32> = "debuginfo-level-tools",
588628
debuginfo_level_tests: Option<u32> = "debuginfo-level-tests",
629+
split_debuginfo: Option<String> = "split-debuginfo",
589630
run_dsymutil: Option<bool> = "run-dsymutil",
590631
backtrace: Option<bool> = "backtrace",
591632
incremental: Option<bool> = "incremental",
@@ -992,7 +1033,12 @@ impl Config {
9921033
debuginfo_level_std = rust.debuginfo_level_std;
9931034
debuginfo_level_tools = rust.debuginfo_level_tools;
9941035
debuginfo_level_tests = rust.debuginfo_level_tests;
995-
config.rust_run_dsymutil = rust.run_dsymutil.unwrap_or(false);
1036+
config.rust_split_debuginfo = rust
1037+
.split_debuginfo
1038+
.as_deref()
1039+
.map(SplitDebuginfo::from_str)
1040+
.map(|v| v.expect("invalid value for rust.split_debuginfo"))
1041+
.unwrap_or(SplitDebuginfo::default_for_platform(&config.build.triple));
9961042
optimize = rust.optimize;
9971043
ignore_git = rust.ignore_git;
9981044
config.rust_new_symbol_mangling = rust.new_symbol_mangling;

0 commit comments

Comments
 (0)