Skip to content

Commit

Permalink
Fix IDL (#2824)
Browse files Browse the repository at this point in the history
* Rewrite IDL type spec

* Rewrite IDL generation

* Partially rewrite the TS package with the new IDL, improved account resolution and types
  • Loading branch information
acheroncrypto authored Mar 10, 2024
1 parent 2302833 commit d9a9f19
Show file tree
Hide file tree
Showing 189 changed files with 7,567 additions and 6,374 deletions.
21 changes: 15 additions & 6 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ description: "Setup"
runs:
using: "composite"
steps:
- run: sudo apt-get update && sudo apt-get install -y pkg-config build-essential libudev-dev
shell: bash
- run: echo "ANCHOR_VERSION=$(cat ./VERSION)" >> $GITHUB_ENV
shell: bash
- run: git submodule update --init --recursive --depth 1
shell: bash
- run: sudo apt-get update && sudo apt-get install -y pkg-config build-essential libudev-dev
shell: bash
- run: echo "ANCHOR_VERSION=$(cat ./VERSION)" >> $GITHUB_ENV
shell: bash
- run: git submodule update --init --recursive --depth 1
shell: bash
# `nightly` toolchain is currently required for building the IDL.
#
# Pinning the toolchain to an older date in order to fix
# `error[E0635]: unknown feature stdsimd` error from `ahash`.
# See: https://github.com/tkaitchuck/aHash/issues/200
#
# TODO: Unpin `nightly` release after upgrading Solana to `1.18`.
- run: rustup toolchain install nightly-2024-01-30
shell: bash
5 changes: 3 additions & 2 deletions .github/workflows/reusable-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,9 @@ jobs:
path: tests/bench
- cmd: cd tests/idl && ./test.sh
path: tests/idl
- cmd: cd tests/solang && anchor test
path: tests/solang
# TODO: Enable when `solang` becomes compatible with the new IDL spec
# - cmd: cd tests/solang && anchor test
# path: tests/solang
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup/
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ The minor version will be incremented upon a breaking change and the patch versi
- cli: Check `@coral-xyz/anchor` package and CLI version compatibility ([#2813](https://github.com/coral-xyz/anchor/pull/2813)).
- cli: Accept package name as program name ([#2816](https://github.com/coral-xyz/anchor/pull/2816)).
- cli: Add ability to build and test only a specified program ([#2823](https://github.com/coral-xyz/anchor/pull/2823)).
- idl: Add new IDL spec ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- idl: Add support for `repr`s ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- idl: Add support for expression evaluation ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- idl: Add support for using external types when generating the IDL ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- idl, ts: Add unit and tuple struct support ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- idl, ts: Add generics support ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- ts: Add `accountsPartial` method to keep the old `accounts` method behavior ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).

### Fixes

Expand All @@ -46,6 +53,9 @@ The minor version will be incremented upon a breaking change and the patch versi
- cli: Fix `migrate` command not working without global `ts-node` installation ([#2767](https://github.com/coral-xyz/anchor/pull/2767)).
- client, lang, spl, syn: Enable all features for docs.rs build ([#2774](https://github.com/coral-xyz/anchor/pull/2774)).
- ts: Fix construction of field layouts for type aliased instruction arguments ([#2821](https://github.com/coral-xyz/anchor/pull/2821))
- idl: Fix IDL ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- idl, ts: Make casing consistent ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- ts: Fix not being able to use numbers in instruction, account, or event names in some cases due to case conversion ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).

### Breaking

Expand All @@ -58,6 +68,14 @@ The minor version will be incremented upon a breaking change and the patch versi
- ts: Remove `associated`, `account.associated` and `account.associatedAddress` methods ([#2749](https://github.com/coral-xyz/anchor/pull/2749)).
- cli: `idl upgrade` command closes the IDL buffer account ([#2760](https://github.com/coral-xyz/anchor/pull/2760)).
- cli: Remove `--jest` option from the `init` command ([#2805](https://github.com/coral-xyz/anchor/pull/2805)).
- cli: Require `idl-build` feature in program `Cargo.toml` ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- cli: Rename `seeds` feature to `resolution` and make it enabled by default ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- cli: Remove `idl parse` command ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- idl: Change IDL spec ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- syn: Remove `idl-parse` and `seeds` features ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- ts: Change `accounts` method to no longer accept resolvable accounts ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- ts: `Program` instances use camelCase for everything ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).
- ts: Remove discriminator functions ([#2824](https://github.com/coral-xyz/anchor/pull/2824)).

## [0.29.0] - 2023-10-16

Expand Down
14 changes: 13 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"avm",
"cli",
"client",
"idl",
"lang",
"lang/attribute/*",
"lang/derive/*",
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ dev = []

[dependencies]
anchor-client = { path = "../client", version = "0.29.0" }
anchor-idl = { path = "../idl", features = ["build"], version = "0.29.0" }
anchor-lang = { path = "../lang", version = "0.29.0" }
anchor-syn = { path = "../lang/syn", features = ["event-cpi", "idl-parse", "init-if-needed"], version = "0.29.0" }
anyhow = "1.0.32"
base64 = "0.21"
bincode = "1.3.3"
Expand Down
31 changes: 25 additions & 6 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::is_hidden;
use anchor_client::Cluster;
use anchor_syn::idl::types::Idl;
use anchor_idl::types::Idl;
use anyhow::{anyhow, bail, Context, Error, Result};
use clap::{Parser, ValueEnum};
use dirs::home_dir;
Expand Down Expand Up @@ -375,14 +375,33 @@ pub struct ToolchainConfig {
pub solana_version: Option<String>,
}

#[derive(Default, Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FeaturesConfig {
#[serde(default)]
pub seeds: bool,
/// Enable account resolution.
///
/// Not able to specify default bool value: https://github.com/serde-rs/serde/issues/368
#[serde(default = "FeaturesConfig::get_default_resolution")]
pub resolution: bool,
/// Disable safety comment checks
#[serde(default, rename = "skip-lint")]
pub skip_lint: bool,
}

impl FeaturesConfig {
fn get_default_resolution() -> bool {
true
}
}

impl Default for FeaturesConfig {
fn default() -> Self {
Self {
resolution: Self::get_default_resolution(),
skip_lint: false,
}
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RegistryConfig {
pub url: String,
Expand Down Expand Up @@ -619,8 +638,8 @@ impl FromStr for Config {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let cfg: _Config = toml::from_str(s)
.map_err(|e| anyhow::format_err!("Unable to deserialize config: {}", e.to_string()))?;
let cfg: _Config =
toml::from_str(s).map_err(|e| anyhow!("Unable to deserialize config: {e}"))?;
Ok(Config {
toolchain: cfg.toolchain.unwrap_or_default(),
features: cfg.features.unwrap_or_default(),
Expand Down
Loading

0 comments on commit d9a9f19

Please sign in to comment.