Skip to content

Conversation

@samkim-crypto
Copy link
Contributor

@samkim-crypto samkim-crypto commented Nov 21, 2025

Summary of Changes

  • Updated CI to build and test the new js client.
  • Applied prettier on the js client to pass the lint ci check

@samkim-crypto samkim-crypto force-pushed the js-client-ci branch 2 times, most recently from 2b05626 to 1cc16ec Compare November 21, 2025 09:30
@grod220
Copy link
Member

grod220 commented Nov 21, 2025

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?
A. CI/CD that generates the IDL, generates clients, and does a git diff check
B. A build.rs file. Reference to what we did in unstake program:

//! 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(())
}

@samkim-crypto samkim-crypto changed the title [ci, program] Add js client build to ci and add codama macros [ci, program] Add js client build to ci and fix lint Nov 21, 2025
@samkim-crypto
Copy link
Contributor Author

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!

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@joncinque
Copy link
Contributor

joncinque commented Nov 21, 2025

For CI, we do have a generate-idl-% Makefile target in the feature-gate program: https://github.com/solana-program/feature-gate/blob/ab45beefb7c1dc0da8a3c80cd9d5add2576b1c95/Makefile#L100

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 codama feature, ie with #[cfg_attr(feature = "codama", ...)], so that the dep is only used for generating the IDL or other codama-related actions.

Edit: let's avoid build.rs files, they very rarely work as expected

@samkim-crypto
Copy link
Contributor Author

Oh I missed that I can featurize the cfg_attr. I can definitely do that for the codama dependency.

@samkim-crypto samkim-crypto merged commit b3f6278 into solana-program:main Nov 22, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants