From 20231c47a7efb113760a23f3dfaac87690e081b4 Mon Sep 17 00:00:00 2001 From: Einherjar Date: Thu, 19 Oct 2023 09:34:53 -0300 Subject: [PATCH] ci: WASM checks --- .github/workflows/cont_integration.yml | 50 +++++++++------------ Cargo.lock | 24 +++++++--- CargoMSRV.lock | 10 +++++ crates/bdk/Cargo.toml | 4 +- flake.nix | 61 ++++++++++++++++++-------- 5 files changed, 93 insertions(+), 56 deletions(-) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 3ecfe6ac95..0e26e11e21 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -28,12 +28,17 @@ jobs: name: bitcoindevkit authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' continue-on-error: true # for forks outside of bitcoindevkit GH org + # Cache Builds - name: Build and Cache latest Rust run: nix build -L . --keep-failed - - name: Build and Cache MRSV Rust + - name: Build and Cache MRSV run: nix build -L .#MSRV --keep-failed + - name: Build and Cache WASM + run: nix build -L .#WASM --keep-failed + # Rustfmt - name: Rustfmt run: nix build -L .#ci.fmt --keep-failed + # Clippy - name: Clippy run: nix build -L .#ci.clippy --keep-failed # Audit @@ -42,40 +47,27 @@ jobs: # Tests: latest - name: Test workspace all-features latest run: nix build -L .#ci.latest.all --keep-failed - - name: Test '--no-default-features' latest Rust + - name: Test workspace no-default-features latest run: nix build -L .#ci.latest.noDefault --keep-failed - - name: Test '-p bdk' no-std latest Rust + - name: Test bdk no-std latest run: nix build -L .#ci.latest.noStdBdk --keep-failed - - name: Test '-p chain' no-std latest Rust + - name: Test bdk_chain no-std latest run: nix build -L .#ci.latest.noStdChain --keep-failed - - name: Test '-p esplora' no-std latest Rust + - name: Test bdk_esplora no-std latest run: nix build -L .#ci.latest.noStdEsplora --keep-failed - - name: Test '--all-features' MSRV Rust + # Tests: MSRV + - name: Test workspace all-features MSRV run: nix build -L .#ci.MSRV.all --keep-failed - - name: Test '--no-default-features' MSRV Rust + - name: Test workspace no-default-features MSRV run: nix build -L .#ci.MSRV.noDefault --keep-failed - - name: Test '-p bdk' no-std MSRV Rust + - name: Test bdk no-std MSRV run: nix build -L .#ci.MSRV.noStdBdk --keep-failed - - name: Test '-p chain' no-std MSRV Rust + - name: Test bdk_chain no-std MSRV run: nix build -L .#ci.MSRV.noStdChain --keep-failed - - name: Test '-p esplora' no-std MSRV Rust + - name: Test bdk_esplora no-std MSRV run: nix build -L .#ci.MSRV.noStdEsplora --keep-failed - # check-wasm: - # name: Check WASM - # runs-on: ubuntu-20.04 - # env: - # CC: clang-10 - # CFLAGS: -I/usr/include - # steps: - # - name: Checkout - # uses: actions/checkout@v4 - # - name: Install Nix - # uses: DeterminateSystems/nix-installer-action@v5 - # - name: Rust Cache - # uses: Swatinem/rust-cache@v2.2.1 - # - name: Check bdk - # working-directory: ./crates/bdk - # run: 'nix develop -L .#test.WASM --command bash -c "cargo check --target wasm32-unknown-unknown --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown,dev-getrandom-wasm"' - # - name: Check esplora - # working-directory: ./crates/esplora - # run: 'nix develop -L .#test.WASM --command bash -c "cargo check --target wasm32-unknown-unknown --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown,async"' + # Checks: WASM + - name: Check bdk WASM + run: nix build -L .#ci.WASM.bdk --keep-failed + - name: Check bdk_esplora WASM + run: nix build -L .#ci.WASM.esplora --keep-failed diff --git a/Cargo.lock b/Cargo.lock index 36547a9d86..57adf50025 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,6 +112,7 @@ dependencies = [ "bdk_chain", "bip39", "bitcoin", + "core2", "env_logger", "getrandom", "hwi", @@ -401,6 +402,15 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +[[package]] +name = "core2" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "239fa3ae9b63c2dc74bd3fa852d4792b8b305ae64eeede946265b6af62f1fff3" +dependencies = [ + "memchr", +] + [[package]] name = "crc32fast" version = "1.3.2" @@ -1493,9 +1503,9 @@ dependencies = [ [[package]] name = "ring" -version = "0.17.4" +version = "0.17.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fce3045ffa7c981a6ee93f640b538952e155f1ae3a1a02b84547fc7a56b7059a" +checksum = "fb0205304757e5d899b9c2e448b867ffd03ae7f988002e47cd24954391394d0b" dependencies = [ "cc", "getrandom", @@ -1513,9 +1523,9 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.19" +version = "0.38.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" +checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0" dependencies = [ "bitflags 2.4.1", "errno", @@ -1900,9 +1910,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.39" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2ef2af84856a50c1d430afce2fdded0a4ec7eda868db86409b4543df0797f9" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "pin-project-lite", "tracing-core", @@ -2129,7 +2139,7 @@ version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed63aea5ce73d0ff405984102c42de94fc55a6b75765d621c65262469b3c9b53" dependencies = [ - "ring 0.17.4", + "ring 0.17.5", "untrusted 0.9.0", ] diff --git a/CargoMSRV.lock b/CargoMSRV.lock index d8a7425c5c..442f3e76f3 100644 --- a/CargoMSRV.lock +++ b/CargoMSRV.lock @@ -112,6 +112,7 @@ dependencies = [ "bdk_chain", "bip39", "bitcoin", + "core2", "env_logger", "getrandom", "hwi", @@ -401,6 +402,15 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +[[package]] +name = "core2" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "239fa3ae9b63c2dc74bd3fa852d4792b8b305ae64eeede946265b6af62f1fff3" +dependencies = [ + "memchr", +] + [[package]] name = "crc32fast" version = "1.3.2" diff --git a/crates/bdk/Cargo.toml b/crates/bdk/Cargo.toml index 0fa7524e49..eb7d99c97a 100644 --- a/crates/bdk/Cargo.toml +++ b/crates/bdk/Cargo.toml @@ -22,7 +22,7 @@ serde_json = { version = "^1.0" } bdk_chain = { path = "../chain", version = "0.6.0", features = ["miniscript", "serde"], default-features = false } # Optional dependencies -hwi = { version = "0.7.0", optional = true, features = [ "miniscript"] } +hwi = { version = "0.7.0", optional = true, features = ["miniscript"] } bip39 = { version = "1.0.1", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] @@ -47,6 +47,8 @@ dev-getrandom-wasm = ["getrandom/js"] lazy_static = "1.4" env_logger = "0.7" assert_matches = "1.5.0" +# WASM dep for rust-bitcoin +core2 = { version = "0.3", default_features = false } [package.metadata.docs.rs] all-features = true diff --git a/flake.nix b/flake.nix index 7911cea681..a5ecf852af 100644 --- a/flake.nix +++ b/flake.nix @@ -73,7 +73,7 @@ craneClippyLib = (crane.mkLib pkgs).overrideToolchain rustClippyTarget; # MSRV specific configs # WASM specific configs - # craneUtils needs to be built using Rust latest (not MSRV) + # craneUtils needs to be built using Rust latest (not MSRV/WASM) # check https://github.com/ipetkov/crane/issues/422 craneMSRVLib = ((crane.mkLib pkgs).overrideToolchain rustMSRVTarget).overrideScope' (final: prev: { inherit (craneLib) craneUtils; }); craneWASMLib = ((crane.mkLib pkgs).overrideToolchain rustWASMTarget).overrideScope' (final: prev: { inherit (craneLib) craneUtils; }); @@ -91,9 +91,12 @@ ] ++ lib.optionals isDarwin libsDarwin; # WASM deps - wasmInputs = [ + WASMInputs = [ # Additional wasm specific inputs can be set here - pkgs.wasm-bindgen-cli + pkgs.llvmPackages_14.clang-unwrapped + pkgs.llvmPackages_14.stdenv + pkgs.llvmPackages_14.libcxxClang + pkgs.llvmPackages_14.libcxxStdenv ]; nativeBuildInputs = [ @@ -114,8 +117,7 @@ # bitcoin_rpc uses `.db` in the source code (lib.hasSuffix "\.db" path) || # Default filter from crane (allow .rs files) - (craneLib.filterCargoSources path type) - ; + (craneLib.filterCargoSources path type); }; # Fixing name/version here to avoid warnings @@ -139,8 +141,18 @@ # WASM derivation arguments WASMArgs = { CARGO_BUILD_TARGET = "wasm32-unknown-unknown"; - buildInputs = buildInputs ++ wasmInputs; + buildInputs = buildInputs ++ WASMInputs; inherit nativeBuildInputs; + # crane tries to run the WASM file as if it were a binary + doCheck = false; + # just build bdk for now + cargoExtraArgs = "--locked --target wasm32-unknown-unknown -p bdk --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown,dev-getrandom-wasm"; + # env vars + CC = "${stdenv.cc.nativePrefix}cc"; + AR = "${stdenv.cc.nativePrefix}ar"; + CC_wasm32_unknown_unknown = "${pkgs.llvmPackages_14.clang-unwrapped}/bin/clang-14"; + CFLAGS_wasm32_unknown_unknown = "-I ${pkgs.llvmPackages_14.libclang.lib}/lib/clang/14.0.6/include/"; + AR_wasm32_unknown_unknown = "${pkgs.llvmPackages_14.llvm}/bin/llvm-ar"; }; @@ -167,11 +179,11 @@ rustFmtExtraArgs = "--config format_code_in_doc_comments=true"; }); in - rec - { + rec { checks = { inherit clippy; inherit fmt; + # Latest latest = packages.default; latestAll = craneLib.cargoTest (commonArgs // { @@ -194,6 +206,7 @@ inherit cargoArtifacts; cargoCheckExtraArgs = "-p bdk_esplora --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown"; }); + # MSRV MSRV = packages.MSRV; MSRVAll = craneMSRVLib.cargoTest (commonArgs // MSRVArgs // { @@ -216,15 +229,16 @@ cargoArtifacts = cargoArtifactsMSRV; cargoCheckExtraArgs = "-p bdk_esplora --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown"; }); + # WASM - # WASMBdk = craneWASMLib.cargoBuild (commonArgs // WASMArgs // { - # cargoArtifacts = cargoArtifactsWASM; - # cargoCheckExtraArgs = "-p bdk --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown,dev-getrandom-wasm"; - # }); - # WASMEsplora = craneWASMLib.cargoBuild (commonArgs // WASMArgs // { - # cargoArtifacts = cargoArtifactsWASM; - # cargoCheckExtraArgs = "-p bdk_esplora --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown,async"; - # }); + WASMBdk = craneWASMLib.buildPackage (commonArgs // WASMArgs // { + cargoArtifacts = cargoArtifactsWASM; + }); + WASMEsplora = craneWASMLib.cargoBuild (commonArgs // WASMArgs // { + cargoArtifacts = cargoArtifactsWASM; + cargoExtraArgs = "--locked -p bdk_esplora --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown,async"; + }); + # Audit dependencies audit = craneLib.cargoAudit (commonArgs // { inherit advisory-db; @@ -240,7 +254,7 @@ cargoArtifacts = cargoArtifactsMSRV; }); WASM = craneWASMLib.cargoBuild (commonArgs // WASMArgs // { - cargoArtifacts = null; + cargoArtifacts = cargoArtifactsWASM; }); }; legacyPackages = { @@ -262,6 +276,10 @@ noStdChain = checks.MSRVNoStdChain; noStdEsplora = checks.MSRVNoStdEsplora; }; + WASM = { + bdk = checks.WASMBdk; + esplora = checks.WASMEsplora; + }; }; }; @@ -329,7 +347,7 @@ noStdEsplora = checks.MSRVNoStdEsplora; }; # dependencies - packages = buildInputs ++ [ + packages = buildInputs ++ WASMInputs ++ [ pkgs.bashInteractive pkgs.git pkgs.ripgrep @@ -338,7 +356,12 @@ BITCOIND_EXEC = commonArgs.BITCOIND_EXEC; ELECTRS_EXEC = commonArgs.ELECTRS_EXEC; - CARGO_BUILD_TARGET = "wasm32-unknown-unknown"; + CARGO_BUILD_TARGET = WASMArgs.CARGO_BUILD_TARGET; + CC = WASMArgs.CC; + AR = WASMArgs.AR; + CC_wasm32_unknown_unknown = WASMArgs.CC_wasm32_unknown_unknown; + CFLAGS_wasm32_unknown_unknown = WASMArgs.CFLAGS_wasm32_unknown_unknown; + AR_wasm32_unknown_unknown = WASMArgs.AR_wasm32_unknown_unknown; }; }; }