Skip to content

Commit 60340d4

Browse files
committed
Don't panic when the target is not supported by Cranelift
1 parent ede41d1 commit 60340d4

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/lib.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,17 @@ impl CodegenBackend for CraneliftCodegenBackend {
217217
) -> Result<(), ErrorReported> {
218218
use rustc_codegen_ssa::back::link::link_binary;
219219

220-
link_binary::<crate::archive::ArArchiveBuilder<'_>>(
221-
sess,
222-
&codegen_results,
223-
outputs,
224-
);
220+
link_binary::<crate::archive::ArArchiveBuilder<'_>>(sess, &codegen_results, outputs);
225221

226222
Ok(())
227223
}
228224
}
229225

230226
fn target_triple(sess: &Session) -> target_lexicon::Triple {
231-
sess.target.llvm_target.parse().unwrap()
227+
match sess.target.llvm_target.parse() {
228+
Ok(triple) => triple,
229+
Err(err) => sess.fatal(&format!("target not recognized: {}", err)),
230+
}
232231
}
233232

234233
fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box<dyn isa::TargetIsa + 'static> {
@@ -278,15 +277,21 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box<dyn isa::Tar
278277
}
279278
Some(value) => {
280279
let mut builder =
281-
cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap();
280+
cranelift_codegen::isa::lookup_variant(target_triple.clone(), variant)
281+
.unwrap_or_else(|err| {
282+
sess.fatal(&format!("can't compile for {}: {}", target_triple, err));
283+
});
282284
if let Err(_) = builder.enable(value) {
283-
sess.fatal("The specified target cpu isn't currently supported by Cranelift.");
285+
sess.fatal("the specified target cpu isn't currently supported by Cranelift.");
284286
}
285287
builder
286288
}
287289
None => {
288290
let mut builder =
289-
cranelift_codegen::isa::lookup_variant(target_triple.clone(), variant).unwrap();
291+
cranelift_codegen::isa::lookup_variant(target_triple.clone(), variant)
292+
.unwrap_or_else(|err| {
293+
sess.fatal(&format!("can't compile for {}: {}", target_triple, err));
294+
});
290295
if target_triple.architecture == target_lexicon::Architecture::X86_64 {
291296
// Don't use "haswell" as the default, as it implies `has_lzcnt`.
292297
// macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`.

0 commit comments

Comments
 (0)