Skip to content

Commit fc45382

Browse files
committed
Auto merge of #60568 - petrochenkov:debi, r=Mark-Simulacrum
rustbuild: Simplify debuginfo configuration This is supposed to fix #52179 This PR introduces one option `debuginfo-level` replacing `debuginfo` and `debuginfo-lines` and corresponding to the `rustc` flag `-C debuginfo=N`. `debuginfo-level` serves as a default for all Rust code built during bootstrap, but it can be overridden for specific subsets of code using finer-grained options `debuginfo-level-{rustc,std,tools,tests}` replacing `debuginfo-only-std`, `debuginfo-tools` and `debuginfo-tests`.
2 parents d96c01e + 780e406 commit fc45382

File tree

9 files changed

+68
-82
lines changed

9 files changed

+68
-82
lines changed

config.toml.example

+19-14
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,27 @@
301301
# library.
302302
#debug-assertions = false
303303

304-
# Whether or not debuginfo is emitted
305-
#debuginfo = false
304+
# Debuginfo level for most of Rust code, corresponds to the `-C debuginfo=N` option of `rustc`.
305+
# `0` - no debug info
306+
# `1` - line tables only
307+
# `2` - full debug info with variable and type information
308+
# Can be overriden for specific subsets of Rust code (rustc, std or tools).
309+
# Debuginfo for tests run with compiletest is not controlled by this option
310+
# and needs to be enabled separately with `debuginfo-level-tests`.
311+
#debuginfo-level = if debug { 2 } else { 0 }
306312

307-
# Whether or not line number debug information is emitted
308-
#debuginfo-lines = false
313+
# Debuginfo level for the compiler.
314+
#debuginfo-level-rustc = debuginfo-level
309315

310-
# Whether or not to only build debuginfo for the standard library if enabled.
311-
# If enabled, this will not compile the compiler with debuginfo, just the
312-
# standard library.
313-
#debuginfo-only-std = false
316+
# Debuginfo level for the standard library.
317+
#debuginfo-level-std = debuginfo-level
314318

315-
# Enable debuginfo for the extended tools: cargo, rls, rustfmt
316-
# Adding debuginfo makes them several times larger.
317-
#debuginfo-tools = false
319+
# Debuginfo level for the tools.
320+
#debuginfo-level-tools = debuginfo-level
321+
322+
# Debuginfo level for the test suites run with compiletest.
323+
# FIXME(#61117): Some tests fail when this option is enabled.
324+
#debuginfo-level-tests = 0
318325

319326
# Whether or not `panic!`s generate backtraces (RUST_BACKTRACE)
320327
#backtrace = true
@@ -345,10 +352,8 @@
345352
# harness are debuggable just from logfiles.
346353
#verbose-tests = false
347354

348-
# Flag indicating whether tests are compiled with optimizations (the -O flag) or
349-
# with debuginfo (the -g flag)
355+
# Flag indicating whether tests are compiled with optimizations (the -O flag).
350356
#optimize-tests = true
351-
#debuginfo-tests = true
352357

353358
# Flag indicating whether codegen tests will be run or not. If you get an error
354359
# saying that the FileCheck executable is missing, you may want to disable this.

src/bootstrap/bin/rustc.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ fn main() {
102102

103103
cmd.env("RUSTC_BREAK_ON_ICE", "1");
104104

105+
if let Ok(debuginfo_level) = env::var("RUSTC_DEBUGINFO_LEVEL") {
106+
cmd.arg(format!("-Cdebuginfo={}", debuginfo_level));
107+
}
108+
105109
if let Some(target) = target {
106110
// The stage0 compiler has a special sysroot distinct from what we
107111
// actually downloaded, so we just always pass the `--sysroot` option.
@@ -169,11 +173,6 @@ fn main() {
169173

170174
// Set various options from config.toml to configure how we're building
171175
// code.
172-
if env::var("RUSTC_DEBUGINFO") == Ok("true".to_string()) {
173-
cmd.arg("-g");
174-
} else if env::var("RUSTC_DEBUGINFO_LINES") == Ok("true".to_string()) {
175-
cmd.arg("-Cdebuginfo=1");
176-
}
177176
let debug_assertions = match env::var("RUSTC_DEBUG_ASSERTIONS") {
178177
Ok(s) => if s == "true" { "y" } else { "n" },
179178
Err(..) => "n",

src/bootstrap/builder.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -970,22 +970,15 @@ impl<'a> Builder<'a> {
970970
cargo.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler));
971971
}
972972

973-
if mode.is_tool() {
974-
// Tools like cargo and rls don't get debuginfo by default right now, but this can be
975-
// enabled in the config. Adding debuginfo makes them several times larger.
976-
if self.config.rust_debuginfo_tools {
977-
cargo.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string());
978-
cargo.env(
979-
"RUSTC_DEBUGINFO_LINES",
980-
self.config.rust_debuginfo_lines.to_string(),
981-
);
982-
}
983-
} else {
984-
cargo.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string());
985-
cargo.env(
986-
"RUSTC_DEBUGINFO_LINES",
987-
self.config.rust_debuginfo_lines.to_string(),
988-
);
973+
let debuginfo_level = match mode {
974+
Mode::Rustc | Mode::Codegen => self.config.rust_debuginfo_level_rustc,
975+
Mode::Std | Mode::Test => self.config.rust_debuginfo_level_std,
976+
Mode::ToolBootstrap | Mode::ToolStd |
977+
Mode::ToolTest | Mode::ToolRustc => self.config.rust_debuginfo_level_tools,
978+
};
979+
cargo.env("RUSTC_DEBUGINFO_LEVEL", debuginfo_level.to_string());
980+
981+
if !mode.is_tool() {
989982
cargo.env("RUSTC_FORCE_UNSTABLE", "1");
990983

991984
// Currently the compiler depends on crates from crates.io, and

src/bootstrap/compile.rs

-7
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,6 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Command) {
586586
let libdir_relative = builder.config.libdir_relative().unwrap_or(Path::new("lib"));
587587
cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);
588588

589-
// If we're not building a compiler with debugging information then remove
590-
// these two env vars which would be set otherwise.
591-
if builder.config.rust_debuginfo_only_std {
592-
cargo.env_remove("RUSTC_DEBUGINFO");
593-
cargo.env_remove("RUSTC_DEBUGINFO_LINES");
594-
}
595-
596589
if let Some(ref ver_date) = builder.rust_info.commit_date() {
597590
cargo.env("CFG_VER_DATE", ver_date);
598591
}

src/bootstrap/config.rs

+29-28
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,14 @@ pub struct Config {
9696
pub rust_codegen_units: Option<u32>,
9797
pub rust_codegen_units_std: Option<u32>,
9898
pub rust_debug_assertions: bool,
99-
pub rust_debuginfo: bool,
100-
pub rust_debuginfo_lines: bool,
101-
pub rust_debuginfo_only_std: bool,
102-
pub rust_debuginfo_tools: bool,
99+
pub rust_debuginfo_level_rustc: u32,
100+
pub rust_debuginfo_level_std: u32,
101+
pub rust_debuginfo_level_tools: u32,
102+
pub rust_debuginfo_level_tests: u32,
103103
pub rust_rpath: bool,
104104
pub rustc_parallel: bool,
105105
pub rustc_default_linker: Option<String>,
106106
pub rust_optimize_tests: bool,
107-
pub rust_debuginfo_tests: bool,
108107
pub rust_dist_src: bool,
109108
pub rust_codegen_backends: Vec<Interned<String>>,
110109
pub rust_codegen_backends_dir: String,
@@ -300,18 +299,18 @@ struct Rust {
300299
codegen_units: Option<u32>,
301300
codegen_units_std: Option<u32>,
302301
debug_assertions: Option<bool>,
303-
debuginfo: Option<bool>,
304-
debuginfo_lines: Option<bool>,
305-
debuginfo_only_std: Option<bool>,
306-
debuginfo_tools: Option<bool>,
302+
debuginfo_level: Option<u32>,
303+
debuginfo_level_rustc: Option<u32>,
304+
debuginfo_level_std: Option<u32>,
305+
debuginfo_level_tools: Option<u32>,
306+
debuginfo_level_tests: Option<u32>,
307307
parallel_compiler: Option<bool>,
308308
backtrace: Option<bool>,
309309
default_linker: Option<String>,
310310
channel: Option<String>,
311311
musl_root: Option<String>,
312312
rpath: Option<bool>,
313313
optimize_tests: Option<bool>,
314-
debuginfo_tests: Option<bool>,
315314
codegen_tests: Option<bool>,
316315
ignore_git: Option<bool>,
317316
debug: Option<bool>,
@@ -495,12 +494,13 @@ impl Config {
495494
// Store off these values as options because if they're not provided
496495
// we'll infer default values for them later
497496
let mut llvm_assertions = None;
498-
let mut debuginfo_lines = None;
499-
let mut debuginfo_only_std = None;
500-
let mut debuginfo_tools = None;
501497
let mut debug = None;
502-
let mut debuginfo = None;
503498
let mut debug_assertions = None;
499+
let mut debuginfo_level = None;
500+
let mut debuginfo_level_rustc = None;
501+
let mut debuginfo_level_std = None;
502+
let mut debuginfo_level_tools = None;
503+
let mut debuginfo_level_tests = None;
504504
let mut optimize = None;
505505
let mut ignore_git = None;
506506

@@ -540,14 +540,14 @@ impl Config {
540540
if let Some(ref rust) = toml.rust {
541541
debug = rust.debug;
542542
debug_assertions = rust.debug_assertions;
543-
debuginfo = rust.debuginfo;
544-
debuginfo_lines = rust.debuginfo_lines;
545-
debuginfo_only_std = rust.debuginfo_only_std;
546-
debuginfo_tools = rust.debuginfo_tools;
543+
debuginfo_level = rust.debuginfo_level;
544+
debuginfo_level_rustc = rust.debuginfo_level_rustc;
545+
debuginfo_level_std = rust.debuginfo_level_std;
546+
debuginfo_level_tools = rust.debuginfo_level_tools;
547+
debuginfo_level_tests = rust.debuginfo_level_tests;
547548
optimize = rust.optimize;
548549
ignore_git = rust.ignore_git;
549550
set(&mut config.rust_optimize_tests, rust.optimize_tests);
550-
set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
551551
set(&mut config.codegen_tests, rust.codegen_tests);
552552
set(&mut config.rust_rpath, rust.rpath);
553553
set(&mut config.jemalloc, rust.jemalloc);
@@ -639,18 +639,19 @@ impl Config {
639639
let default = true;
640640
config.rust_optimize = optimize.unwrap_or(default);
641641

642-
let default = match &config.channel[..] {
643-
"stable" | "beta" | "nightly" => true,
644-
_ => false,
645-
};
646-
config.rust_debuginfo_lines = debuginfo_lines.unwrap_or(default);
647-
config.rust_debuginfo_only_std = debuginfo_only_std.unwrap_or(default);
648-
config.rust_debuginfo_tools = debuginfo_tools.unwrap_or(false);
649-
650642
let default = debug == Some(true);
651-
config.rust_debuginfo = debuginfo.unwrap_or(default);
652643
config.rust_debug_assertions = debug_assertions.unwrap_or(default);
653644

645+
let with_defaults = |debuginfo_level_specific: Option<u32>| {
646+
debuginfo_level_specific
647+
.or(debuginfo_level)
648+
.unwrap_or(if debug == Some(true) { 2 } else { 0 })
649+
};
650+
config.rust_debuginfo_level_rustc = with_defaults(debuginfo_level_rustc);
651+
config.rust_debuginfo_level_std = with_defaults(debuginfo_level_std);
652+
config.rust_debuginfo_level_tools = with_defaults(debuginfo_level_tools);
653+
config.rust_debuginfo_level_tests = debuginfo_level_tests.unwrap_or(0);
654+
654655
let default = config.channel == "dev";
655656
config.ignore_git = ignore_git.unwrap_or(default);
656657

src/bootstrap/configure.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def v(*args):
3737
o("optimize-tests", "rust.optimize-tests", "build tests with optimizations")
3838
o("parallel-compiler", "rust.parallel-compiler", "build a multi-threaded rustc")
3939
o("test-miri", "rust.test-miri", "run miri's test suite")
40-
o("debuginfo-tests", "rust.debuginfo-tests", "build tests with debugger metadata")
4140
o("verbose-tests", "rust.verbose-tests", "enable verbose output when running tests")
4241
o("ccache", "llvm.ccache", "invoke gcc/clang via ccache to reuse object files between builds")
4342
o("sccache", None, "invoke gcc/clang via sccache to reuse object files between builds")
@@ -77,10 +76,11 @@ def v(*args):
7776
o("llvm-assertions", "llvm.assertions", "build LLVM with assertions")
7877
o("debug-assertions", "rust.debug-assertions", "build with debugging assertions")
7978
o("llvm-release-debuginfo", "llvm.release-debuginfo", "build LLVM with debugger metadata")
80-
o("debuginfo", "rust.debuginfo", "build with debugger metadata")
81-
o("debuginfo-lines", "rust.debuginfo-lines", "build with line number debugger metadata")
82-
o("debuginfo-only-std", "rust.debuginfo-only-std", "build only libstd with debugging information")
83-
o("debuginfo-tools", "rust.debuginfo-tools", "build extended tools with debugging information")
79+
o("debuginfo-level", "rust.debuginfo-level", "debuginfo level for Rust code")
80+
o("debuginfo-level-rustc", "rust.debuginfo-level-rustc", "debuginfo level for the compiler")
81+
o("debuginfo-level-std", "rust.debuginfo-level-std", "debuginfo level for the standard library")
82+
o("debuginfo-level-tools", "rust.debuginfo-level-tools", "debuginfo level for the tools")
83+
o("debuginfo-level-tests", "rust.debuginfo-level-tests", "debuginfo level for the test suites run with compiletest")
8484
v("save-toolstates", "rust.save-toolstates", "save build and test status of external tools into this file")
8585

8686
v("prefix", "install.prefix", "set installation prefix")

src/bootstrap/test.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1078,10 +1078,8 @@ impl Step for Compiletest {
10781078
if builder.config.rust_optimize_tests {
10791079
flags.push("-O".to_string());
10801080
}
1081-
if builder.config.rust_debuginfo_tests {
1082-
flags.push("-g".to_string());
1083-
}
10841081
}
1082+
flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests));
10851083
flags.push("-Zunstable-options".to_string());
10861084
flags.push(builder.config.cmd.rustc_args().join(" "));
10871085

src/bootstrap/tool.rs

-4
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,6 @@ impl Step for Rustdoc {
485485
&[],
486486
);
487487

488-
// Most tools don't get debuginfo, but rustdoc should.
489-
cargo.env("RUSTC_DEBUGINFO", builder.config.rust_debuginfo.to_string())
490-
.env("RUSTC_DEBUGINFO_LINES", builder.config.rust_debuginfo_lines.to_string());
491-
492488
let _folder = builder.fold_output(|| format!("stage{}-rustdoc", target_compiler.stage));
493489
builder.info(&format!("Building rustdoc for stage{} ({})",
494490
target_compiler.stage, target_compiler.host));

src/ci/run.sh

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then
4848
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"
4949
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp"
5050
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.remap-debuginfo"
51+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.debuginfo-level-std=1"
5152

5253
if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then
5354
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"

0 commit comments

Comments
 (0)