Skip to content

Commit ca743f3

Browse files
committed
Auto merge of #2730 - alexcrichton:fix-panic-abort-build-script, r=alexcrichton
Fix build scripts and panic=abort Build scripts were apparently always compiled with the "dev" profile rather than the standard "match whatever the normal build was" profile, which meant that if dev/release disagreed on panic=abort you'd get compile errors. Seems bad! This commit fixes this by just having build scripts always compile with the same profile as libraries (for now), as this was the original intention anyway. Closes #2726
2 parents 259324c + 183c59c commit ca743f3

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/cargo/ops/cargo_rustc/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,10 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
632632
}
633633
}
634634

635-
pub fn build_script_profile(&self, _pkg: &PackageId) -> &'a Profile {
636-
// TODO: should build scripts always be built with a dev
635+
pub fn build_script_profile(&self, pkg: &PackageId) -> &'a Profile {
636+
// TODO: should build scripts always be built with the same library
637637
// profile? How is this controlled at the CLI layer?
638-
&self.profiles.dev
638+
self.lib_profile(pkg)
639639
}
640640

641641
pub fn rustflags_args(&self, unit: &Unit) -> CargoResult<Vec<String>> {

tests/test_cargo_compile_custom_build.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,3 +1930,45 @@ test!(custom_target_dir {
19301930
assert_that(p.cargo_process("build").arg("-v"),
19311931
execs().with_status(0));
19321932
});
1933+
1934+
test!(panic_abort_with_build_scripts {
1935+
if !::is_nightly() {
1936+
return
1937+
}
1938+
let p = project("foo")
1939+
.file("Cargo.toml", r#"
1940+
[project]
1941+
name = "foo"
1942+
version = "0.5.0"
1943+
authors = []
1944+
1945+
[profile.release]
1946+
panic = 'abort'
1947+
1948+
[dependencies]
1949+
a = { path = "a" }
1950+
"#)
1951+
.file("src/lib.rs", "extern crate a;")
1952+
.file("a/Cargo.toml", r#"
1953+
[project]
1954+
name = "a"
1955+
version = "0.5.0"
1956+
authors = []
1957+
build = "build.rs"
1958+
1959+
[build-dependencies]
1960+
b = { path = "../b" }
1961+
"#)
1962+
.file("a/src/lib.rs", "")
1963+
.file("a/build.rs", "extern crate b; fn main() {}")
1964+
.file("b/Cargo.toml", r#"
1965+
[project]
1966+
name = "b"
1967+
version = "0.5.0"
1968+
authors = []
1969+
"#)
1970+
.file("b/src/lib.rs", "");
1971+
1972+
assert_that(p.cargo_process("build").arg("-v").arg("--release"),
1973+
execs().with_status(0));
1974+
});

0 commit comments

Comments
 (0)