From 15ea8cdcccd3c1ab6a18c1e0c17e5e567252ebd1 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 20 Aug 2026 18:36:41 +0000 Subject: [PATCH] ci: skip IDL generation where Anchor 2.0.0-rc.1 cannot parse its own output TEMPORARY. Delete the block in anchor.yml when a release after 2.0.0-rc.1 ships; the upstream fix is already merged. anchor-derive-accounts 2.0.0-rc.1 emits enum type definitions with the JSON key "fields" where anchor-lang-idl-spec requires "variants", so `anchor build` cannot deserialize the IDL it just generated: Error: missing field `variants` at line 1 column N The defect is one shared helper: `type_def_header_parts` in anchor-derive-accounts' `src/idl.rs` hardcodes "fields" and is called by both the struct emitter (kind_name = "struct", correct) and the enum emitter (kind_name = "enum", wrong). A two-variant enum reproduces it. Fixed upstream in https://github.com/otter-sec/anchor/pull/4947, unreleased at the time of writing. Patching only the derive crate to that commit does not work: it requires solana-address 2.7, and these programs pin `>=2.6, <2.7` because anchor-lang 2.0.0-rc.1 is built against wincode 0.5 while solana-address 2.7 moved to 0.6. Eight projects have an enum reachable from their IDL and hit it. None of them consumes a generated IDL, so `--no-idl` costs nothing today: the program is still compiled and its tests still run. vault-strategy was failing for an unrelated and genuine reason, fixed here rather than skipped: it has `BorshAccount` fields whose type is declared in mock-swap-router, and `#[account]` only generates the IDL glue when the declaring crate has its own `idl-build` feature enabled. Its `idl-build` now forwards to `mock-swap-router/idl-build`. Verified locally with `anchor idl build`: the "has no IDL type information" error is gone. --- .github/workflows/anchor.yml | 41 ++++++++++++++++++- .../anchor/programs/vault-strategy/Cargo.toml | 7 +++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/.github/workflows/anchor.yml b/.github/workflows/anchor.yml index 0f4651241..d1e039bcd 100644 --- a/.github/workflows/anchor.yml +++ b/.github/workflows/anchor.yml @@ -261,8 +261,47 @@ jobs: done fi + # TEMPORARY WORKAROUND - delete this block and the `$idl_flag` + # below once an Anchor release after 2.0.0-rc.1 is out. + # + # anchor-derive-accounts 2.0.0-rc.1 emits enum type definitions with + # the JSON key "fields" where the IDL spec requires "variants", so + # `anchor build` cannot parse the IDL it just generated and dies + # with `Error: missing field variants`. Every project below has + # an enum reachable from its IDL and hits it. Reproduce with any + # program containing `#[derive(IdlType)] pub enum E { A, B }`. + # + # Fixed upstream, unreleased at time of writing: + # https://github.com/otter-sec/anchor/pull/4947 + # + # Patching just the derive crate to that fix is not an option: it + # requires solana-address 2.7, and these programs pin + # `>=2.6, <2.7` because anchor-lang 2.0.0-rc.1 is built against + # wincode 0.5 while solana-address 2.7 moved to 0.6. + # + # Skipping IDL generation costs nothing today: none of these + # projects consumes a generated IDL (no `idls/` directory, no + # `declare_program!`). The program is still compiled and its tests + # still run. + case "$project" in + ./basics/pyth/anchor \ + |./finance/betting-market/anchor \ + |./finance/order-book/anchor \ + |./finance/perpetual-futures/anchor \ + |./finance/prop-amm/anchor \ + |./tokens/token-extensions/default-account-state/anchor \ + |./tokens/token-extensions/metadata/anchor \ + |./tokens/token-extensions/transfer-hook/allow-block-list-token/anchor) + echo "::notice::skipping IDL generation for $project (anchor#4947)" + idl_flag="--no-idl" + ;; + *) + idl_flag="" + ;; + esac + # Run anchor build - if ! anchor build; then + if ! anchor build $idl_flag; then echo "::error::anchor build failed for $project" echo "$project: anchor build failed" >> $GITHUB_WORKSPACE/failed_projects.txt rm -rf target node_modules diff --git a/finance/vault-strategy/anchor/programs/vault-strategy/Cargo.toml b/finance/vault-strategy/anchor/programs/vault-strategy/Cargo.toml index 573c1df5c..d978a46cc 100644 --- a/finance/vault-strategy/anchor/programs/vault-strategy/Cargo.toml +++ b/finance/vault-strategy/anchor/programs/vault-strategy/Cargo.toml @@ -14,7 +14,12 @@ cpi = ["no-entrypoint"] no-entrypoint = [] no-idl = [] no-log-ix-name = [] -idl-build = ["anchor-lang/idl-build"] +# `mock-swap-router/idl-build` is required, not optional: this program has +# `BorshAccount` fields whose type is declared in that crate, and +# `#[account]` only generates the IDL glue when the declaring crate has its own +# `idl-build` feature on. Without the forward, `anchor idl build` fails with +# "`mock_swap_router::AssetRate` has no IDL type information". +idl-build = ["anchor-lang/idl-build", "mock-swap-router/idl-build"] anchor-debug = [] custom-heap = [] custom-panic = []