From c873f72ed5ee61562a46849ca9efb0b9076b117f Mon Sep 17 00:00:00 2001 From: pinkforest <36498018+pinkforest@users.noreply.github.com> Date: Fri, 9 Dec 2022 21:53:02 +1100 Subject: [PATCH] Set well known defaults for wasm and arm As discussed in #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") --- .github/workflows/rust.yml | 33 +++++++++++++++++++++++++ CHANGELOG.md | 1 + Cargo.toml | 3 +++ build.rs | 50 +++++++++++++++++++++++++++++--------- 4 files changed, 76 insertions(+), 11 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 57330f6a6..e3132388c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 841d3809f..cb1572d85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Cargo.toml b/Cargo.toml index 17ba12ea8..8b7db7831 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/build.rs b/build.rs index cb896efd6..d4b4af050 100644 --- a/build.rs +++ b/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\""), + } }