From 895f01865ad0fd88a3e0db72c85c6c81ccf69983 Mon Sep 17 00:00:00 2001 From: acheron <98934430+acheroncrypto@users.noreply.github.com> Date: Mon, 29 Jul 2024 22:55:06 +0200 Subject: [PATCH] cli: Warn if `anchor-spl/idl-build` is missing (#3133) --- CHANGELOG.md | 1 + cli/src/checks.rs | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ff69036e0..a9a82ea7d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ The minor version will be incremented upon a breaking change and the patch versi - client: Support non-8-byte discriminators ([#3125](https://github.com/coral-xyz/anchor/pull/3125)). - spl: Add `withdraw_withheld_tokens_from_accounts` instruction ([#3128]([https://github.com/coral-xyz/anchor/pull/3128)). - ts: Add optional `wallet` property to the `Provider` interface ([#3130](https://github.com/coral-xyz/anchor/pull/3130)). +- cli: Warn if `anchor-spl/idl-build` is missing ([#3133](https://github.com/coral-xyz/anchor/pull/3133)). ### Fixes diff --git a/cli/src/checks.rs b/cli/src/checks.rs index 82b5cf5ffd..20069c4455 100644 --- a/cli/src/checks.rs +++ b/cli/src/checks.rs @@ -85,7 +85,10 @@ pub fn check_anchor_version(cfg: &WithPath) -> Result<()> { /// /// **Note:** The check expects the current directory to be a program directory. pub fn check_idl_build_feature() -> Result<()> { - Manifest::from_path("Cargo.toml")? + let manifest = Manifest::from_path("Cargo.toml")?; + + // Check if `idl-build` is enabled by default + manifest .dependencies .iter() .filter(|(_, dep)| dep.req_features().contains(&"idl-build".into())) @@ -100,5 +103,22 @@ pub fn check_idl_build_feature() -> Result<()> { ) }); + // Check `anchor-spl`'s `idl-build` feature + manifest + .dependencies + .get("anchor-spl") + .and_then(|_| manifest.features.get("idl-build")) + .map(|feature_list| !feature_list.contains(&"anchor-spl/idl-build".into())) + .unwrap_or_default() + .then(|| { + eprintln!( + "WARNING: `idl-build` feature of `anchor-spl` is not enabled. \ + This is likely to result in cryptic compile errors.\n\n\t\ + To solve, add `anchor-spl/idl-build` to the `idl-build` feature list:\n\n\t\ + [features]\n\t\ + idl-build = [\"anchor-spl/idl-build\", ...]\n" + ) + }); + Ok(()) }