cli: Add checks for incorrect usage of `idl-build` feature (#3061)

This commit is contained in:
acheron 2024-06-28 19:01:28 +02:00 committed by GitHub
parent ca7fcee6b8
commit f7916d4159
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 4 deletions

View File

@ -13,7 +13,8 @@ The minor version will be incremented upon a breaking change and the patch versi
### Features
- ts: Add optional `commitment` parameter to `Program.addEventListener` ([#3052](https://github.com/coral-xyz/anchor/pull/3052)).
- cli: Pass "cargo args" to idl generation when building program or idl ([#3059](https://github.com/coral-xyz/anchor/pull/3059)).
- cli, idl: Pass `cargo` args to IDL generation when building program or IDL ([#3059](https://github.com/coral-xyz/anchor/pull/3059)).
- cli: Add checks for incorrect usage of `idl-build` feature ([#3061](https://github.com/coral-xyz/anchor/pull/3061)).
### Fixes

View File

@ -80,3 +80,25 @@ pub fn check_anchor_version(cfg: &WithPath<Config>) -> Result<()> {
Ok(())
}
/// Check whether the `idl-build` feature is being used correctly.
///
/// **Note:** The check expects the current directory to be a program directory.
pub fn check_idl_build_feature() -> Result<()> {
Manifest::from_path("Cargo.toml")?
.dependencies
.iter()
.filter(|(_, dep)| dep.req_features().contains(&"idl-build".into()))
.for_each(|(name, _)| {
eprintln!(
"WARNING: `idl-build` feature of crate `{name}` is enabled by default. \
This is not the intended usage.\n\n\t\
To solve, do not enable the `idl-build` feature and include crates that have \
`idl-build` feature in the `idl-build` feature list:\n\n\t\
[features]\n\t\
idl-build = [\"{name}/idl-build\", ...]\n"
)
});
Ok(())
}

View File

@ -11,7 +11,7 @@ use anchor_lang::{AccountDeserialize, AnchorDeserialize, AnchorSerialize};
use anchor_lang_idl::convert::convert_idl;
use anchor_lang_idl::types::{Idl, IdlArrayLen, IdlDefinedFields, IdlType, IdlTypeDefTy};
use anyhow::{anyhow, Context, Result};
use checks::{check_anchor_version, check_overflow};
use checks::{check_anchor_version, check_idl_build_feature, check_overflow};
use clap::Parser;
use dirs::home_dir;
use flate2::read::GzDecoder;
@ -1819,9 +1819,10 @@ fn _build_rust_cwd(
arch: &ProgramArch,
cargo_args: Vec<String>,
) -> Result<()> {
let subcommand = arch.build_subcommand();
check_idl_build_feature().ok();
let exit = std::process::Command::new("cargo")
.arg(subcommand)
.arg(arch.build_subcommand())
.args(cargo_args.clone())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
@ -1830,6 +1831,7 @@ fn _build_rust_cwd(
if !exit.status.success() {
std::process::exit(exit.status.code().unwrap_or(1));
}
// Generate IDL
if !no_idl {
let idl = generate_idl(cfg, skip_lint, no_docs, &cargo_args)?;