Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- spl: Add pausable mint extension support ([#4092](https://github.com/solana-foundation/anchor/pull/4092)).
- cli: Resolve the target directory via `cargo metadata` to support target directory overrides ([#3817](https://github.com/solana-foundation/anchor/pull/3817)).
- spl: Added `token_metadata_remove_key` to support removing keys from token metadata extension ([#3717](https://github.com/solana-foundation/anchor/pull/3717)).
- cli: Allow configuring IDL JSON location in workspace config ([#4483](https://github.com/solana-foundation/anchor/pull/4483)).
- lang: Derive `Clone`, `Debug`, `Copy`, and `Default` on generated client / CPI account structs and instruction args where the field types allow it ([#4085](https://github.com/solana-foundation/anchor/pull/4085)).
- lang: Add `AccountLoader::new_unchecked` for constructing an `AccountLoader` without performing owner or discriminator checks ([#4162](https://github.com/solana-foundation/anchor/pull/4162)).

Expand Down
2 changes: 2 additions & 0 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ pub struct WorkspaceConfig {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub exclude: Vec<String>,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub idls: String,
#[serde(default, skip_serializing_if = "String::is_empty")]
pub types: String,
}

Expand Down
31 changes: 30 additions & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,9 @@ pub fn build(
};
fs::create_dir_all(idl_ts_out.as_ref().unwrap())?;

if !cfg.workspace.idls.is_empty() {
fs::create_dir_all(cfg_parent.join(&cfg.workspace.idls))?;
};
if !cfg.workspace.types.is_empty() {
fs::create_dir_all(cfg_parent.join(&cfg.workspace.types))?;
};
Expand Down Expand Up @@ -2450,6 +2453,9 @@ fn build_cwd_verifiable(
fs::create_dir_all(target_dir.join("verifiable"))?;
fs::create_dir_all(target_dir.join("idl"))?;
fs::create_dir_all(target_dir.join("types"))?;
if !&cfg.workspace.idls.is_empty() {
fs::create_dir_all(workspace_dir.join(&cfg.workspace.idls))?;
}
if !&cfg.workspace.types.is_empty() {
fs::create_dir_all(workspace_dir.join(&cfg.workspace.types))?;
}
Expand Down Expand Up @@ -2485,6 +2491,18 @@ fn build_cwd_verifiable(
.with_extension("json");
write_idl(&idl, OutFile::File(out_file.clone()))?;

if !&cfg.workspace.idls.is_empty() {
write_idl(
&idl,
OutFile::File(
workspace_dir
.join(&cfg.workspace.idls)
.join(&idl.metadata.name)
.with_extension("json"),
),
)?;
}

// Write out the TypeScript type.
println!("Writing the .ts file");
let ts_file = target_dir
Expand Down Expand Up @@ -2772,6 +2790,7 @@ fn _build_rust_cwd(
// Generate IDL
if !no_idl {
let idl = generate_idl(cfg, skip_lint, no_docs, &cargo_args)?;
let cfg_parent = cfg.path().parent().expect("Invalid Anchor.toml");

// JSON out path.
let out = match idl_out {
Expand All @@ -2790,11 +2809,21 @@ fn _build_rust_cwd(

// Write out the JSON file.
write_idl(&idl, OutFile::File(out.clone()))?;
if !&cfg.workspace.idls.is_empty() {
write_idl(
&idl,
OutFile::File(
cfg_parent
.join(&cfg.workspace.idls)
.join(&idl.metadata.name)
.with_extension("json"),
),
)?;
}
// Write out the TypeScript type.
fs::write(&ts_out, idl_ts(&idl)?)?;

// Copy out the TypeScript type.
let cfg_parent = cfg.path().parent().expect("Invalid Anchor.toml");
if !&cfg.workspace.types.is_empty() {
fs::copy(
&ts_out,
Expand Down
20 changes: 17 additions & 3 deletions docs/content/docs/references/anchor-toml.mdx

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will be deployed immediately after the merge, which could cause issues when people try to use this feature before the next version is out. This has been a common problem. I see someone already working on v2 docs (#4460), so thoughts on versioning the docs going forward?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, we should probably figure this out before touching the docs too much

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That PR seems to update how the TS package docs work, but the issue was about the main docs site. I believe TS package docs never automatically updated on every merge anyway.

Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,32 @@

## workspace

### idls

Adds a directory where you want the `<program_name>.json` file to be copied when running
`anchor build`. This is helpful when you want the generated IDL JSON outside the
workspace `target` directory, such as for versioning or consumption by another
tool.

Example:

```toml
[workspace]
idls = "app/src/idls/"
```

### types

Adds a directory where you want the `<idl>.ts` file to be copied when running
`anchor build`. This is helpful when you want to keep this file in version
Adds a directory where you want the `<program_name>.ts` file to be copied when running
`anchor build`. This is helpful when you want to keep IDL type definitions in version
control, like when using it on the frontend, which will probably not have access
to the `target` directory generated by anchor.

Example:

```toml
[workspace]
types = "app/src/idl/"
types = "app/src/idls/"
```

### members
Expand Down Expand Up @@ -101,8 +115,8 @@

## clients

Configures Codama client generation. When `auto = true`, `anchor build`

Check warning on line 118 in docs/content/docs/references/anchor-toml.mdx

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (Codama)
converts emitted Anchor IDLs into Codama IDLs and invokes the selected language

Check warning on line 119 in docs/content/docs/references/anchor-toml.mdx

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (Codama)
renderers after the build completes.

Each language can be enabled with a boolean or a table. If `path` is omitted,
Expand Down Expand Up @@ -249,7 +263,7 @@
Configuration for the [Surfpool](https://github.com/solana-foundation/surfpool) validator,
which is the default local validator used by `anchor test`. Surfpool provides a
lightweight Solana simulator with features like automatic account cloning and
runbook execution. All fields are optional and have sensible defaults.

Check warning on line 266 in docs/content/docs/references/anchor-toml.mdx

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (runbook)

Example:

Expand All @@ -264,7 +278,7 @@
datasource_rpc_url = "https://api.mainnet.solana.com" # RPC URL to use as the data source when online mode is enabled.
airdrop_addresses = ["addr1...", "addr2..."] # Addresses to airdrop SOL to at startup.
manifest_file_path = "./Cargo.toml" # Path to the Cargo.toml manifest file.
runbooks = ["./runbooks/setup.json"] # Paths to runbook files to execute on startup.

Check warning on line 281 in docs/content/docs/references/anchor-toml.mdx

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (runbook)

Check warning on line 281 in docs/content/docs/references/anchor-toml.mdx

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (runbooks)

Check warning on line 281 in docs/content/docs/references/anchor-toml.mdx

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (runbooks)
slot_time = 400 # Simulated slot time in milliseconds.
log_level = "info" # Log level for Surfpool. Default: "none".
block_production_mode = "clock" # Block production mode. Default: "transaction".
Expand All @@ -273,7 +287,7 @@
### startup_wait

Time in milliseconds to wait for Surfpool to start up. This is useful when
loading many accounts or running runbooks at startup. Default: `5000`.

Check warning on line 290 in docs/content/docs/references/anchor-toml.mdx

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (runbooks)

### shutdown_wait

Expand Down Expand Up @@ -332,9 +346,9 @@
Path to the `Cargo.toml` manifest file for the workspace. Typically not needed
since Anchor resolves this automatically.

### runbooks

Check warning on line 349 in docs/content/docs/references/anchor-toml.mdx

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (runbooks)

A list of file paths to runbooks that Surfpool will execute on startup. Runbooks

Check warning on line 351 in docs/content/docs/references/anchor-toml.mdx

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (Runbooks)

Check warning on line 351 in docs/content/docs/references/anchor-toml.mdx

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (runbooks)
allow you to set up initial state (deploy programs, create accounts, etc.)
before tests run.

Expand Down
2 changes: 2 additions & 0 deletions tests/idl/.gitignore
Comment thread
jamie-osec marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
workspace-idls
workspace-types
4 changes: 4 additions & 0 deletions tests/idl/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ numbers_123 = { address = "Numbers111111111111111111111111111111111111", idl = "
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[workspace]
idls = "workspace-idls"
types = "workspace-types"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
12 changes: 12 additions & 0 deletions tests/idl/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ popd
# Run anchor test
anchor test --skip-lint

# Verify workspace.idl copies the generated JSON files out of `target/idl`.
for idl in target/idl/*.json; do
filename=$(basename "$idl")
diff -u "$idl" "workspace-idls/$filename"
done

# Verify workspace.types copies the generated TypeScript files out of `target/types`.
for types in target/types/*.ts; do
filename=$(basename "$types")
diff -u "$types" "workspace-types/$filename"
done

# Generate IDLs
./generate.sh $tmp_dir

Expand Down
Loading