Skip to content

fix(core,chain): disable serde default features for no_std#2238

Open
ANAMASGARD wants to merge 1 commit into
bitcoindevkit:masterfrom
ANAMASGARD:fix/2208-serde-no-std-default-features
Open

fix(core,chain): disable serde default features for no_std#2238
ANAMASGARD wants to merge 1 commit into
bitcoindevkit:masterfrom
ANAMASGARD:fix/2208-serde-no-std-default-features

Conversation

@ANAMASGARD

Copy link
Copy Markdown

Description

Fixes #2208.

Both bdk_core and bdk_chain declared their serde dependency without default-features = false. Since serde's default feature set includes std, enabling bdk_chain/serde (or bdk_core/serde) in a downstream no_std crate activated serde/std through Cargo's feature unification, breaking compilation on bare-metal targets where std is unavailable.

This PR disables serde's default features in both crates and re-enables serde/std only through each crate's own std feature.

Changes

  • bdk_core / bdk_chain: serde = { version = "1", optional = true, default-features = false, features = ["derive", "rc", "alloc"] }
    • alloc mirrors the bitcoin crate and is required for no_std + alloc serialization
    • rc is kept unchanged (existing behavior)
  • Propagate serde/std only via each crate's std feature using serde?/std
  • CI (check-no-std job): added a cargo tree feature-graph assertion (--no-dev-dependencies) that fails if serde/std is pulled into a no_std build, plus a thumbv7em-none-eabihf bare-metal cargo check

Notes to the reviewers

cargo check --no-default-features --features serde on the host passes even before this fix, because the host provides std. The bug only surfaces on targets without std, so verification uses cargo tree -e features (dependency-graph proof) and a bare-metal target (compile proof).

Verified locally:

  • no_std + serde no longer pulls serde feature "std" for bdk_core and bdk_chain
  • std + serde still enables serde/std (no behavior change for std users)
  • Full test suite green: bdk_core, bdk_chain, bdk_file_store, bdk_testenv, bdk_bitcoind_rpc, bdk_electrum, bdk_esplora
  • cargo clippy --all-features --all-targets -- -D warnings, cargo doc, and cargo +nightly fmt --all --check all pass
image

Follow-up (out of scope): a no_std + miniscript + serde combination may still pull serde/std via upstream miniscript's serde dependency, which does not disable its default features. That is a separate upstream concern and is not addressed here.

Changelog notice

  • Fixed bdk_core and bdk_chain incorrectly enabling serde/std in no_std builds when the serde feature was enabled.

Checklists

All Submissions:

Bugfixes:

  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

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 bitcoindevkit#2208
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[core] Set default-features = false for serde dependency

1 participant