forked from dalek-cryptography/curve25519-dalek
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes curve25519_dalek_bits defaults for cross and wasm
build.rs was using cfg(target) but it has to evaluate this from env TARGET as build.rs cfg(target) in build context is the builder host and not the target. This change fixes curve25519_dalek_bits lottery to determine the correct automatic curve25119_dalek_bits with the help of platforms crate. As discussed in dalek-cryptography#456 this also prepares for well known defaults for wasm and arm serial backend via cfg(curve25519_dalek_bits = "64") If the wasm32 or armv7 are going to be u64 serial by default these will be followed up on later.
- Loading branch information
1 parent
cc304c2
commit c32b031
Showing
4 changed files
with
76 additions
and
11 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,15 +1,45 @@ | ||
//! This selects the curve25519_dalek_bits either by default from target_pointer_width or explicitly set | ||
#[allow(non_camel_case_types)] | ||
enum DalekBits { | ||
Dalek32, | ||
Dalek64, | ||
} | ||
|
||
#[cfg(all(not(curve25519_dalek_bits = "64"), not(curve25519_dalek_bits = "32")))] | ||
#[deny(dead_code)] | ||
fn lotto_curve25519_dalek_bits() -> DalekBits { | ||
use platforms::target::PointerWidth; | ||
|
||
let target_triplet = std::env::var("TARGET").unwrap(); | ||
let platform = platforms::Platform::find(&target_triplet).unwrap(); | ||
|
||
match platform.target_arch { | ||
//Issues: 449 and 456 | ||
//TODO(Arm): Needs tests + benchmarks to back this up | ||
//platforms::target::Arch::Arm => DalekBits::Dalek64, | ||
//TODO(Wasm32): Needs tests + benchmarks to back this up | ||
//platforms::target::Arch::Wasm32 => DalekBits::Dalek64, | ||
_ => match platform.target_pointer_width { | ||
PointerWidth::U64 => DalekBits::Dalek64, | ||
PointerWidth::U32 => DalekBits::Dalek32, | ||
_ => DalekBits::Dalek32, | ||
}, | ||
} | ||
} | ||
|
||
fn main() { | ||
#[cfg(any( | ||
all(not(target_pointer_width = "64"), not(curve25519_dalek_bits = "64")), | ||
curve25519_dalek_bits = "32" | ||
))] | ||
println!("cargo:rustc-cfg=curve25519_dalek_bits=\"32\""); | ||
|
||
#[cfg(any( | ||
all(target_pointer_width = "64", not(curve25519_dalek_bits = "32")), | ||
curve25519_dalek_bits = "64" | ||
))] | ||
println!("cargo:rustc-cfg=curve25519_dalek_bits=\"64\""); | ||
#[cfg(curve25519_dalek_bits = "32")] | ||
let curve25519_dalek_bits = DalekBits::Dalek32; | ||
|
||
#[cfg(curve25519_dalek_bits = "64")] | ||
let curve25519_dalek_bits = DalekBits::Dalek64; | ||
|
||
#[cfg(all(not(curve25519_dalek_bits = "64"), not(curve25519_dalek_bits = "32")))] | ||
let curve25519_dalek_bits = lotto_curve25519_dalek_bits(); | ||
|
||
match curve25519_dalek_bits { | ||
DalekBits::Dalek64 => println!("cargo:rustc-cfg=curve25519_dalek_bits=\"64\""), | ||
DalekBits::Dalek32 => println!("cargo:rustc-cfg=curve25519_dalek_bits=\"32\""), | ||
} | ||
} |