Skip to content

Commit 3dfbf0b

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 9672b5e commit 3dfbf0b

File tree

3 files changed

+16
-40
lines changed

3 files changed

+16
-40
lines changed

Cargo.toml

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ 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

45-
[profile.release.package.compiler_builtins]
4646
# For compiler-builtins we always use a high number of codegen units.
4747
# The goal here is to place every single intrinsic into its own object
4848
# file to avoid symbol clashes with the system libgcc if possible. Note

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
@@ -950,14 +950,6 @@ impl<'a> Builder<'a> {
950950
.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
951951
.env("RUSTC_REAL", self.rustc(compiler))
952952
.env("RUSTC_STAGE", stage.to_string())
953-
.env(
954-
"RUSTC_DEBUG_ASSERTIONS",
955-
if mode == Mode::Std {
956-
self.config.rust_debug_assertions_std.to_string()
957-
} else {
958-
self.config.rust_debug_assertions.to_string()
959-
},
960-
)
961953
.env("RUSTC_SYSROOT", &sysroot)
962954
.env("RUSTC_LIBDIR", &libdir)
963955
.env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc"))
@@ -1041,6 +1033,14 @@ impl<'a> Builder<'a> {
10411033
}
10421034
};
10431035
cargo.env(profile_var("DEBUG"), debuginfo_level.to_string());
1036+
cargo.env(
1037+
profile_var("DEBUG_ASSERTIONS"),
1038+
if mode == Mode::Std {
1039+
self.config.rust_debug_assertions_std.to_string()
1040+
} else {
1041+
self.config.rust_debug_assertions.to_string()
1042+
},
1043+
);
10441044

10451045
if !mode.is_tool() {
10461046
cargo.env("RUSTC_FORCE_UNSTABLE", "1");

0 commit comments

Comments
 (0)