Skip to content

Commit 260d5cf

Browse files
committed
rustbuild: Move compiler-builtins build logic to manifest
This commit moves the compiler-builtins-specific build logic from `src/bootstrap/bin/rustc.rs` into the workspace `Cargo.toml`'s `[profile]` configuration. Now that rust-lang/cargo#7253 is fixed we can ensure that Cargo knows about debug assertions settings, and it can also be configured to specifically disable debug assertions unconditionally for compiler-builtins. This should improve rebuild logic when debug-assertions settings change and also improve build-std integration where Cargo externally now has an avenue to learn how to build compiler-builtins as well.
1 parent 7355816 commit 260d5cf

File tree

3 files changed

+16
-39
lines changed

3 files changed

+16
-39
lines changed

Cargo.toml

+8-7
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ exclude = [
3333
"obj",
3434
]
3535

36-
# These options are controlled from our rustc wrapper script, so turn them off
37-
# here and have them controlled elsewhere.
38-
[profile.dev]
39-
debug = false
40-
debug-assertions = false
41-
[profile.test]
42-
debug = false
36+
[profile.release.package.compiler_builtins]
37+
# The compiler-builtins crate cannot reference libcore, and it's own CI will
38+
# verify that this is the case. This requires, however, that the crate is built
39+
# without overflow checks and debug assertions. Forcefully disable debug
40+
# assertions and overflow checks here which should ensure that even if these
41+
# assertions are enabled for libstd we won't enable then for compiler_builtins
42+
# which should ensure we still link everything correctly.
4343
debug-assertions = false
44+
overflow-checks = false
4445

4546
# We want the RLS to use the version of Cargo that we've got vendored in this
4647
# repository to ensure that the same exact version of Cargo is used by both the

src/bootstrap/bin/rustc.rs

-24
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,6 @@ fn main() {
101101
{
102102
cmd.arg("-C").arg("panic=abort");
103103
}
104-
105-
// Set various options from config.toml to configure how we're building
106-
// code.
107-
let debug_assertions = match env::var("RUSTC_DEBUG_ASSERTIONS") {
108-
Ok(s) => {
109-
if s == "true" {
110-
"y"
111-
} else {
112-
"n"
113-
}
114-
}
115-
Err(..) => "n",
116-
};
117-
118-
// The compiler builtins are pretty sensitive to symbols referenced in
119-
// libcore and such, so we never compile them with debug assertions.
120-
//
121-
// FIXME(rust-lang/cargo#7253) we should be doing this in `builder.rs`
122-
// with env vars instead of doing it here in this script.
123-
if crate_name == Some("compiler_builtins") {
124-
cmd.arg("-C").arg("debug-assertions=no");
125-
} else {
126-
cmd.arg("-C").arg(format!("debug-assertions={}", debug_assertions));
127-
}
128104
} else {
129105
// FIXME(rust-lang/cargo#5754) we shouldn't be using special env vars
130106
// here, but rather Cargo should know what flags to pass rustc itself.

src/bootstrap/builder.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -918,14 +918,6 @@ impl<'a> Builder<'a> {
918918
.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
919919
.env("RUSTC_REAL", self.rustc(compiler))
920920
.env("RUSTC_STAGE", stage.to_string())
921-
.env(
922-
"RUSTC_DEBUG_ASSERTIONS",
923-
if mode == Mode::Std {
924-
self.config.rust_debug_assertions_std.to_string()
925-
} else {
926-
self.config.rust_debug_assertions.to_string()
927-
},
928-
)
929921
.env("RUSTC_SYSROOT", &sysroot)
930922
.env("RUSTC_LIBDIR", &libdir)
931923
.env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc"))
@@ -1009,6 +1001,14 @@ impl<'a> Builder<'a> {
10091001
}
10101002
};
10111003
cargo.env(profile_var("DEBUG"), debuginfo_level.to_string());
1004+
cargo.env(
1005+
profile_var("DEBUG_ASSERTIONS"),
1006+
if mode == Mode::Std {
1007+
self.config.rust_debug_assertions_std.to_string()
1008+
} else {
1009+
self.config.rust_debug_assertions.to_string()
1010+
},
1011+
);
10121012

10131013
if !mode.is_tool() {
10141014
cargo.env("RUSTC_FORCE_UNSTABLE", "1");

0 commit comments

Comments
 (0)