From 28405cabd50181afa6eccfd7f2ee8eb363d35594 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 5 May 2019 22:15:42 +0300 Subject: [PATCH 1/4] rustbuild: Simplify debuginfo configuration --- config.toml.example | 30 ++++++++++---------- src/bootstrap/bin/rustc.rs | 9 +++--- src/bootstrap/builder.rs | 25 ++++++----------- src/bootstrap/compile.rs | 7 ----- src/bootstrap/config.rs | 57 +++++++++++++++++++------------------- src/bootstrap/configure.py | 10 +++---- src/bootstrap/test.rs | 4 +-- src/bootstrap/tool.rs | 4 --- src/ci/run.sh | 1 + 9 files changed, 65 insertions(+), 82 deletions(-) diff --git a/config.toml.example b/config.toml.example index 556625b531d1c..361a1b00ae226 100644 --- a/config.toml.example +++ b/config.toml.example @@ -301,20 +301,24 @@ # library. #debug-assertions = false -# Whether or not debuginfo is emitted -#debuginfo = false +# Debuginfo level for Rust code, corresponds to the `-C debuginfo=N` option of `rustc`. +# `0` - no debug info +# `1` - line tables only +# `2` - full debug info with variable and type information +# Can be overriden for specific subsets of Rust code (rustc, std, tools or tests). +#debuginfo-level = if debug { 2 } else { 0 } -# Whether or not line number debug information is emitted -#debuginfo-lines = false +# Debuginfo level for the compiler. +#debuginfo-level-rustc = debuginfo-level -# Whether or not to only build debuginfo for the standard library if enabled. -# If enabled, this will not compile the compiler with debuginfo, just the -# standard library. -#debuginfo-only-std = false +# Debuginfo level for the standard library. +#debuginfo-level-std = debuginfo-level -# Enable debuginfo for the extended tools: cargo, rls, rustfmt -# Adding debuginfo makes them several times larger. -#debuginfo-tools = false +# Debuginfo level for the tools. +#debuginfo-level-tools = debuginfo-level + +# Debuginfo level for the test suites run with compiletest. +#debuginfo-level-tests = debuginfo-level # Whether or not `panic!`s generate backtraces (RUST_BACKTRACE) #backtrace = true @@ -345,10 +349,8 @@ # harness are debuggable just from logfiles. #verbose-tests = false -# Flag indicating whether tests are compiled with optimizations (the -O flag) or -# with debuginfo (the -g flag) +# Flag indicating whether tests are compiled with optimizations (the -O flag) #optimize-tests = true -#debuginfo-tests = true # Flag indicating whether codegen tests will be run or not. If you get an error # saying that the FileCheck executable is missing, you may want to disable this. diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 821c37dc23596..d51961c65b7ae 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -102,6 +102,10 @@ fn main() { cmd.env("RUSTC_BREAK_ON_ICE", "1"); + if let Ok(debuginfo_level) = env::var("RUSTC_DEBUGINFO_LEVEL") { + cmd.arg(format!("-Cdebuginfo={}", debuginfo_level)); + } + if let Some(target) = target { // The stage0 compiler has a special sysroot distinct from what we // actually downloaded, so we just always pass the `--sysroot` option. @@ -169,11 +173,6 @@ fn main() { // Set various options from config.toml to configure how we're building // code. - if env::var("RUSTC_DEBUGINFO") == Ok("true".to_string()) { - cmd.arg("-g"); - } else if env::var("RUSTC_DEBUGINFO_LINES") == Ok("true".to_string()) { - cmd.arg("-Cdebuginfo=1"); - } let debug_assertions = match env::var("RUSTC_DEBUG_ASSERTIONS") { Ok(s) => if s == "true" { "y" } else { "n" }, Err(..) => "n", diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 51663e9316982..e616b2647a9f4 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -970,22 +970,15 @@ impl<'a> Builder<'a> { cargo.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler)); } - if mode.is_tool() { - // Tools like cargo and rls don't get debuginfo by default right now, but this can be - // enabled in the config. Adding debuginfo makes them several times larger. - if self.config.rust_debuginfo_tools { - cargo.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string()); - cargo.env( - "RUSTC_DEBUGINFO_LINES", - self.config.rust_debuginfo_lines.to_string(), - ); - } - } else { - cargo.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string()); - cargo.env( - "RUSTC_DEBUGINFO_LINES", - self.config.rust_debuginfo_lines.to_string(), - ); + let debuginfo_level = match mode { + Mode::Rustc | Mode::Codegen => self.config.rust_debuginfo_level_rustc, + Mode::Std | Mode::Test => self.config.rust_debuginfo_level_std, + Mode::ToolBootstrap | Mode::ToolStd | + Mode::ToolTest | Mode::ToolRustc => self.config.rust_debuginfo_level_tools, + }; + cargo.env("RUSTC_DEBUGINFO_LEVEL", debuginfo_level.to_string()); + + if !mode.is_tool() { cargo.env("RUSTC_FORCE_UNSTABLE", "1"); // Currently the compiler depends on crates from crates.io, and diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 2da5e1c5902c1..6c81b6ada2b9f 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -586,13 +586,6 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Command) { let libdir_relative = builder.config.libdir_relative().unwrap_or(Path::new("lib")); cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative); - // If we're not building a compiler with debugging information then remove - // these two env vars which would be set otherwise. - if builder.config.rust_debuginfo_only_std { - cargo.env_remove("RUSTC_DEBUGINFO"); - cargo.env_remove("RUSTC_DEBUGINFO_LINES"); - } - if let Some(ref ver_date) = builder.rust_info.commit_date() { cargo.env("CFG_VER_DATE", ver_date); } diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index b1d009a674066..836a1d13c3053 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -96,15 +96,14 @@ pub struct Config { pub rust_codegen_units: Option, pub rust_codegen_units_std: Option, pub rust_debug_assertions: bool, - pub rust_debuginfo: bool, - pub rust_debuginfo_lines: bool, - pub rust_debuginfo_only_std: bool, - pub rust_debuginfo_tools: bool, + pub rust_debuginfo_level_rustc: u32, + pub rust_debuginfo_level_std: u32, + pub rust_debuginfo_level_tools: u32, + pub rust_debuginfo_level_tests: u32, pub rust_rpath: bool, pub rustc_parallel: bool, pub rustc_default_linker: Option, pub rust_optimize_tests: bool, - pub rust_debuginfo_tests: bool, pub rust_dist_src: bool, pub rust_codegen_backends: Vec>, pub rust_codegen_backends_dir: String, @@ -300,10 +299,11 @@ struct Rust { codegen_units: Option, codegen_units_std: Option, debug_assertions: Option, - debuginfo: Option, - debuginfo_lines: Option, - debuginfo_only_std: Option, - debuginfo_tools: Option, + debuginfo_level: Option, + debuginfo_level_rustc: Option, + debuginfo_level_std: Option, + debuginfo_level_tools: Option, + debuginfo_level_tests: Option, parallel_compiler: Option, backtrace: Option, default_linker: Option, @@ -311,7 +311,6 @@ struct Rust { musl_root: Option, rpath: Option, optimize_tests: Option, - debuginfo_tests: Option, codegen_tests: Option, ignore_git: Option, debug: Option, @@ -495,12 +494,13 @@ impl Config { // Store off these values as options because if they're not provided // we'll infer default values for them later let mut llvm_assertions = None; - let mut debuginfo_lines = None; - let mut debuginfo_only_std = None; - let mut debuginfo_tools = None; let mut debug = None; - let mut debuginfo = None; let mut debug_assertions = None; + let mut debuginfo_level = None; + let mut debuginfo_level_rustc = None; + let mut debuginfo_level_std = None; + let mut debuginfo_level_tools = None; + let mut debuginfo_level_tests = None; let mut optimize = None; let mut ignore_git = None; @@ -540,14 +540,14 @@ impl Config { if let Some(ref rust) = toml.rust { debug = rust.debug; debug_assertions = rust.debug_assertions; - debuginfo = rust.debuginfo; - debuginfo_lines = rust.debuginfo_lines; - debuginfo_only_std = rust.debuginfo_only_std; - debuginfo_tools = rust.debuginfo_tools; + debuginfo_level = rust.debuginfo_level; + debuginfo_level_rustc = rust.debuginfo_level_rustc; + debuginfo_level_std = rust.debuginfo_level_std; + debuginfo_level_tools = rust.debuginfo_level_tools; + debuginfo_level_tests = rust.debuginfo_level_tests; optimize = rust.optimize; ignore_git = rust.ignore_git; set(&mut config.rust_optimize_tests, rust.optimize_tests); - set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests); set(&mut config.codegen_tests, rust.codegen_tests); set(&mut config.rust_rpath, rust.rpath); set(&mut config.jemalloc, rust.jemalloc); @@ -639,18 +639,19 @@ impl Config { let default = true; config.rust_optimize = optimize.unwrap_or(default); - let default = match &config.channel[..] { - "stable" | "beta" | "nightly" => true, - _ => false, - }; - config.rust_debuginfo_lines = debuginfo_lines.unwrap_or(default); - config.rust_debuginfo_only_std = debuginfo_only_std.unwrap_or(default); - config.rust_debuginfo_tools = debuginfo_tools.unwrap_or(false); - let default = debug == Some(true); - config.rust_debuginfo = debuginfo.unwrap_or(default); config.rust_debug_assertions = debug_assertions.unwrap_or(default); + let with_defaults = |debuginfo_level_specific: Option| { + debuginfo_level_specific + .or(debuginfo_level) + .unwrap_or(if debug == Some(true) { 2 } else { 0 }) + }; + config.rust_debuginfo_level_rustc = with_defaults(debuginfo_level_rustc); + config.rust_debuginfo_level_std = with_defaults(debuginfo_level_std); + config.rust_debuginfo_level_tools = with_defaults(debuginfo_level_tools); + config.rust_debuginfo_level_tests = with_defaults(debuginfo_level_tests); + let default = config.channel == "dev"; config.ignore_git = ignore_git.unwrap_or(default); diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index ade8afee7c109..53d3dbf60d1d7 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -37,7 +37,6 @@ def v(*args): o("optimize-tests", "rust.optimize-tests", "build tests with optimizations") o("parallel-compiler", "rust.parallel-compiler", "build a multi-threaded rustc") o("test-miri", "rust.test-miri", "run miri's test suite") -o("debuginfo-tests", "rust.debuginfo-tests", "build tests with debugger metadata") o("verbose-tests", "rust.verbose-tests", "enable verbose output when running tests") o("ccache", "llvm.ccache", "invoke gcc/clang via ccache to reuse object files between builds") o("sccache", None, "invoke gcc/clang via sccache to reuse object files between builds") @@ -77,10 +76,11 @@ def v(*args): o("llvm-assertions", "llvm.assertions", "build LLVM with assertions") o("debug-assertions", "rust.debug-assertions", "build with debugging assertions") o("llvm-release-debuginfo", "llvm.release-debuginfo", "build LLVM with debugger metadata") -o("debuginfo", "rust.debuginfo", "build with debugger metadata") -o("debuginfo-lines", "rust.debuginfo-lines", "build with line number debugger metadata") -o("debuginfo-only-std", "rust.debuginfo-only-std", "build only libstd with debugging information") -o("debuginfo-tools", "rust.debuginfo-tools", "build extended tools with debugging information") +o("debuginfo-level", "rust.debuginfo-level", "debuginfo level for Rust code") +o("debuginfo-level-rustc", "rust.debuginfo-level-rustc", "debuginfo level for the compiler") +o("debuginfo-level-std", "rust.debuginfo-level-std", "debuginfo level for the standard library") +o("debuginfo-level-tools", "rust.debuginfo-level-tools", "debuginfo level for the tools") +o("debuginfo-level-tests", "rust.debuginfo-level-tests", "debuginfo level for the test suites run with compiletest") v("save-toolstates", "rust.save-toolstates", "save build and test status of external tools into this file") v("prefix", "install.prefix", "set installation prefix") diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 25d45fa5f40df..05b3ce6bc8964 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1078,10 +1078,8 @@ impl Step for Compiletest { if builder.config.rust_optimize_tests { flags.push("-O".to_string()); } - if builder.config.rust_debuginfo_tests { - flags.push("-g".to_string()); - } } + flags.push(format!("-Cdebuginfo={}", builder.config.rust_debuginfo_level_tests)); flags.push("-Zunstable-options".to_string()); flags.push(builder.config.cmd.rustc_args().join(" ")); diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index edcd68d010e84..d723f286fa889 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -485,10 +485,6 @@ impl Step for Rustdoc { &[], ); - // Most tools don't get debuginfo, but rustdoc should. - cargo.env("RUSTC_DEBUGINFO", builder.config.rust_debuginfo.to_string()) - .env("RUSTC_DEBUGINFO_LINES", builder.config.rust_debuginfo_lines.to_string()); - let _folder = builder.fold_output(|| format!("stage{}-rustdoc", target_compiler.stage)); builder.info(&format!("Building rustdoc for stage{} ({})", target_compiler.stage, target_compiler.host)); diff --git a/src/ci/run.sh b/src/ci/run.sh index 42d0d7db5964c..14ae2ae3b01c1 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -32,6 +32,7 @@ RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-manage-submodules" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-locked-deps" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-cargo-native-static" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-units-std=1" +RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.debuginfo-level-std=1" if [ "$DIST_SRC" = "" ]; then RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-dist-src" From 3da7bbc6da494f291f18a1ac3290e7d92d3ba958 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 24 May 2019 01:04:50 +0300 Subject: [PATCH 2/4] ci: Enable debuginfo for std only if release channel is set --- src/ci/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/run.sh b/src/ci/run.sh index 14ae2ae3b01c1..c8d9ffd92fa0c 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -32,7 +32,6 @@ RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-manage-submodules" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-locked-deps" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-cargo-native-static" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-units-std=1" -RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.debuginfo-level-std=1" if [ "$DIST_SRC" = "" ]; then RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-dist-src" @@ -49,6 +48,7 @@ if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.remap-debuginfo" + RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.debuginfo-level-std=1" if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions" From 763470dc1312482f8f067f90925579fb0072ef92 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 24 May 2019 02:11:33 +0300 Subject: [PATCH 3/4] rustbuild: Untie `debuginfo-level-tests` from `debuginfo-level` --- config.toml.example | 8 +++++--- src/bootstrap/config.rs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config.toml.example b/config.toml.example index 361a1b00ae226..ae3107b51feaf 100644 --- a/config.toml.example +++ b/config.toml.example @@ -301,11 +301,13 @@ # library. #debug-assertions = false -# Debuginfo level for Rust code, corresponds to the `-C debuginfo=N` option of `rustc`. +# Debuginfo level for most of Rust code, corresponds to the `-C debuginfo=N` option of `rustc`. # `0` - no debug info # `1` - line tables only # `2` - full debug info with variable and type information -# Can be overriden for specific subsets of Rust code (rustc, std, tools or tests). +# Can be overriden for specific subsets of Rust code (rustc, std or tools). +# Debuginfo for tests run with compiletest is not controlled by this option +# and needs to be enabled separately with `debuginfo-level-tests`. #debuginfo-level = if debug { 2 } else { 0 } # Debuginfo level for the compiler. @@ -318,7 +320,7 @@ #debuginfo-level-tools = debuginfo-level # Debuginfo level for the test suites run with compiletest. -#debuginfo-level-tests = debuginfo-level +#debuginfo-level-tests = 0 # Whether or not `panic!`s generate backtraces (RUST_BACKTRACE) #backtrace = true diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 836a1d13c3053..d618654b129af 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -650,7 +650,7 @@ impl Config { config.rust_debuginfo_level_rustc = with_defaults(debuginfo_level_rustc); config.rust_debuginfo_level_std = with_defaults(debuginfo_level_std); config.rust_debuginfo_level_tools = with_defaults(debuginfo_level_tools); - config.rust_debuginfo_level_tests = with_defaults(debuginfo_level_tests); + config.rust_debuginfo_level_tests = debuginfo_level_tests.unwrap_or(0); let default = config.channel == "dev"; config.ignore_git = ignore_git.unwrap_or(default); From 780e406db2eb553e9127e64462ee8626f4132aa3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 24 May 2019 13:01:23 +0300 Subject: [PATCH 4/4] Address review comments --- config.toml.example | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.toml.example b/config.toml.example index ae3107b51feaf..c14adf8ce33c7 100644 --- a/config.toml.example +++ b/config.toml.example @@ -320,6 +320,7 @@ #debuginfo-level-tools = debuginfo-level # Debuginfo level for the test suites run with compiletest. +# FIXME(#61117): Some tests fail when this option is enabled. #debuginfo-level-tests = 0 # Whether or not `panic!`s generate backtraces (RUST_BACKTRACE) @@ -351,7 +352,7 @@ # harness are debuggable just from logfiles. #verbose-tests = false -# Flag indicating whether tests are compiled with optimizations (the -O flag) +# Flag indicating whether tests are compiled with optimizations (the -O flag). #optimize-tests = true # Flag indicating whether codegen tests will be run or not. If you get an error