idl: Remove `anchor-syn` dependency (#3030)
This commit is contained in:
parent
1c2aabe315
commit
d4318cc7cf
|
@ -27,6 +27,7 @@ The minor version will be incremented upon a breaking change and the patch versi
|
||||||
- cli: Add `idl type` command ([#3017](https://github.com/coral-xyz/anchor/pull/3017)).
|
- cli: Add `idl type` command ([#3017](https://github.com/coral-xyz/anchor/pull/3017)).
|
||||||
- lang: Add `anchor_lang::pubkey` macro for declaring `Pubkey` const values ([#3021](https://github.com/coral-xyz/anchor/pull/3021)).
|
- lang: Add `anchor_lang::pubkey` macro for declaring `Pubkey` const values ([#3021](https://github.com/coral-xyz/anchor/pull/3021)).
|
||||||
- cli: Sync program ids on the initial build ([#3023](https://github.com/coral-xyz/anchor/pull/3023)).
|
- cli: Sync program ids on the initial build ([#3023](https://github.com/coral-xyz/anchor/pull/3023)).
|
||||||
|
- idl: Remove `anchor-syn` dependency ([#3030](https://github.com/coral-xyz/anchor/pull/3030)).
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
|
||||||
|
|
|
@ -291,7 +291,6 @@ dependencies = [
|
||||||
name = "anchor-lang-idl"
|
name = "anchor-lang-idl"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anchor-syn",
|
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"heck 0.3.3",
|
"heck 0.3.3",
|
||||||
"regex",
|
"regex",
|
||||||
|
|
|
@ -12,7 +12,7 @@ all-features = true
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
build = ["anchor-syn", "regex"]
|
build = ["regex"]
|
||||||
convert = ["heck", "sha2"]
|
convert = ["heck", "sha2"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -21,7 +21,6 @@ serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
|
||||||
# `build` feature only
|
# `build` feature only
|
||||||
anchor-syn = { path = "../lang/syn", version = "0.30.0", optional = true }
|
|
||||||
regex = { version = "1", optional = true }
|
regex = { version = "1", optional = true }
|
||||||
|
|
||||||
# `convert` feature only
|
# `convert` feature only
|
||||||
|
|
|
@ -5,7 +5,6 @@ use std::{
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anchor_syn::parser::context::CrateContext;
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -51,15 +50,7 @@ pub fn build_idl(
|
||||||
skip_lint: bool,
|
skip_lint: bool,
|
||||||
no_docs: bool,
|
no_docs: bool,
|
||||||
) -> Result<Idl> {
|
) -> Result<Idl> {
|
||||||
// Check safety comments
|
let idl = build(program_path.as_ref(), resolution, skip_lint, no_docs)?;
|
||||||
let program_path = program_path.as_ref();
|
|
||||||
let lib_path = program_path.join("src").join("lib.rs");
|
|
||||||
let ctx = CrateContext::parse(lib_path)?;
|
|
||||||
if !skip_lint {
|
|
||||||
ctx.safety_checks()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let idl = build(program_path, resolution, no_docs)?;
|
|
||||||
let idl = convert_module_paths(idl);
|
let idl = convert_module_paths(idl);
|
||||||
let idl = sort(idl);
|
let idl = sort(idl);
|
||||||
verify(&idl)?;
|
verify(&idl)?;
|
||||||
|
@ -68,7 +59,7 @@ pub fn build_idl(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build IDL.
|
/// Build IDL.
|
||||||
fn build(program_path: &Path, resolution: bool, no_docs: bool) -> Result<Idl> {
|
fn build(program_path: &Path, resolution: bool, skip_lint: bool, no_docs: bool) -> Result<Idl> {
|
||||||
// `nightly` toolchain is currently required for building the IDL.
|
// `nightly` toolchain is currently required for building the IDL.
|
||||||
let toolchain = std::env::var("RUSTUP_TOOLCHAIN")
|
let toolchain = std::env::var("RUSTUP_TOOLCHAIN")
|
||||||
.map(|toolchain| format!("+{}", toolchain))
|
.map(|toolchain| format!("+{}", toolchain))
|
||||||
|
@ -95,6 +86,10 @@ fn build(program_path: &Path, resolution: bool, no_docs: bool) -> Result<Idl> {
|
||||||
"ANCHOR_IDL_BUILD_RESOLUTION",
|
"ANCHOR_IDL_BUILD_RESOLUTION",
|
||||||
if resolution { "TRUE" } else { "FALSE" },
|
if resolution { "TRUE" } else { "FALSE" },
|
||||||
)
|
)
|
||||||
|
.env(
|
||||||
|
"ANCHOR_IDL_BUILD_SKIP_LINT",
|
||||||
|
if skip_lint { "TRUE" } else { "FALSE" },
|
||||||
|
)
|
||||||
.env("ANCHOR_IDL_BUILD_PROGRAM_PATH", program_path)
|
.env("ANCHOR_IDL_BUILD_PROGRAM_PATH", program_path)
|
||||||
.env("RUSTFLAGS", "--cfg procmacro2_semver_exempt")
|
.env("RUSTFLAGS", "--cfg procmacro2_semver_exempt")
|
||||||
.current_dir(program_path)
|
.current_dir(program_path)
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use anyhow::Result;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use anyhow::{anyhow, Result};
|
||||||
use heck::CamelCase;
|
use heck::CamelCase;
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
|
@ -7,10 +9,15 @@ use super::{
|
||||||
common::{gen_print_section, get_idl_module_path, get_no_docs},
|
common::{gen_print_section, get_idl_module_path, get_no_docs},
|
||||||
defined::gen_idl_type,
|
defined::gen_idl_type,
|
||||||
};
|
};
|
||||||
use crate::{parser::docs, Program};
|
use crate::{
|
||||||
|
parser::{context::CrateContext, docs},
|
||||||
|
Program,
|
||||||
|
};
|
||||||
|
|
||||||
/// Generate the IDL build print function for the program module.
|
/// Generate the IDL build print function for the program module.
|
||||||
pub fn gen_idl_print_fn_program(program: &Program) -> TokenStream {
|
pub fn gen_idl_print_fn_program(program: &Program) -> TokenStream {
|
||||||
|
check_safety_comments().unwrap_or_else(|e| panic!("Safety checks failed: {e}"));
|
||||||
|
|
||||||
let idl = get_idl_module_path();
|
let idl = get_idl_module_path();
|
||||||
let no_docs = get_no_docs();
|
let no_docs = get_no_docs();
|
||||||
|
|
||||||
|
@ -139,3 +146,21 @@ pub fn gen_idl_print_fn_program(program: &Program) -> TokenStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check safety comments.
|
||||||
|
fn check_safety_comments() -> Result<()> {
|
||||||
|
let skip_lint = option_env!("ANCHOR_IDL_BUILD_SKIP_LINT")
|
||||||
|
.map(|val| val == "TRUE")
|
||||||
|
.unwrap_or_default();
|
||||||
|
if skip_lint {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::env::var("ANCHOR_IDL_BUILD_PROGRAM_PATH")
|
||||||
|
.map(PathBuf::from)
|
||||||
|
.map(|path| path.join("src").join("lib.rs"))
|
||||||
|
.map_err(|_| anyhow!("Failed to get program path"))
|
||||||
|
.map(CrateContext::parse)?
|
||||||
|
.map_err(|e| anyhow!("Failed to parse crate: {e}"))?
|
||||||
|
.safety_checks()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue