[ci, program] Add js client build to ci and fix lint#130
Conversation
2b05626 to
1cc16ec
Compare
|
Can we get the codama macros in another PR? Feels independent to the javascript formatting. Also, we need a way to enforce that the idl is always up to date. One of these two? //! Codama IDL build script.
use {
codama::Codama,
codama_korok_marinade_unstake::KorokPluginMarinadeUnstake,
codama_korok_plugins::DefaultPlugin,
codama_korok_spl_discriminator::KorokPluginSplDiscriminate,
codama_korok_spl_pod::KorokPluginSplPod,
std::{env, fs, path::Path},
};
fn main() {
// Run the build script if the source files have changed, or if the
// developer provides the GENERATE_IDL environment variable.
//
// ```
// `GENERATE_IDL=1 cargo build`
// ```
//
// The environment variable approach is useful if the local Codama has been
// updated.
println!("cargo:rerun-if-changed=src/");
println!("cargo:rerun-if-env-changed=GENERATE_IDL");
if let Err(e) = generate_idl() {
panic!("cargo:warning=Failed to generate IDL: {}", e)
}
}
fn generate_idl() -> Result<(), Box<dyn std::error::Error>> {
let manifest_dir = env::var("CARGO_MANIFEST_DIR")?;
let crate_path = Path::new(&manifest_dir);
let codama = Codama::load(crate_path)?
.without_default_plugin()
.add_plugin(KorokPluginSplPod)
.add_plugin(DefaultPlugin)
.add_plugin(KorokPluginSplDiscriminate)
.add_plugin(KorokPluginMarinadeUnstake);
let idl_json = codama.get_json_idl()?;
// Parse and format the JSON with pretty printing.
let parsed: serde_json::Value = serde_json::from_str(&idl_json)?;
let mut formatted_json = serde_json::to_string_pretty(&parsed)?;
// Add newline at the end to match VS Code formatting.
formatted_json.push('\n');
let out_dir = Path::new(&manifest_dir).join("idl");
fs::create_dir_all(&out_dir)?;
let idl_path = out_dir.join("marinade_unstake.json");
fs::write(&idl_path, formatted_json)?;
println!("cargo:warning=IDL written to: {}", idl_path.display());
Ok(())
} |
1cc16ec to
f178cf2
Compare
|
Okay, got it. I'll just restrict to the CI update and the prettier (to satisfy the lint CI) in this PR. Then I'll add the codama macros in a follow-up PR. I think option B seems to be slightly easier, so I'll add option B in that PR. I rebased, so please take a look! |
|
For CI, we do have a Which can be added to CI easily, ie https://github.com/solana-program/feature-gate/blob/ab45beefb7c1dc0da8a3c80cd9d5add2576b1c95/.github/workflows/main.yml#L16 As for adding the macros, let's featurize all codama macro usage on a Edit: let's avoid build.rs files, they very rarely work as expected |
|
Oh I missed that I can featurize the |
Summary of Changes