From a11bc4acbfee5816d7e2cc7364217b98c75838ed Mon Sep 17 00:00:00 2001 From: Gaurav Chaudhary Date: Tue, 7 Jul 2026 16:57:35 +0530 Subject: [PATCH] fix(core,chain): disable serde default features for no_std Serde's default `std` feature was leaking into downstream no_std builds via Cargo feature unification when `bdk_chain/serde` was enabled. Gate `serde/std` behind each crate's `std` feature instead, add the `alloc` feature (matching the `bitcoin` crate), and guard against regressions in CI with a feature-tree assertion plus a bare-metal target check. Fixes #2208 --- .github/workflows/cont_integration.yml | 21 +++++++++++++++++++++ crates/chain/Cargo.toml | 4 ++-- crates/core/Cargo.toml | 4 ++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 1a5c38444..9e44f2542 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -72,6 +72,27 @@ jobs: working-directory: ./crates/chain # TODO "--target thumbv6m-none-eabi" should work but currently does not run: cargo check --no-default-features --features hashbrown + - name: Check serde does not enable serde/std in no_std builds + run: | + set -euo pipefail + check_no_serde_std() { + local pkg="$1" features="$2" + if cargo tree -p "$pkg" -e features \ + --no-default-features --features "$features" --no-dev-dependencies \ + | grep -q 'serde feature "std"'; then + echo "error: serde/std enabled for $pkg with features=$features" + exit 1 + fi + } + check_no_serde_std bdk_core serde + check_no_serde_std bdk_chain serde + - name: Install ARM cross-compiler + run: sudo apt-get update && sudo apt-get install -y gcc-arm-none-eabi + - name: Add bare-metal target + run: rustup target add thumbv7em-none-eabihf + - name: Check bdk_chain serde on bare-metal target + working-directory: ./crates/chain + run: cargo check --no-default-features --features serde --target thumbv7em-none-eabihf - name: Check esplora working-directory: ./crates/esplora # TODO "--target thumbv6m-none-eabi" should work but currently does not diff --git a/crates/chain/Cargo.toml b/crates/chain/Cargo.toml index 949f177c8..8a65e7d1c 100644 --- a/crates/chain/Cargo.toml +++ b/crates/chain/Cargo.toml @@ -18,7 +18,7 @@ workspace = true [dependencies] bitcoin = { version = "0.32.0", default-features = false } bdk_core = { path = "../core", version = "0.6.2", default-features = false } -serde = { version = "1", optional = true, features = ["derive", "rc"] } +serde = { version = "1", optional = true, default-features = false, features = ["derive", "rc", "alloc"] } miniscript = { version = "13.0.0", optional = true, default-features = false } # Feature dependencies @@ -32,7 +32,7 @@ criterion = { version = "0.7" } [features] default = ["std", "miniscript"] -std = ["bitcoin/std", "miniscript?/std", "bdk_core/std"] +std = ["bitcoin/std", "miniscript?/std", "bdk_core/std", "serde?/std"] serde = ["dep:serde", "bitcoin/serde", "miniscript?/serde", "bdk_core/serde"] hashbrown = ["bdk_core/hashbrown"] rusqlite = ["std", "dep:rusqlite", "serde"] diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index ed313f3ae..29f988cb9 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -12,12 +12,12 @@ readme = "README.md" [dependencies] bitcoin = { version = "0.32", default-features = false } -serde = { version = "1", optional = true, features = ["derive", "rc"] } +serde = { version = "1", optional = true, default-features = false, features = ["derive", "rc", "alloc"] } hashbrown = { version = "0.14.5", optional = true, default-features = false, features = ["ahash", "inline-more"] } [features] default = ["std"] -std = ["bitcoin/std"] +std = ["bitcoin/std", "serde?/std"] serde = ["dep:serde", "bitcoin/serde", "hashbrown?/serde"] [dev-dependencies]