Skip to content

Commit

Permalink
Set well known defaults for wasm and arm
Browse files Browse the repository at this point in the history
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
pinkforest committed Dec 9, 2022
1 parent cc304c2 commit 97c84d7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -22,6 +22,7 @@ major series.

#### Other changes

* Set well known defaults for wasm and arm
* Update Maintenance Policies for SemVer
* Migrate documentation to docs.rs hosted
* Fix backend documentation generation
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Expand Up @@ -38,6 +38,9 @@ hex = "0.4.2"
rand = "0.8"
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }

[build-dependencies]
platforms = "3.0.2"

[[bench]]
name = "dalek_benchmarks"
harness = false
Expand Down
37 changes: 26 additions & 11 deletions build.rs
@@ -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\""),
}
}

0 comments on commit 97c84d7

Please sign in to comment.