Skip to content

Commit 7593c50

Browse files
committed
bootstrap: add split-debuginfo config
Replace `run-dysutil` option with more general `split-debuginfo` option that works on all platforms. Signed-off-by: David Wood <[email protected]>
1 parent e27d9df commit 7593c50

File tree

3 files changed

+78
-21
lines changed

3 files changed

+78
-21
lines changed

config.toml.example

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,28 @@ 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, packed split debuginfo is used by default, which splits debuginfo
481+
# into a separate `rustc.dwp` file. Split DWARF on Linux results in lower
482+
# linking times (there's less debuginfo for the linker to process),
483+
# `split-debuginfo` is enabled on default for Linux. Unpacked debuginfo could
484+
# technically work too, but the cost of running the DWARF packager is marginal
485+
# and results in debuginfo being in a single file.
486+
#
487+
# On Apple platforms, unpacked split debuginfo is used by default. Unpacked
488+
# debuginfo does not run `dsymutil`, which packages debuginfo from disparate
489+
# object files into a single `.dSYM` file. `dsymutil` adds time to builds for
490+
# no clear benefit, and also makes it more difficult for debuggers to find
491+
# debug info. The compiler currently defaults to running `dsymutil` to preserve
492+
# its historical default, but when compiling the compiler itself, we skip it by
493+
# default since we know it's safe to do so in that case.
494+
#
495+
# On Windows platforms, packed debuginfo is the only supported option,
496+
# producing a `.pdb` file.
497+
#split-debuginfo = if linux { packed } else if windows { packed } else if apple { unpacked }
483498

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

src/bootstrap/builder.rs

Lines changed: 8 additions & 12 deletions
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};
@@ -1365,18 +1365,14 @@ impl<'a> Builder<'a> {
13651365
},
13661366
);
13671367

1368-
// `dsymutil` adds time to builds on Apple platforms for no clear benefit, and also makes
1369-
// it more difficult for debuggers to find debug info. The compiler currently defaults to
1370-
// running `dsymutil` to preserve its historical default, but when compiling the compiler
1371-
// itself, we skip it by default since we know it's safe to do so in that case.
1372-
// See https://github.com/rust-lang/rust/issues/79361 for more info on this flag.
1373-
if target.contains("apple") {
1374-
if self.config.rust_run_dsymutil {
1375-
rustflags.arg("-Csplit-debuginfo=packed");
1376-
} else {
1377-
rustflags.arg("-Csplit-debuginfo=unpacked");
1378-
}
1368+
if target.contains("linux") || target.contains("windows") {
1369+
rustflags.arg("-Zunstable-options");
13791370
}
1371+
match self.config.rust_split_debuginfo {
1372+
SplitDebuginfo::Packed => rustflags.arg("-Csplit-debuginfo=packed"),
1373+
SplitDebuginfo::Unpacked => rustflags.arg("-Csplit-debuginfo=unpacked"),
1374+
SplitDebuginfo::Off => rustflags.arg("-Csplit-debuginfo=off"),
1375+
};
13801376

13811377
if self.config.cmd.bless() {
13821378
// Bless `expect!` tests.

src/bootstrap/config.rs

Lines changed: 48 additions & 2 deletions
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::Unpacked
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)