Skip to content

Commit

Permalink
ci: WASM checks
Browse files Browse the repository at this point in the history
  • Loading branch information
realeinherjar committed Oct 19, 2023
1 parent d716439 commit 20231c4
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 56 deletions.
50 changes: 21 additions & 29 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/[email protected]
# - 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
24 changes: 17 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions CargoMSRV.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ dependencies = [
"bdk_chain",
"bip39",
"bitcoin",
"core2",
"env_logger",
"getrandom",
"hwi",
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion crates/bdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
61 changes: 42 additions & 19 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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; });
Expand All @@ -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 = [
Expand All @@ -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
Expand All @@ -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";
};


Expand All @@ -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 // {
Expand All @@ -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 // {
Expand All @@ -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;
Expand All @@ -240,7 +254,7 @@
cargoArtifacts = cargoArtifactsMSRV;
});
WASM = craneWASMLib.cargoBuild (commonArgs // WASMArgs // {
cargoArtifacts = null;
cargoArtifacts = cargoArtifactsWASM;
});
};
legacyPackages = {
Expand All @@ -262,6 +276,10 @@
noStdChain = checks.MSRVNoStdChain;
noStdEsplora = checks.MSRVNoStdEsplora;
};
WASM = {
bdk = checks.WASMBdk;
esplora = checks.WASMEsplora;
};
};
};

Expand Down Expand Up @@ -329,7 +347,7 @@
noStdEsplora = checks.MSRVNoStdEsplora;
};
# dependencies
packages = buildInputs ++ [
packages = buildInputs ++ WASMInputs ++ [
pkgs.bashInteractive
pkgs.git
pkgs.ripgrep
Expand All @@ -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;
};
};
}
Expand Down

0 comments on commit 20231c4

Please sign in to comment.