Skip to content

Commit 0b3ffcb

Browse files
committed
Allow building std with cranelift
- Don't pass llvm-specific args when using cranelift - Don't use `asm` in compiler_builtins when using cranelift
1 parent 2d76a9d commit 0b3ffcb

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ fn codegen_msvc_try<'ll>(
567567
// module.
568568
//
569569
// When modifying, make sure that the type_name string exactly matches
570-
// the one used in src/libpanic_unwind/seh.rs.
570+
// the one used in library/panic_unwind/src/seh.rs.
571571
let type_info_vtable = bx.declare_global("??_7type_info@@6B@", bx.type_i8p());
572572
let type_name = bx.const_bytes(b"rust_panic\0");
573573
let type_info =

src/bootstrap/builder.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,10 @@ impl<'a> Builder<'a> {
18531853
};
18541854

18551855
if let Some(limit) = limit {
1856-
rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={}", limit));
1856+
if stage == 0 || self.config.default_codegen_backend().unwrap_or_default() == "llvm"
1857+
{
1858+
rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={}", limit));
1859+
}
18571860
}
18581861
}
18591862

src/bootstrap/compile.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,15 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
321321
""
322322
};
323323

324+
let mut features = String::new();
325+
326+
// Cranelift doesn't support `asm`.
327+
if stage != 0 && builder.config.default_codegen_backend().unwrap_or_default() == "cranelift" {
328+
features += " compiler-builtins-no-asm";
329+
}
330+
324331
if builder.no_std(target) == Some(true) {
325-
let mut features = "compiler-builtins-mem".to_string();
332+
features += " compiler-builtins-mem";
326333
if !target.starts_with("bpf") {
327334
features.push_str(compiler_builtins_c_feature);
328335
}
@@ -335,7 +342,7 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
335342
.arg("--features")
336343
.arg(features);
337344
} else {
338-
let mut features = builder.std_features(target);
345+
features += &builder.std_features(target);
339346
features.push_str(compiler_builtins_c_feature);
340347

341348
cargo
@@ -754,7 +761,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
754761
.env("CFG_RELEASE_CHANNEL", &builder.config.channel)
755762
.env("CFG_VERSION", builder.rust_version());
756763

757-
if let Some(backend) = builder.config.rust_codegen_backends.get(0) {
764+
if let Some(backend) = builder.config.default_codegen_backend() {
758765
cargo.env("CFG_DEFAULT_CODEGEN_BACKEND", backend);
759766
}
760767

src/bootstrap/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,10 @@ impl Config {
16101610
self.submodules.unwrap_or(rust_info.is_managed_git_subrepository())
16111611
}
16121612

1613+
pub fn default_codegen_backend(&self) -> Option<Interned<String>> {
1614+
self.rust_codegen_backends.get(0).cloned()
1615+
}
1616+
16131617
/// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
16141618
fn download_ci_rustc_commit(&self, download_rustc: Option<StringOrBool>) -> Option<String> {
16151619
// If `download-rustc` is not set, default to rebuilding.

src/bootstrap/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ impl Build {
782782
/// Gets the space-separated set of activated features for the standard
783783
/// library.
784784
fn std_features(&self, target: TargetSelection) -> String {
785-
let mut features = "panic-unwind".to_string();
785+
let mut features = " panic-unwind".to_string();
786786

787787
match self.config.llvm_libunwind(target) {
788788
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"),

0 commit comments

Comments
 (0)