V2: Remove idl-build from Anchor crates#4512
Merged
jamie-osec merged 4 commits intoMay 8, 2026
Merged
Conversation
|
@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. |
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.
62a9d6e to
62db698
Compare
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We now only have
idl-buildin the end user crate