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 c873f72
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 11 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/rust.yml
Expand Up @@ -48,6 +48,39 @@ jobs:
RUSTFLAGS: '--cfg curve25519_dalek_backend="simd" -C target_feature=+avx512ifma'
run: cargo build --target x86_64-unknown-linux-gnu

cross:
strategy:
matrix:
include:
# ARM32
- target: armv7-unknown-linux-gnueabihf
rust: 1.56.1 # MSRV (cross)
- target: armv7-unknown-linux-gnueabihf
rust: stable

# ARM64
- target: aarch64-unknown-linux-gnu
rust: 1.56.1 # MSRV (cross)
- target: aarch64-unknown-linux-gnu
rust: stable

# PPC32
- target: powerpc-unknown-linux-gnu
rust: 1.56.1 # MSRV (cross)
- target: powerpc-unknown-linux-gnu
rust: stable

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: ${{ matrix.deps }}
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- run: cargo install cross
- run: cross test --release --target ${{ matrix.target }}

nightly:
name: Test nightly compiler
runs-on: ubuntu-latest
Expand Down
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
50 changes: 39 additions & 11 deletions build.rs
@@ -1,15 +1,43 @@
//! 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::{Arch, PointerWidth};

let target_triplet = std::env::var("TARGET").unwrap();
let platform = platforms::Platform::find(&target_triplet).unwrap();

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,
},
}
}

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\""),
}
}

0 comments on commit c873f72

Please sign in to comment.