Skip to content

Allow debuginfo level to be specified #3534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub struct Profile {
pub codegen_units: Option<u32>, // None = use rustc default
pub rustc_args: Option<Vec<String>>,
pub rustdoc_args: Option<Vec<String>>,
pub debuginfo: bool,
pub debuginfo: Option<u32>,
pub debug_assertions: bool,
pub rpath: bool,
pub test: bool,
Expand All @@ -143,7 +143,7 @@ pub struct Profile {
#[derive(RustcEncodable)]
struct SerializedProfile<'a> {
opt_level: &'a str,
debuginfo: bool,
debuginfo: Option<u32>,
debug_assertions: bool,
test: bool,
}
Expand Down Expand Up @@ -488,7 +488,7 @@ impl fmt::Display for Target {
impl Profile {
pub fn default_dev() -> Profile {
Profile {
debuginfo: true,
debuginfo: Some(2),
debug_assertions: true,
..Profile::default()
}
Expand All @@ -497,7 +497,7 @@ impl Profile {
pub fn default_release() -> Profile {
Profile {
opt_level: "3".to_string(),
debuginfo: false,
debuginfo: None,
..Profile::default()
}
}
Expand Down Expand Up @@ -554,7 +554,7 @@ impl Default for Profile {
codegen_units: None,
rustc_args: None,
rustdoc_args: None,
debuginfo: false,
debuginfo: None,
debug_assertions: false,
rpath: false,
test: false,
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_rustc/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
Kind::Host => cx.host_triple(),
Kind::Target => cx.target_triple(),
})
.env("DEBUG", &profile.debuginfo.to_string())
.env("DEBUG", &profile.debuginfo.is_some().to_string())
.env("OPT_LEVEL", &profile.opt_level)
.env("PROFILE", if cx.build_config.release { "release" } else { "debug" })
.env("HOST", cx.host_triple())
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_rustc/job_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl<'a> JobQueue<'a> {
let profile = cx.lib_profile();
let mut opt_type = String::from(if profile.opt_level == "0" { "unoptimized" }
else { "optimized" });
if profile.debuginfo {
if profile.debuginfo.is_some() {
opt_type = opt_type + " + debuginfo";
}
let duration = start_time.elapsed();
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn compile_targets<'a, 'cfg: 'a>(ws: &Workspace<'cfg>,
resolve: &'a Resolve,
config: &'cfg Config,
build_config: BuildConfig,
profiles: &'a Profiles,
profiles: &'a Profiles,
exec: Arc<Executor>)
-> CargoResult<Compilation<'cfg>> {
let units = pkg_targets.iter().flat_map(|&(pkg, ref targets)| {
Expand Down Expand Up @@ -659,8 +659,8 @@ fn build_base_args(cx: &mut Context,
}
}

if debuginfo {
cmd.arg("-g");
if let Some(debuginfo) = debuginfo {
cmd.arg("-C").arg(format!("debuginfo={}", debuginfo));
}

if let Some(ref args) = *rustc_args {
Expand Down
16 changes: 14 additions & 2 deletions src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,18 @@ impl Decodable for TomlOptLevel {
}
}

#[derive(RustcDecodable, Clone)]
pub enum U32OrBool {
U32(u32),
Bool(bool),
}

#[derive(RustcDecodable, Clone, Default)]
pub struct TomlProfile {
opt_level: Option<TomlOptLevel>,
lto: Option<bool>,
codegen_units: Option<u32>,
debug: Option<bool>,
debug: Option<U32OrBool>,
debug_assertions: Option<bool>,
rpath: Option<bool>,
panic: Option<String>,
Expand Down Expand Up @@ -1265,12 +1271,18 @@ fn build_profiles(profiles: &Option<TomlProfiles>) -> Profiles {

fn merge(profile: Profile, toml: Option<&TomlProfile>) -> Profile {
let &TomlProfile {
ref opt_level, lto, codegen_units, debug, debug_assertions, rpath,
ref opt_level, lto, codegen_units, ref debug, debug_assertions, rpath,
ref panic
} = match toml {
Some(toml) => toml,
None => return profile,
};
let debug = match *debug {
Some(U32OrBool::U32(debug)) => Some(Some(debug)),
Some(U32OrBool::Bool(true)) => Some(Some(2)),
Some(U32OrBool::Bool(false)) => Some(None),
None => None,
};
Profile {
opt_level: opt_level.clone().unwrap_or(TomlOptLevel(profile.opt_level)).0,
lto: lto.unwrap_or(profile.lto),
Expand Down
7 changes: 4 additions & 3 deletions src/doc/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ along with the defaults for each profile.
# The development profile, used for `cargo build`.
[profile.dev]
opt-level = 0 # controls the `--opt-level` the compiler builds with
debug = true # controls whether the compiler passes `-g`
debug = true # controls whether the compiler passes `-C debuginfo`
# a value of `true` is equivalent to `2`
rpath = false # controls whether the compiler passes `-C rpath`
lto = false # controls `-C lto` for binaries and staticlibs
debug-assertions = true # controls whether debug assertions are enabled
Expand All @@ -202,7 +203,7 @@ panic = 'unwind'
# The testing profile, used for `cargo test`.
[profile.test]
opt-level = 0
debug = true
debug = 2
rpath = false
lto = false
debug-assertions = true
Expand All @@ -222,7 +223,7 @@ panic = 'unwind'
# The documentation profile, used for `cargo doc`.
[profile.doc]
opt-level = 0
debug = true
debug = 2
rpath = false
lto = false
debug-assertions = true
Expand Down
2 changes: 1 addition & 1 deletion tests/build-lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
format!("\
[COMPILING] {name} v{version} ({url})
[RUNNING] `rustc --crate-name {name} src[/]lib.rs --crate-type lib \
--emit=dep-info,link -g \
--emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
Expand Down
8 changes: 4 additions & 4 deletions tests/build-script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ fn custom_build_script_rustc_flags() {
execs().with_status(101)
.with_stderr(&format!("\
[COMPILING] bar v0.5.0 ({url})
[RUNNING] `rustc --crate-name test {dir}{sep}src{sep}lib.rs --crate-type lib -g \
[RUNNING] `rustc --crate-name test {dir}{sep}src{sep}lib.rs --crate-type lib -C debuginfo=2 \
-C metadata=[..] \
-C extra-filename=-[..] \
--out-dir {dir}{sep}target \
Expand Down Expand Up @@ -766,19 +766,19 @@ fn build_cmd_with_a_build_cmd() {
[RUNNING] `rustc [..] a[/]build.rs [..] --extern b=[..]`
[RUNNING] `[..][/]a-[..][/]build-script-build`
[RUNNING] `rustc --crate-name a [..]lib.rs --crate-type lib \
--emit=dep-info,link -g \
--emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..]target[/]debug[/]deps \
-L [..]target[/]debug[/]deps`
[COMPILING] foo v0.5.0 (file://[..])
[RUNNING] `rustc --crate-name build_script_build build.rs --crate-type bin \
--emit=dep-info,link \
-g -C metadata=[..] --out-dir [..] \
-C debuginfo=2 -C metadata=[..] --out-dir [..] \
-L [..]target[/]debug[/]deps \
--extern a=[..]liba[..].rlib`
[RUNNING] `[..][/]foo-[..][/]build-script-build`
[RUNNING] `rustc --crate-name foo [..]lib.rs --crate-type lib \
--emit=dep-info,link -g \
--emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L [..]target[/]debug[/]deps`
Expand Down
16 changes: 8 additions & 8 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,13 +821,13 @@ fn cargo_default_env_metadata_env_var() {
[COMPILING] bar v0.0.1 ({url}/bar)
[RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
--emit=dep-info,link \
-C prefer-dynamic -g \
-C prefer-dynamic -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
--emit=dep-info,link -g \
--emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
-C extra-filename=[..] \
--out-dir [..] \
Expand All @@ -848,13 +848,13 @@ suffix = env::consts::DLL_SUFFIX,
[COMPILING] bar v0.0.1 ({url}/bar)
[RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \
--emit=dep-info,link \
-C prefer-dynamic -g \
-C prefer-dynamic -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc --crate-name foo src[/]lib.rs --crate-type lib \
--emit=dep-info,link -g \
--emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
-C extra-filename=[..] \
--out-dir [..] \
Expand Down Expand Up @@ -1198,7 +1198,7 @@ fn verbose_build() {
execs().with_status(0).with_stderr(&format!("\
[COMPILING] test v0.0.0 ({url})
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
--emit=dep-info,link -g \
--emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
Expand Down Expand Up @@ -2443,7 +2443,7 @@ fn compiler_json_error_format() {
"reason":"compiler-artifact",
"profile": {
"debug_assertions": true,
"debuginfo": true,
"debuginfo": 2,
"opt_level": "0",
"test": false
},
Expand Down Expand Up @@ -2475,7 +2475,7 @@ fn compiler_json_error_format() {
"target":{"kind":["bin"],"name":"foo","src_path":"[..]main.rs"},
"profile": {
"debug_assertions": true,
"debuginfo": true,
"debuginfo": 2,
"opt_level": "0",
"test": false
},
Expand Down Expand Up @@ -2537,7 +2537,7 @@ fn message_format_json_forward_stderr() {
"target":{"kind":["bin"],"name":"foo","src_path":"[..]"},
"profile":{
"debug_assertions":true,
"debuginfo":true,
"debuginfo":2,
"opt_level":"0",
"test":false
},
Expand Down
2 changes: 1 addition & 1 deletion tests/cross-compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ fn linker_and_ar() {
.with_stderr_contains(&format!("\
[COMPILING] foo v0.5.0 ({url})
[RUNNING] `rustc --crate-name foo src[/]foo.rs --crate-type bin \
--emit=dep-info,link -g \
--emit=dep-info,link -C debuginfo=2 \
-C metadata=[..] \
--out-dir {dir}[/]target[/]{target}[/]debug[/]deps \
--target {target} \
Expand Down
39 changes: 35 additions & 4 deletions tests/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,38 @@ fn opt_level_override_0() {
[COMPILING] test v0.0.0 ({url})
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
--emit=dep-info,link \
-g \
-C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
[FINISHED] [..] target(s) in [..]
",
dir = p.root().display(),
url = p.url()
)));
}

#[test]
fn debug_override_1() {
let mut p = project("foo");

p = p
.file("Cargo.toml", r#"
[package]
name = "test"
version = "0.0.0"
authors = []

[profile.dev]
debug = 1
"#)
.file("src/lib.rs", "");
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(0).with_stderr(&format!("\
[COMPILING] test v0.0.0 ({url})
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
--emit=dep-info,link \
-C debuginfo=1 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]debug[/]deps`
Expand Down Expand Up @@ -93,7 +124,7 @@ fn check_opt_level_override(profile_level: &str, rustc_level: &str) {
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
--emit=dep-info,link \
-C opt-level={level} \
-g \
-C debuginfo=2 \
-C debug-assertions=on \
-C metadata=[..] \
--out-dir [..] \
Expand Down Expand Up @@ -164,15 +195,15 @@ fn top_level_overrides_deps() {
--emit=dep-info,link \
-C prefer-dynamic \
-C opt-level=1 \
-g \
-C debuginfo=2 \
-C metadata=[..] \
--out-dir {dir}[/]target[/]release[/]deps \
-L dependency={dir}[/]target[/]release[/]deps`
[COMPILING] test v0.0.0 ({url})
[RUNNING] `rustc --crate-name test src[/]lib.rs --crate-type lib \
--emit=dep-info,link \
-C opt-level=1 \
-g \
-C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency={dir}[/]target[/]release[/]deps \
Expand Down
4 changes: 2 additions & 2 deletions tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,14 @@ fast2"));
[COMPILING] bar v0.0.1 ({url}/bar)
[RUNNING] `rustc --crate-name bar bar[/]src[/]bar.rs --crate-type lib \
--emit=dep-info,link \
-g \
-C debuginfo=2 \
-C metadata=[..] \
--out-dir {dir}[/]target[/]debug[/]deps \
-L dependency={dir}[/]target[/]debug[/]deps`
[COMPILING] foo v0.0.1 ({url})
[RUNNING] `rustc --crate-name a examples[/]a.rs --crate-type bin \
--emit=dep-info,link \
-g \
-C debuginfo=2 \
-C metadata=[..] \
--out-dir {dir}[/]target[/]debug[/]examples \
-L dependency={dir}[/]target[/]debug[/]deps \
Expand Down
Loading