From 05a4e3963cbd41ef967796d2216fcdf6705affd7 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 3 Jul 2024 05:46:18 +0200 Subject: [PATCH 1/8] Don't use `core::i32::MAX` This is a legacy constant and it's better to just use `i32::MAX`. Note that one cannot `use` an associated constant so this just removed the import. This is better anyway since it's only used once and it didn't provide meaningful line length reduction. --- src/key.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/key.rs b/src/key.rs index 012f09d36..9a868980d 100644 --- a/src/key.rs +++ b/src/key.rs @@ -638,10 +638,9 @@ impl PublicKey { /// # } /// ``` pub fn combine_keys(keys: &[&PublicKey]) -> Result { - use core::i32::MAX; use core::mem::transmute; - if keys.is_empty() || keys.len() > MAX as usize { + if keys.is_empty() || keys.len() > i32::MAX as usize { return Err(InvalidPublicKeySum); } From 614fe81708b86d8119de4706f379d6651f67a8c6 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 3 Jul 2024 06:02:12 +0200 Subject: [PATCH 2/8] Whitelist known cfgs Rust is now checking cfg attributes for typos but this interferes with our cfgs that rustc/cargo don't recognize. This whitelists them so they no longer produce warnings. --- Cargo.toml | 2 ++ secp256k1-sys/Cargo.toml | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index a1958d945..7a3403864 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,6 +54,8 @@ bincode = "1.3.3" wasm-bindgen-test = "0.3" getrandom = { version = "0.2", features = ["js"] } +[lints.rust] +unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)', 'cfg(secp256k1_fuzz)', 'cfg(rust_secp_no_symbol_renaming)'] } [[example]] name = "sign_verify_recovery" diff --git a/secp256k1-sys/Cargo.toml b/secp256k1-sys/Cargo.toml index 5d591ffcb..1ca432045 100644 --- a/secp256k1-sys/Cargo.toml +++ b/secp256k1-sys/Cargo.toml @@ -32,3 +32,6 @@ recovery = [] lowmemory = [] std = ["alloc"] alloc = [] + +[lints.rust] +unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)', 'cfg(secp256k1_fuzz)', 'cfg(rust_secp_no_symbol_renaming)'] } From 924ba381c8541805fd1bf029213f6a1776fadb3b Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 3 Jul 2024 06:43:40 +0200 Subject: [PATCH 3/8] Update panic message handling The newest nightly stabilized `PanicMessage` with a slightly different API. This updates the API and removes the `#![feature()]` attribute. --- no_std_test/src/main.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/no_std_test/src/main.rs b/no_std_test/src/main.rs index eb3871f47..e93c2eb09 100644 --- a/no_std_test/src/main.rs +++ b/no_std_test/src/main.rs @@ -29,7 +29,6 @@ #![feature(start)] #![feature(core_intrinsics)] -#![feature(panic_info_message)] #![feature(alloc_error_handler)] #![no_std] extern crate libc; @@ -48,7 +47,7 @@ extern crate wee_alloc; #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; -use core::fmt::{self, write, Write}; +use core::fmt::{self, Write}; use core::intrinsics; use core::panic::PanicInfo; @@ -170,9 +169,9 @@ impl Write for Print { #[panic_handler] fn panic(info: &PanicInfo) -> ! { unsafe { libc::printf("shi1\n\0".as_ptr() as _) }; - let msg = info.message().unwrap(); + let msg = info.message(); let mut buf = Print::new(); - write(&mut buf, *msg).unwrap(); + write!(&mut buf, "{}", msg).unwrap(); buf.print(); intrinsics::abort() } From df0523a0a72c7e3a59abf48a097de6a8c1f840c4 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 3 Jul 2024 06:45:23 +0200 Subject: [PATCH 4/8] Use `libc::abort` instead of `intrinsics::abort` Despite using the `#![feature()]` attribute rustc still warns about it being unstable. Changing it to `libc::abort` gets rid of the annoying message. --- no_std_test/src/main.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/no_std_test/src/main.rs b/no_std_test/src/main.rs index e93c2eb09..53898873a 100644 --- a/no_std_test/src/main.rs +++ b/no_std_test/src/main.rs @@ -28,7 +28,6 @@ //! #![feature(start)] -#![feature(core_intrinsics)] #![feature(alloc_error_handler)] #![no_std] extern crate libc; @@ -48,7 +47,6 @@ extern crate wee_alloc; static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; use core::fmt::{self, Write}; -use core::intrinsics; use core::panic::PanicInfo; use secp256k1::ecdh::{self, SharedSecret}; @@ -61,6 +59,10 @@ use serde_cbor::de; use serde_cbor::ser::SliceWrite; use serde_cbor::Serializer; +fn abort() -> ! { + unsafe { libc::abort() } +} + struct FakeRng; impl RngCore for FakeRng { fn next_u32(&mut self) -> u32 { @@ -157,7 +159,7 @@ impl Write for Print { if curr + s.len() > MAX_PRINT { unsafe { libc::printf("overflow\n\0".as_ptr() as _); - intrinsics::abort(); + abort(); } } self.loc += s.len(); @@ -173,11 +175,11 @@ fn panic(info: &PanicInfo) -> ! { let mut buf = Print::new(); write!(&mut buf, "{}", msg).unwrap(); buf.print(); - intrinsics::abort() + abort() } #[alloc_error_handler] fn alloc_error(_layout: Layout) -> ! { unsafe { libc::printf("alloc shi1\n\0".as_ptr() as _) }; - intrinsics::abort() + abort() } From 2572fb6ab0c9323d98b58c57c0ec9634f03caefa Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Thu, 4 Jul 2024 07:22:40 +0200 Subject: [PATCH 5/8] Migrate `no_std_test` to edition 2021 Previously we had dependency problems that were resolved by resolver v2. We want to activate it just in case it happens again but even better, bump the edition. This was probably forgotten when other crates were migrated. --- no_std_test/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/no_std_test/Cargo.toml b/no_std_test/Cargo.toml index d36523550..31ce5c17e 100644 --- a/no_std_test/Cargo.toml +++ b/no_std_test/Cargo.toml @@ -2,6 +2,7 @@ name = "no_std_test" version = "0.1.0" authors = ["Elichai Turkel "] +edition = "2021" [features] alloc = ["secp256k1/alloc", "wee_alloc"] From 742c69f9757745e7e2ba8343f10bc79c5e788a78 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Thu, 4 Jul 2024 08:14:18 +0200 Subject: [PATCH 6/8] Compile `no_std` test using xargo The `no_std` test disables `std`, so unwinding is unsupported, so we use `panic = "abort"` but the `core` library is compiled with unwind by default which breaks the build. Xargo can handle this by recompiling `core` with `panic = "abort"` so we use it. --- .github/workflows/rust.yml | 2 ++ contrib/_test.sh | 6 ++++-- no_std_test/Xargo.toml | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 no_std_test/Xargo.toml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f435fdda7..bbe07b19d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -46,6 +46,8 @@ jobs: uses: dtolnay/rust-toolchain@nightly - name: Install src run: rustup component add rust-src + - name: Install xargo + run: cargo install xargo - name: Running test script env: DO_FMT: true diff --git a/contrib/_test.sh b/contrib/_test.sh index e18b23146..d415b5689 100755 --- a/contrib/_test.sh +++ b/contrib/_test.sh @@ -101,8 +101,10 @@ if [ "$DO_ASAN" = true ]; then RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins -Cforce-frame-pointers=yes -Cllvm-args=-msan-eager-checks=0' \ 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" + cd no_std_test + xargo run --release --target=x86_64-unknown-linux-gnu | grep -q "Verified Successfully" + xargo run --release --target=x86_64-unknown-linux-gnu --features=alloc | grep -q "Verified alloc Successfully" + cd - fi # Run formatter if told to. diff --git a/no_std_test/Xargo.toml b/no_std_test/Xargo.toml new file mode 100644 index 000000000..de8cec3df --- /dev/null +++ b/no_std_test/Xargo.toml @@ -0,0 +1,2 @@ +[dependencies] +alloc = {} From 24e81eeadb15b448657dd1b6a0c5e1d622acc306 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Thu, 4 Jul 2024 09:41:56 +0200 Subject: [PATCH 7/8] Run cross with --verbose flag This can help debug CI issues. --- .github/workflows/cross.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cross.yml b/.github/workflows/cross.yml index fb92c84d7..84c8e894f 100644 --- a/.github/workflows/cross.yml +++ b/.github/workflows/cross.yml @@ -53,4 +53,4 @@ jobs: - name: install cross run: cargo install cross - name: run cross test - run: cross test --target ${{ matrix.arch }} + run: cross test --target ${{ matrix.arch }} --verbose From 33a1893c14f242ba0653bbb26a9dad6f83ea81c2 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Thu, 4 Jul 2024 10:17:26 +0200 Subject: [PATCH 8/8] Upgrade cross image for windows Cross uses an old image by default and there's a problem that is resolved in the newest wine version, so this commit upgrades the image. --- Cross.toml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Cross.toml diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 000000000..cc9bc4cfb --- /dev/null +++ b/Cross.toml @@ -0,0 +1,2 @@ +[target.x86_64-pc-windows-gnu] +image = "ghcr.io/cross-rs/x86_64-pc-windows-gnu:main"