Skip to content

Commit 7ad4297

Browse files
committed
Use the first codegen backend in the config.toml as default
It is currently hard coded to llvm if enabled and cranelift otherwise. This made some sense when cranelift was the only alternative codegen backend. Since the introduction of the gcc backend this doesn't make much sense anymore. Before this PR bootstrapping rustc using a backend other than llvm or cranelift required changing the source of rustc_interface. With this PR it becomes a matter of putting the right backend as first enabled backend in config.toml.
1 parent 3d127e2 commit 7ad4297

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

compiler/rustc_interface/src/util.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,9 @@ pub fn get_codegen_backend(
236236
static LOAD: SyncOnceCell<unsafe fn() -> Box<dyn CodegenBackend>> = SyncOnceCell::new();
237237

238238
let load = LOAD.get_or_init(|| {
239-
#[cfg(feature = "llvm")]
240-
const DEFAULT_CODEGEN_BACKEND: &str = "llvm";
239+
let default_codegen_backend = option_env!("CFG_DEFAULT_CODEGEN_BACKEND").unwrap_or("llvm");
241240

242-
#[cfg(not(feature = "llvm"))]
243-
const DEFAULT_CODEGEN_BACKEND: &str = "cranelift";
244-
245-
match backend_name.unwrap_or(DEFAULT_CODEGEN_BACKEND) {
241+
match backend_name.unwrap_or(default_codegen_backend) {
246242
filename if filename.contains('.') => load_backend_from_dylib(filename.as_ref()),
247243
#[cfg(feature = "llvm")]
248244
"llvm" => rustc_codegen_llvm::LlvmCodegenBackend::new,

config.toml.example

+3-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,9 @@ changelog-seen = 2
551551

552552
# This is an array of the codegen backends that will be compiled for the rustc
553553
# that's being compiled. The default is to only build the LLVM codegen backend,
554-
# and currently the only standard options supported are `"llvm"` and `"cranelift"`.
554+
# and currently the only standard options supported are `"llvm"`, `"cranelift"`
555+
# and `"gcc"`. The first backend in this list will be used as default by rustc
556+
# when no explicit backend is specified.
555557
#codegen-backends = ["llvm"]
556558

557559
# Indicates whether LLD will be compiled and made available in the sysroot for

src/bootstrap/compile.rs

+4
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,10 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
662662
.env("CFG_RELEASE_CHANNEL", &builder.config.channel)
663663
.env("CFG_VERSION", builder.rust_version());
664664

665+
if let Some(backend) = builder.config.rust_codegen_backends.get(0) {
666+
cargo.env("CFG_DEFAULT_CODEGEN_BACKEND", backend);
667+
}
668+
665669
let libdir_relative = builder.config.libdir_relative().unwrap_or_else(|| Path::new("lib"));
666670
let target_config = builder.config.target_config.get(&target);
667671

0 commit comments

Comments
 (0)