Skip to content

feat(cli): add --artifacts-path flag to override .so program location#573

Merged
MicaiahReid merged 3 commits intosolana-foundation:mainfrom
procdump:artifacts_path
Mar 25, 2026
Merged

feat(cli): add --artifacts-path flag to override .so program location#573
MicaiahReid merged 3 commits intosolana-foundation:mainfrom
procdump:artifacts_path

Conversation

@procdump
Copy link
Contributor

@procdump procdump commented Mar 13, 2026

Summary

cargo-build-sbf --debug emits artifacts in target/deploy/debug on purpose to prevent accidental deployments on mainnet so in that sense:

  • Add --artifacts-path CLI flag to support loading debug-compiled .so programs (e.g. surfpool start --artifacts-path ./target/deploy/debug)
  • Thread artifacts_path through framework detection, .so existence checks, in-memory template generation, and the --watch file watcher

While working on this PR I've unearthed a calculation overflow bug in txtx-addon-network-svm (details in the PR): solana-foundation/txtx#399

Allow overriding the default `target/deploy` path for .so artifacts
with `--artifacts-path`. This enables loading debug-compiled programs
during local development (e.g. `surfpool start --artifacts-path
./target/deploy/debug`). The flag conflicts with `--network` to
prevent deploying debug builds to mainnet/devnet/testnet.

Threads artifacts_path through framework detection, .so existence
checks, in-memory template generation (bin_path injection), and the
file watcher.
Allow overriding the default target/deploy path for .so program
artifacts. Deployment always targets the local surfnet regardless
of --network or --rpc-url, so no conflicts are needed.
@MicaiahReid
Copy link
Collaborator

Hmm, I just ran cargo-build-sbf --tools-version v1.52--debug on a project and it didn't generate a /target/deploy/debug folder. Instead, it put a binary in deploy: deploy/my_program.debug. Are you sure this functionality is consistent across versions?

@procdump
Copy link
Contributor Author

procdump commented Mar 18, 2026

Hmm, I just ran cargo-build-sbf --tools-version v1.52--debug on a project and it didn't generate a /target/deploy/debug folder. Instead, it put a binary in deploy: deploy/my_program.debug. Are you sure this functionality is consistent across versions?

The change dates back to anza-xyz/agave#9263 . What you observe is most probably because you use cargo-build-sbf from stable. However with agave 4.x the path for debug builds is changed to target/deploy/debug and in that sense surfpool needs some instrumentation to specify the different directory hence the PR.

@procdump
Copy link
Contributor Author

@MicaiahReid - is it possible that you have a look on this one again?

@MicaiahReid MicaiahReid force-pushed the main branch 5 times, most recently from 5419677 to 2129ad9 Compare March 23, 2026 19:40
@MicaiahReid
Copy link
Collaborator

@MicaiahReid - is it possible that you have a look on this one again?

@procdump I was able to get this tested, it looks good to me! One question - it looks like the debug build also generates a new keypair / program id. Should this artifacts-path also be updating the keypair used for the deployment?

Something like

            let bin_path = format!("{}/{}.so", artifacts.trim_end_matches('/'), program_name);
            let keypair_path = format!("{}/{}-keypair.json", artifacts.trim_end_matches('/'), program_name);
            // Pass bin_path as the 4th argument (program_name, keypair_path, idl_path, bin_path)
            let old = format!("program = {}(\"{}\") ", get_program_fn, program_name);
            let new = format!(
                "program = {}(\"{}\", \"{}\", null, \"{}\") ",
                get_program_fn, program_name, keypair_path, bin_path
            );

When --artifacts-path is set, use the keypair from the same
directory as the .so instead of defaulting to target/deploy/.
cargo build-sbf outputs both files to the same location.
@procdump
Copy link
Contributor Author

@MicaiahReid - is it possible that you have a look on this one again?

@procdump I was able to get this tested, it looks good to me! One question - it looks like the debug build also generates a new keypair / program id. Should this artifacts-path also be updating the keypair used for the deployment?

Something like

            let bin_path = format!("{}/{}.so", artifacts.trim_end_matches('/'), program_name);
            let keypair_path = format!("{}/{}-keypair.json", artifacts.trim_end_matches('/'), program_name);
            // Pass bin_path as the 4th argument (program_name, keypair_path, idl_path, bin_path)
            let old = format!("program = {}(\"{}\") ", get_program_fn, program_name);
            let new = format!(
                "program = {}(\"{}\", \"{}\", null, \"{}\") ",
                get_program_fn, program_name, keypair_path, bin_path
            );

@MicaiahReid - Good point. I've fixed it as you suggest 7346dbc.

Copy link
Collaborator

@MicaiahReid MicaiahReid left a comment

Choose a reason for hiding this comment

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

Thanks @procdump!

@MicaiahReid MicaiahReid merged commit dd0274a into solana-foundation:main Mar 25, 2026
3 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.

2 participants