-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add crate details * Add readme * Update crate name * Add cli crate details * Typos
- Loading branch information
Showing
10 changed files
with
98 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
[package] | ||
name = "include-idl-cli" | ||
name = "solana-include-idl-cli" | ||
description = "CLI to parse IDL files from a program binary" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license-file = "Apache-2.0" | ||
|
||
[dependencies] | ||
clap = { version = "4.5.7", features = ["derive"] } | ||
goblin = { version = "0.8.2" } | ||
include-idl = { path = "../include-idl", features = ["parse"] } | ||
solana-include-idl = { version = "^0", features = ["parse"], path = "../include-idl" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# `solana-include-idl-cli` | ||
|
||
A simple CLI to read an IDL file stored on a Solana program binary. | ||
|
||
```console | ||
Usage: solana-include-idl-cli parse <PATH> | ||
|
||
Arguments: | ||
<PATH> Path to the program binary | ||
|
||
Options: | ||
-h, --help Print help | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# `solana-include-idl` | ||
|
||
A collection of macro and helpers to manage IDLs stored on the program binary. | ||
|
||
IDL files describe the structure and API of a Solana program, facilitating easier integration and interaction with various client applications. This crate automates the task of publishing the IDL file by storing it as a separate ELF section within the program binary. | ||
|
||
## Usage | ||
|
||
The crate provides a macro that includes the type and contents of the IDL file in separate ELF sections on the program binary. | ||
|
||
* `.idl.type` contains the type of the IDL file. | ||
* `.idl.data` contains the IDL file itself. | ||
|
||
The macro takes two arguments: | ||
|
||
* `type`: The type of the IDL file. This should be one of the variants of the `IdlType` enum (e.g., `IdlType::Anchor` or `IdlType::Codama`). | ||
* `file`: The path to the IDL file. | ||
|
||
```rust | ||
use include_idl::{include_idl, parse::IdlType}; | ||
|
||
include_idl!(IdlType::Codama, concat!(env!("OUT_DIR"), "/codama.idl.zip")); | ||
``` | ||
|
||
In general, the macro is used in combination with a `build.rs` build script to compress the IDL file, reducing the space required on the program binary. | ||
|
||
To specify a build script, add a `build = "build.rs"` entry to your `Cargo.toml` file under the `[package]` section. Below is a `build.rs` example file that compresses an existing IDL file. | ||
|
||
```rust | ||
use std::env; | ||
use std::path::PathBuf; | ||
use include_idl::compress_idl; | ||
|
||
fn main() { | ||
// Get the IDL path. | ||
let idl_path = PathBuf::from("../api").join("idl.json"); | ||
// Compress the IDL file to a zip file. | ||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
let dest_path = PathBuf::from(out_dir).join("codama.idl.zip"); | ||
|
||
compress_idl(&idl_path, &dest_path); | ||
} | ||
``` | ||
|
||
### Generating an IDL | ||
|
||
If you are using [Anchor](https://www.anchor-lang.com), this step is alredy done for your. If you are writing a native Solana program or using a framework that does not export and IDL, you can use [Codama](https://github.com/codama-idl/codama?tab=readme-ov-file#from-program-to-codama). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters