diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 145bdacfe..1e8edede4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -3,21 +3,19 @@ on: [push, pull_request] name: Continuous integration jobs: - bench_nightly: - name: Nightly - ASan + Bench + Nightly: + name: Nightly - ASan + Bench + Docs runs-on: ubuntu-latest - strategy: - matrix: - rust: - - nightly steps: - - name: Checkout Crate + - name: Checkout Crate uses: actions/checkout@v2 + - name: Install clang # Needed for ASan. + run: sudo apt-get install -y clang-9 - name: Checkout Toolchain uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: ${{ matrix.rust }} + toolchain: nightly override: true components: rust-src - name: Running address sanitizer @@ -28,27 +26,17 @@ jobs: env: DO_BENCH: true run: ./contrib/test.sh + - name: Building docs + env: + DO_DOCS: true + run: ./contrib/test.sh Tests: name: Tests runs-on: ubuntu-latest strategy: matrix: - include: - - rust: stable - env: - DO_FEATURE_MATRIX: true - DO_WASM: true - - rust: beta - env: - DO_FEATURE_MATRIX: true - - rust: nightly - env: - DO_FEATURE_MATRIX: true - DO_DOCS: true - - rust: 1.29.0 - env: - DO_FEATURE_MATRIX: true + rust: [stable, beta, nightly, 1.29.0] steps: - name: Checkout Crate uses: actions/checkout@v2 @@ -62,6 +50,29 @@ jobs: if: matrix.rust == '1.29.0' run: cargo generate-lockfile --verbose && cargo update -p cc --precise "1.0.41" --verbose - name: Running cargo - env: ${{ matrix.env }} + env: + DO_FEATURE_MATRIX: true run: ./contrib/test.sh + WASM: + name: WASM + runs-on: ubuntu-latest + strategy: + matrix: + rust: [stable, beta, nightly] # WASM requires Rust 1.30 + steps: + - name: Checkout Crate + uses: actions/checkout@v2 + - name: Install clang + run: sudo apt-get install -y clang-10 + - name: Checkout Toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: rust-src + - name: Running WASM tests + env: + DO_WASM: true + run: ./contrib/test.sh diff --git a/contrib/test.sh b/contrib/test.sh index a892a78d2..0d9bb5e85 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -1,5 +1,7 @@ #!/bin/sh -ex +set -e + # TODO: Add "alloc" once we bump MSRV to past 1.29 FEATURES="bitcoin_hashes global-context lowmemory rand recovery serde std" # These features are typically enabled along with the 'std' feature, so we test @@ -15,6 +17,9 @@ fi cargo --version rustc --version +# Test if panic in C code aborts the process (either with a real panic or with SIGILL) +cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>&1 | tee /dev/stderr | grep "SIGILL\\|panicked at '\[libsecp256k1\]" + # Make all cargo invocations verbose export CARGO_TERM_VERBOSE=true @@ -64,11 +69,11 @@ fi # Webassembly stuff if [ "$DO_WASM" = true ]; then - clang --version && - CARGO_TARGET_DIR=wasm cargo install --force wasm-pack && - printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml && - CC=clang-9 wasm-pack build && - CC=clang-9 wasm-pack test --node; + clang --version + CARGO_TARGET_DIR=wasm cargo install --force wasm-pack + printf '\n[lib]\ncrate-type = ["cdylib", "rlib"]\n' >> Cargo.toml + CC=clang wasm-pack build + CC=clang wasm-pack test --node fi # Address Sanitizer @@ -77,20 +82,18 @@ if [ "$DO_ASAN" = true ]; then CC='clang -fsanitize=address -fno-omit-frame-pointer' \ RUSTFLAGS='-Zsanitizer=address -Clinker=clang -Cforce-frame-pointers=yes' \ ASAN_OPTIONS='detect_leaks=1 detect_invalid_pointer_pairs=1 detect_stack_use_after_return=1' \ - cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu && - cargo clean && + cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu + cargo clean CC='clang -fsanitize=memory -fno-omit-frame-pointer' \ RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes' \ - cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu && + cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu cargo run --release --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified Successfully" cargo run --release --features=alloc --manifest-path=./no_std_test/Cargo.toml | grep -q "Verified alloc Successfully" fi -# Test if panic in C code aborts the process (either with a real panic or with SIGILL) -cargo test -- --ignored --exact 'tests::test_panic_raw_ctx_should_terminate_abnormally' 2>&1 | tee /dev/stderr | grep "SIGILL\\|panicked at '\[libsecp256k1\]" - # Bench if [ "$DO_BENCH" = true ]; then cargo bench --all --features="unstable" fi +exit 0 diff --git a/secp256k1-sys/src/types.rs b/secp256k1-sys/src/types.rs index e257d437b..54cdb0ba1 100644 --- a/secp256k1-sys/src/types.rs +++ b/secp256k1-sys/src/types.rs @@ -66,41 +66,3 @@ mod tests { assert!(mem::align_of::() >= mem::align_of::()); } } - -#[doc(hidden)] -#[cfg(target_arch = "wasm32")] -pub fn sanity_checks_for_wasm() { - use core::mem::{align_of, size_of}; - extern "C" { - pub static WASM32_INT_SIZE: c_uchar; - pub static WASM32_INT_ALIGN: c_uchar; - - pub static WASM32_UNSIGNED_INT_SIZE: c_uchar; - pub static WASM32_UNSIGNED_INT_ALIGN: c_uchar; - - pub static WASM32_SIZE_T_SIZE: c_uchar; - pub static WASM32_SIZE_T_ALIGN: c_uchar; - - pub static WASM32_UNSIGNED_CHAR_SIZE: c_uchar; - pub static WASM32_UNSIGNED_CHAR_ALIGN: c_uchar; - - pub static WASM32_PTR_SIZE: c_uchar; - pub static WASM32_PTR_ALIGN: c_uchar; - } - unsafe { - assert_eq!(size_of::(), WASM32_INT_SIZE as usize); - assert_eq!(align_of::(), WASM32_INT_ALIGN as usize); - - assert_eq!(size_of::(), WASM32_UNSIGNED_INT_SIZE as usize); - assert_eq!(align_of::(), WASM32_UNSIGNED_INT_ALIGN as usize); - - assert_eq!(size_of::(), WASM32_SIZE_T_SIZE as usize); - assert_eq!(align_of::(), WASM32_SIZE_T_ALIGN as usize); - - assert_eq!(size_of::(), WASM32_UNSIGNED_CHAR_SIZE as usize); - assert_eq!(align_of::(), WASM32_UNSIGNED_CHAR_ALIGN as usize); - - assert_eq!(size_of::<*const ()>(), WASM32_PTR_SIZE as usize); - assert_eq!(align_of::<*const ()>(), WASM32_PTR_ALIGN as usize); - } -} diff --git a/secp256k1-sys/wasm-sysroot/stdio.h b/secp256k1-sys/wasm-sysroot/stdio.h index 36cc90052..e69de29bb 100644 --- a/secp256k1-sys/wasm-sysroot/stdio.h +++ b/secp256k1-sys/wasm-sysroot/stdio.h @@ -1,17 +0,0 @@ -#include -#define alignof(type) offsetof (struct { char c; type member; }, member) - -extern const unsigned char WASM32_INT_SIZE = sizeof(int); -extern const unsigned char WASM32_INT_ALIGN = alignof(int); - -extern const unsigned char WASM32_UNSIGNED_INT_SIZE = sizeof(unsigned int); -extern const unsigned char WASM32_UNSIGNED_INT_ALIGN = alignof(unsigned int); - -extern const unsigned char WASM32_SIZE_T_SIZE = sizeof(size_t); -extern const unsigned char WASM32_SIZE_T_ALIGN = alignof(size_t); - -extern const unsigned char WASM32_UNSIGNED_CHAR_SIZE = sizeof(unsigned char); -extern const unsigned char WASM32_UNSIGNED_CHAR_ALIGN = alignof(unsigned char); - -extern const unsigned char WASM32_PTR_SIZE = sizeof(void*); -extern const unsigned char WASM32_PTR_ALIGN = alignof(void*); \ No newline at end of file diff --git a/src/context.rs b/src/context.rs index b7568778a..f9f308914 100644 --- a/src/context.rs +++ b/src/context.rs @@ -192,9 +192,6 @@ mod alloc_only { /// ``` #[allow(unused_mut)] // Unused when `rand-std` is not enabled. pub fn gen_new() -> Secp256k1 { - #[cfg(target_arch = "wasm32")] - ffi::types::sanity_checks_for_wasm(); - let size = unsafe { ffi::secp256k1_context_preallocated_size(C::FLAGS) }; let layout = alloc::Layout::from_size_align(size, ALIGN_TO).unwrap(); let ptr = unsafe {alloc::alloc(layout)}; @@ -302,9 +299,6 @@ unsafe impl<'buf> Context for AllPreallocated<'buf> { impl<'buf, C: Context + 'buf> Secp256k1 { /// Lets you create a context with preallocated buffer in a generic manner(sign/verify/all) pub fn preallocated_gen_new(buf: &'buf mut [AlignedType]) -> Result, Error> { - #[cfg(target_arch = "wasm32")] - ffi::types::sanity_checks_for_wasm(); - if buf.len() < Self::preallocate_size_gen() { return Err(Error::NotEnoughMemory); }