Skip to content

Commit a27af88

Browse files
committed
Auto merge of #12165 - weihanglo:issue/12163, r=ehuss
fix: pass `-C debuginfo` after weakening if explicitly set
2 parents a6c0d43 + 277e65b commit a27af88

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

src/cargo/core/profiles.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,12 @@ impl DebugInfo {
780780
}
781781

782782
/// Reset to the lowest level: no debuginfo.
783+
/// If it is explicitly set, keep it explicit.
783784
pub(crate) fn weaken(self) -> Self {
784-
DebugInfo::None
785+
match self {
786+
DebugInfo::None => DebugInfo::None,
787+
_ => DebugInfo::Explicit(TomlDebugInfo::None),
788+
}
785789
}
786790
}
787791

tests/testsuite/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3885,7 +3885,7 @@ fn compiler_json_error_format() {
38853885
},
38863886
"profile": {
38873887
"debug_assertions": true,
3888-
"debuginfo": null,
3888+
"debuginfo": 0,
38893889
"opt_level": "0",
38903890
"overflow_checks": true,
38913891
"test": false

tests/testsuite/profile_targets.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,23 @@ fn profile_selection_build() {
8383
// - bdep `panic` is not set because it thinks `build.rs` is a plugin.
8484
// - build_script_build is built without panic because it thinks `build.rs` is a plugin.
8585
// - We make sure that the build dependencies bar, bdep, and build.rs
86-
// are built without debuginfo.
86+
// are built with debuginfo=0.
8787
p.cargo("build -vv")
8888
.with_stderr_unordered("\
8989
[COMPILING] bar [..]
9090
[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..]
91-
[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 [..]
91+
[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=0[..]
9292
[COMPILING] bdep [..]
93-
[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 [..]
93+
[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=0[..]
9494
[COMPILING] foo [..]
95-
[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units=5 [..]
95+
[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units=5 -C debuginfo=0[..]
9696
[RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build`
9797
[foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0
9898
[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..]
9999
[RUNNING] `[..] rustc --crate-name foo src/main.rs [..]--crate-type bin --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..]
100100
[FINISHED] dev [unoptimized + debuginfo] [..]
101101
"
102102
)
103-
.with_stderr_line_without(&["[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]-C codegen-units=5 [..]"], &["-C debuginfo"])
104-
.with_stderr_line_without(&["[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]-C codegen-units=5 [..]"], &["-C debuginfo"])
105-
.with_stderr_line_without(&["[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]-C codegen-units=5 [..]"], &["-C debuginfo"])
106103
.run();
107104
p.cargo("build -vv")
108105
.with_stderr_unordered(
@@ -158,7 +155,7 @@ fn profile_selection_build_all_targets() {
158155
// - Benchmark dependencies are compiled in `dev` mode, which may be
159156
// surprising. See issue rust-lang/cargo#4929.
160157
// - We make sure that the build dependencies bar, bdep, and build.rs
161-
// are built without debuginfo.
158+
// are built with debuginfo=0.
162159
//
163160
// - Dependency profiles:
164161
// Pkg Target Profile Reason
@@ -184,11 +181,11 @@ fn profile_selection_build_all_targets() {
184181
[COMPILING] bar [..]
185182
[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=1 -C debuginfo=2 [..]
186183
[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..]
187-
[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 [..]
184+
[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=0[..]
188185
[COMPILING] bdep [..]
189-
[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 [..]
186+
[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]--crate-type lib --emit=[..]link[..]-C codegen-units=5 -C debuginfo=0[..]
190187
[COMPILING] foo [..]
191-
[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units=5 [..]
188+
[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]--crate-type bin --emit=[..]link[..]-C codegen-units=5 -C debuginfo=0[..]
192189
[RUNNING] `[..]/target/debug/build/foo-[..]/build-script-build`
193190
[foo 0.0.1] foo custom build PROFILE=debug DEBUG=true OPT_LEVEL=0
194191
[RUNNING] `[..] rustc --crate-name foo src/lib.rs [..]--crate-type lib --emit=[..]link -C panic=abort[..]-C codegen-units=1 -C debuginfo=2 [..]`
@@ -202,9 +199,6 @@ fn profile_selection_build_all_targets() {
202199
[FINISHED] dev [unoptimized + debuginfo] [..]
203200
"
204201
)
205-
.with_stderr_line_without(&["[RUNNING] `[..] rustc --crate-name bar bar/src/lib.rs [..]-C codegen-units=5 [..]"], &["-C debuginfo"])
206-
.with_stderr_line_without(&["[RUNNING] `[..] rustc --crate-name bdep bdep/src/lib.rs [..]-C codegen-units=5 [..]"], &["-C debuginfo"])
207-
.with_stderr_line_without(&["[RUNNING] `[..] rustc --crate-name build_script_build build.rs [..]-C codegen-units=5 [..]"], &["-C debuginfo"])
208202
.run();
209203
p.cargo("build -vv")
210204
.with_stderr_unordered(

0 commit comments

Comments
 (0)