Don't panic when the target is not supported by Cranelift
This commit is contained in:
parent
ede41d1b98
commit
60340d44d8
1 changed files with 14 additions and 9 deletions
23
src/lib.rs
23
src/lib.rs
|
@ -217,18 +217,17 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||||
) -> Result<(), ErrorReported> {
|
) -> Result<(), ErrorReported> {
|
||||||
use rustc_codegen_ssa::back::link::link_binary;
|
use rustc_codegen_ssa::back::link::link_binary;
|
||||||
|
|
||||||
link_binary::<crate::archive::ArArchiveBuilder<'_>>(
|
link_binary::<crate::archive::ArArchiveBuilder<'_>>(sess, &codegen_results, outputs);
|
||||||
sess,
|
|
||||||
&codegen_results,
|
|
||||||
outputs,
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn target_triple(sess: &Session) -> target_lexicon::Triple {
|
fn target_triple(sess: &Session) -> target_lexicon::Triple {
|
||||||
sess.target.llvm_target.parse().unwrap()
|
match sess.target.llvm_target.parse() {
|
||||||
|
Ok(triple) => triple,
|
||||||
|
Err(err) => sess.fatal(&format!("target not recognized: {}", err)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box<dyn isa::TargetIsa + 'static> {
|
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
|
||||||
}
|
}
|
||||||
Some(value) => {
|
Some(value) => {
|
||||||
let mut builder =
|
let mut builder =
|
||||||
cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap();
|
cranelift_codegen::isa::lookup_variant(target_triple.clone(), variant)
|
||||||
|
.unwrap_or_else(|err| {
|
||||||
|
sess.fatal(&format!("can't compile for {}: {}", target_triple, err));
|
||||||
|
});
|
||||||
if let Err(_) = builder.enable(value) {
|
if let Err(_) = builder.enable(value) {
|
||||||
sess.fatal("The specified target cpu isn't currently supported by Cranelift.");
|
sess.fatal("the specified target cpu isn't currently supported by Cranelift.");
|
||||||
}
|
}
|
||||||
builder
|
builder
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let mut builder =
|
let mut builder =
|
||||||
cranelift_codegen::isa::lookup_variant(target_triple.clone(), variant).unwrap();
|
cranelift_codegen::isa::lookup_variant(target_triple.clone(), variant)
|
||||||
|
.unwrap_or_else(|err| {
|
||||||
|
sess.fatal(&format!("can't compile for {}: {}", target_triple, err));
|
||||||
|
});
|
||||||
if target_triple.architecture == target_lexicon::Architecture::X86_64 {
|
if target_triple.architecture == target_lexicon::Architecture::X86_64 {
|
||||||
// Don't use "haswell" as the default, as it implies `has_lzcnt`.
|
// Don't use "haswell" as the default, as it implies `has_lzcnt`.
|
||||||
// macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`.
|
// macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`.
|
||||||
|
|
Loading…
Reference in a new issue