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.
Set well known defaults for wasm and arm
As discussed in dalek-cryptography#456 this sets well known defaults for cfg(target_family = "wasm") and cfg(target_arch = "arm") for 64 bit arithmetric via cfg(curve25519_dalek_bits = "64")
- Loading branch information
1 parent
cc304c2
commit 97c84d7
Showing
3 changed files
with
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,30 @@ | ||
//! This selects the curve25519_dalek_bits either by default from target_pointer_width or explicitly set | ||
use platforms::target::{Arch, PointerWidth}; | ||
|
||
#[allow(non_camel_case_types)] | ||
enum DalekBits { | ||
Dalek32, | ||
Dalek64, | ||
} | ||
|
||
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\""); | ||
let target_triplet = std::env::var("TARGET").unwrap(); | ||
let platform = platforms::Platform::find(&target_triplet).unwrap(); | ||
|
||
let curve25519_dalek_bits = match platform.target_arch { | ||
Arch::Arm => DalekBits::Dalek64, | ||
//TODO: Needs tests + benchmarks to back it up across | ||
//Arch::Wasm32 => DalekBits::Dalek64, | ||
_ => match platform.target_pointer_width { | ||
PointerWidth::U64 => DalekBits::Dalek64, | ||
PointerWidth::U32 => DalekBits::Dalek32, | ||
_ => DalekBits::Dalek32, | ||
}, | ||
}; | ||
|
||
match curve25519_dalek_bits { | ||
DalekBits::Dalek64 => println!("cargo:rustc-cfg=curve25519_dalek_bits=\"64\""), | ||
DalekBits::Dalek32 => println!("cargo:rustc-cfg=curve25519_dalek_bits=\"32\""), | ||
} | ||
} |