-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Autodetect default backend, add features for architecture type
- Loading branch information
Mark McCaskey
committed
Nov 22, 2019
1 parent
c3f93f1
commit 31437a1
Showing
6 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! This build script sets the default compiler using special output. | ||
//! | ||
//! See https://doc.rust-lang.org/cargo/reference/build-scripts.html | ||
//! for details. | ||
/// This function tells Cargo which default backend to use | ||
fn set_default_backend() { | ||
// we must use this rather than `cfg` because the build.rs executes on the | ||
// compiling system. This method works with cross compilation too. | ||
match std::env::var("CARGO_CFG_TARGET_ARCH") | ||
.expect("compilation target env var") | ||
.as_ref() | ||
{ | ||
"x86_64" => { | ||
println!("cargo:rustc-cfg=feature=\"default-backend-cranelift\""); | ||
} | ||
"aarch64" => { | ||
println!("cargo:rustc-cfg=feature=\"default-backend-singlepass\""); | ||
} | ||
other => { | ||
println!("cargo:warning=compiling for untested architecture: \"{}\"! Attempting to use LLVM", other); | ||
println!("cargo:rustc-cfg=feature=\"default-backend-llvm\""); | ||
} | ||
} | ||
} | ||
|
||
/// This function checks if the user specified a default backend | ||
fn has_default_backend() -> bool { | ||
std::env::var("CARGO_FEATURE_DEFAULT_BACKEND_SINGLEPASS").is_ok() | ||
|| std::env::var("CARGO_FEATURE_DEFAULT_BACKEND_CRANELIFT").is_ok() | ||
|| std::env::var("CARGO_FEATURE_DEFAULT_BACKEND_LLVM").is_ok() | ||
} | ||
|
||
fn main() { | ||
if !has_default_backend() { | ||
set_default_backend(); | ||
} | ||
} |