diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-02-27 21:46:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-27 21:46:36 +0100 |
| commit | c9308846197a7e0255080bdebfbc09026d7c6309 (patch) | |
| tree | ad0799ba1429c266b883550f33f1bccea8935305 | |
| parent | 736dae2f71370c6c1ad04d8b2c6d97484cd02f33 (diff) | |
| parent | 7ad4297a4960c657932885173bef77fde0f26ccd (diff) | |
| download | rust-c9308846197a7e0255080bdebfbc09026d7c6309.tar.gz rust-c9308846197a7e0255080bdebfbc09026d7c6309.zip | |
Rollup merge of #94415 - bjorn3:cfg_default_backend, r=Mark-Simulacrum
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. cc ```@antoyo```
| -rw-r--r-- | compiler/rustc_interface/src/util.rs | 8 | ||||
| -rw-r--r-- | config.toml.example | 4 | ||||
| -rw-r--r-- | src/bootstrap/compile.rs | 4 |
3 files changed, 9 insertions, 7 deletions
diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 83b54810db2..046f4f9451f 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -236,13 +236,9 @@ pub fn get_codegen_backend( static LOAD: SyncOnceCell<unsafe fn() -> Box<dyn CodegenBackend>> = SyncOnceCell::new(); let load = LOAD.get_or_init(|| { - #[cfg(feature = "llvm")] - const DEFAULT_CODEGEN_BACKEND: &str = "llvm"; + let default_codegen_backend = option_env!("CFG_DEFAULT_CODEGEN_BACKEND").unwrap_or("llvm"); - #[cfg(not(feature = "llvm"))] - const DEFAULT_CODEGEN_BACKEND: &str = "cranelift"; - - match backend_name.unwrap_or(DEFAULT_CODEGEN_BACKEND) { + match backend_name.unwrap_or(default_codegen_backend) { filename if filename.contains('.') => load_backend_from_dylib(filename.as_ref()), #[cfg(feature = "llvm")] "llvm" => rustc_codegen_llvm::LlvmCodegenBackend::new, diff --git a/config.toml.example b/config.toml.example index ad48cc881f3..466a3a29c4c 100644 --- a/config.toml.example +++ b/config.toml.example @@ -551,7 +551,9 @@ changelog-seen = 2 # This is an array of the codegen backends that will be compiled for the rustc # that's being compiled. The default is to only build the LLVM codegen backend, -# and currently the only standard options supported are `"llvm"` and `"cranelift"`. +# and currently the only standard options supported are `"llvm"`, `"cranelift"` +# and `"gcc"`. The first backend in this list will be used as default by rustc +# when no explicit backend is specified. #codegen-backends = ["llvm"] # Indicates whether LLD will be compiled and made available in the sysroot for diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index b2805d93b70..b4c6210b388 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -662,6 +662,10 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS .env("CFG_RELEASE_CHANNEL", &builder.config.channel) .env("CFG_VERSION", builder.rust_version()); + if let Some(backend) = builder.config.rust_codegen_backends.get(0) { + cargo.env("CFG_DEFAULT_CODEGEN_BACKEND", backend); + } + let libdir_relative = builder.config.libdir_relative().unwrap_or_else(|| Path::new("lib")); let target_config = builder.config.target_config.get(&target); |
