Skip to content

Commit b9648d4

Browse files
authored
Rollup merge of #114278 - ozkanonur:validate-codegen-backend-config, r=clubby789
better error handling for `rust.codegen-backends` on deserialization Fixes #109315
2 parents 307c573 + b602cf5 commit b9648d4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/bootstrap/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ fn needs_codegen_config(run: &RunConfig<'_>) -> bool {
11291129
needs_codegen_cfg
11301130
}
11311131

1132-
const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_";
1132+
pub(crate) const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_";
11331133

11341134
fn is_codegen_cfg_needed(path: &TaskPath, run: &RunConfig<'_>) -> bool {
11351135
if path.path.to_str().unwrap().contains(&CODEGEN_BACKEND_PREFIX) {

src/bootstrap/config.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::str::FromStr;
2020
use crate::cache::{Interned, INTERNER};
2121
use crate::cc_detect::{ndk_compiler, Language};
2222
use crate::channel::{self, GitInfo};
23+
use crate::compile::CODEGEN_BACKEND_PREFIX;
2324
pub use crate::flags::Subcommand;
2425
use crate::flags::{Color, Flags, Warnings};
2526
use crate::util::{exe, output, t};
@@ -1443,8 +1444,21 @@ impl Config {
14431444
.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"));
14441445

14451446
if let Some(ref backends) = rust.codegen_backends {
1446-
config.rust_codegen_backends =
1447-
backends.iter().map(|s| INTERNER.intern_str(s)).collect();
1447+
let available_backends = vec!["llvm", "cranelift", "gcc"];
1448+
1449+
config.rust_codegen_backends = backends.iter().map(|s| {
1450+
if let Some(backend) = s.strip_prefix(CODEGEN_BACKEND_PREFIX) {
1451+
if available_backends.contains(&backend) {
1452+
panic!("Invalid value '{s}' for 'rust.codegen-backends'. Instead, please use '{backend}'.");
1453+
} else {
1454+
println!("help: '{s}' for 'rust.codegen-backends' might fail. \
1455+
Codegen backends are mostly defined without the '{CODEGEN_BACKEND_PREFIX}' prefix. \
1456+
In this case, it would be referred to as '{backend}'.");
1457+
}
1458+
}
1459+
1460+
INTERNER.intern_str(s)
1461+
}).collect();
14481462
}
14491463

14501464
config.rust_codegen_units = rust.codegen_units.map(threads_from_config);

0 commit comments

Comments
 (0)