Skip to content

V2: Remove idl-build from Anchor crates#4512

Merged
jamie-osec merged 4 commits into
otter-sec:anchor-nextfrom
jamie-osec:v2/decouple-idl-build
May 8, 2026
Merged

V2: Remove idl-build from Anchor crates#4512
jamie-osec merged 4 commits into
otter-sec:anchor-nextfrom
jamie-osec:v2/decouple-idl-build

Conversation

@jamie-osec

Copy link
Copy Markdown
Collaborator

We now only have idl-build in the end user crate

@vercel

vercel Bot commented May 7, 2026

Copy link
Copy Markdown

@jamie-osec is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

jamie-osec added 3 commits May 8, 2026 00:58
The program-level print test used to assemble accounts[]/types[] by parsing
each __IDL_TYPE string with serde_json and peeling off the discriminator at
runtime. Replace with two consts on IdlAccountType — __IDL_ACCOUNT_ENTRY
and __IDL_TYPE_DEF — both pre-built at macro-expansion time. The print
test now just dedupes and joins. Behavior is preserved for accounts;
events' types[] entry no longer carries a stray discriminator (matching
the IdlTypeDef spec). Tested via tests-v2/programs/constraints (26/26).

This is the prerequisite for dropping the idl-build feature from lang-v2:
serde_json was the only runtime cost of always-on IDL infrastructure.
The IDL infrastructure (IdlAccountType trait, primitive impls,
__idl_const_seed_json helper) ships unconditionally now that runtime
serde_json is gone. Trait declarations + empty default-method impls cost
zero bytes in BPF, so gating them behind a feature only created
threading busywork — every consumer crate had to redeclare
`idl-build = ["anchor-lang-v2/idl-build"]` and forgetting it silently
disabled IDL emission.

What changed:
- Removed all `cfg(feature = "idl-build")` gates from lang-v2/src and
  spl-v2/src — IdlAccountType impls, IDL_ADDRESS consts, prelude
  re-exports, and the idl_build module are now unconditional.
- Dropped `idl-build` feature + optional `serde_json` dep from
  anchor-lang-v2/Cargo.toml; dropped `idl-build` feature from spl-v2.
- End-user programs (tests-v2/programs/*, bench/programs/*) keep their
  own local `idl-build = []` feature — purely local, no library
  threading. The macro emissions in anchor-derive-accounts-v2 still
  gate on `cfg(feature = "idl-build")`, which now resolves only against
  the user crate.
- Updated cli/src/rust_template.rs scaffolding to match.
- Registered `feature = "idl-build"` in lang-v2's check-cfg so rustc
  doesn't warn when lang-v2's own integration tests apply derives that
  emit the cfg.

End-user impact: programs that opted into IDL emission via
`idl-build = ["anchor-lang-v2/idl-build"]` should change to
`idl-build = []`. `cargo test --features idl-build` keeps working
identically.
The IDL surface is implementation detail of the `anchor idl build`
pipeline — users should never call into it directly. Per the agreed
opaque/unstable contract:

- `IdlType` derive + `IdlAccountType` trait stay technically visible.
  Their pages now lead with **Opaque / unstable** notes warning users
  off direct use; impls of the trait carry `#[doc(hidden)]` so the
  trait page's "Implementors" section is empty and the impl never
  appears under "Trait Implementations" on user types.
- All emitted `__idl_accounts()`, `__idl_register_deps()` (account +
  Accounts struct), and `__idl_errors()` fns carry `#[doc(hidden)]`.
  `__idl_const_seed_json` is reachable only through the doc-hidden
  `idl_build` module.
- Wrapper impls (Box<T>, Slab, BorshAccount, Nested, Signer,
  Program<T>, Sysvar<T>, SystemAccount, UncheckedAccount, Mint,
  TokenAccount, Interface<T>, primitives, Vec, Option, [T; N], [T],
  &T, PodVec) all carry `#[doc(hidden)]`.

Verified `cargo doc -p constraints --features idl-build`: zero
references to IdlAccountType / __idl_* / __IDL_TYPE_DEF on the user
types' generated pages.
@jamie-osec jamie-osec force-pushed the v2/decouple-idl-build branch from 62a9d6e to 62db698 Compare May 7, 2026 23:58
After the IDL redesign, lang-v2 and spl-v2 no longer expose an
`idl-build` feature — passing `--features idl-build` to them in the
coverage host pass would now fail. The IDL-emission code paths instead
fire in end-user crates that declare their own local `idl-build = []`
feature.

Retarget the third coverage pass at `tests-v2/programs/{constraints,
derives,accounts,spl}` so the derive-emitted `IdlAccountType` impls,
`__idl_accounts()` / `__idl_register_deps()` / `__idl_errors()` fns,
and `__anchor_private_print_idl_*` test bodies still get instrumented.
Net coverage of the IDL paths is unchanged; the pass just lands the
`--features idl-build` flag on the crates that actually own the
feature now.
@codecov-commenter

codecov-commenter commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.76923% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.59%. Comparing base (b05ddb2) to head (32fdaf3).

Files with missing lines Patch % Lines
lang-v2/src/idl_build.rs 42.85% 20 Missing ⚠️
lang-v2/derive/src/lib.rs 40.00% 12 Missing ⚠️
lang-v2/derive/src/idl.rs 68.96% 9 Missing ⚠️
lang-v2/src/traits.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           anchor-next    #4512      +/-   ##
===============================================
+ Coverage        62.96%   63.59%   +0.62%     
===============================================
  Files               50       51       +1     
  Lines             6189     6471     +282     
===============================================
+ Hits              3897     4115     +218     
- Misses            2292     2356      +64     
Flag Coverage Δ
v2 63.59% <55.76%> (+0.62%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jamie-osec jamie-osec merged commit e3cf760 into otter-sec:anchor-next May 8, 2026
41 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants