Force use of portable blst in Rust bindings (#338)

This commit is contained in:
Justin Traglia 2023-08-11 10:19:02 -05:00 committed by GitHub
parent 74069dad68
commit d874c06b42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 34 deletions

View File

@ -11,20 +11,10 @@ license = "Apache-2.0"
[features] [features]
# BLST Compilation:
# By default, compile with ADX extension if the host supports it. Binary can be
# executed on systems similar to the host.
default = ["mainnet-spec"] default = ["mainnet-spec"]
mainnet-spec = [] mainnet-spec = []
minimal-spec = [] minimal-spec = []
# BLST Compilation:
# Compile in portable mode, without ISA extensions.
# Binary can be executed on all systems.
portable = []
# BLST Compilation:
# Enable ADX even if the host CPU doesn't support it.
# Binary can be executed on Broadwell+ and Ryzen+ systems.
force-adx = []
# BLST Compilation: # BLST Compilation:
# Suppress multi-threading. # Suppress multi-threading.
# Engaged on wasm32 target architecture automatically. # Engaged on wasm32 target architecture automatically.

View File

@ -58,29 +58,7 @@ fn compile_blst(blst_base_dir: PathBuf) {
} else { } else {
cc.define("__BLST_NO_ASM__", None); cc.define("__BLST_NO_ASM__", None);
} }
match (cfg!(feature = "portable"), cfg!(feature = "force-adx")) { cc.define("__BLST_PORTABLE__", None);
(true, false) => {
println!("Compiling in portable mode without ISA extensions");
cc.define("__BLST_PORTABLE__", None);
}
(false, true) => {
if target_arch.eq("x86_64") {
println!("Enabling ADX support via `force-adx` feature");
cc.define("__ADX__", None);
} else {
println!("`force-adx` is ignored for non-x86_64 targets");
}
}
(false, false) =>
{
#[cfg(target_arch = "x86_64")]
if target_arch.eq("x86_64") && std::is_x86_feature_detected!("adx") {
println!("Enabling ADX because it was detected on the host");
cc.define("__ADX__", None);
}
}
(true, true) => panic!("Cannot compile with both `portable` and `force-adx` features"),
}
if env::var("CARGO_CFG_TARGET_ENV").unwrap().eq("msvc") { if env::var("CARGO_CFG_TARGET_ENV").unwrap().eq("msvc") {
cc.flag("-Zl"); cc.flag("-Zl");
} }