3

Compared to the normal cargo build --release --workspace, rebuilding a program with cargo build-bpf (or sbf) ends up redoing quite a bit of work. If you have already built the workspace using cargo build, it caches that result and doesn't try to rebuild if nothing has changed. cargo build --release not recompiling anything on rebuild

Is there a reason cargo build-bpf doesn't have this same behavior? It appears to build each package in the workspace individually. Is there a reason for this? Is there a path forward that builds all the programs together like normal cargo builds instead of one at a time?

1 Answer 1

3

In normal cases, the build artifacts are cached, like with normal cargo.

For example, if you try to build the SPL token program at https://github.com/solana-labs/solana-program-library/tree/master/token/program twice, on the second round you'll see:

$ cargo build-sbf
    Finished release [optimized] target(s) in 0.24s

It could be that your program's transitive dependencies have different features enabled on the same crate, which forces multiple compilations of the same crate, which need to be recompiled on every subsequent build. This is a known "feature" of cargo, however.

Edit: sorry, I missed the "workspace" part of this. This is a bug with cargo build-sbf

2
  • Gotcha! Thank you! Is there an open issue on the bug and/or somewhere I can read up on it a bit more?
    – Sammy
    Commented Jan 24, 2023 at 21:35
  • Not currently... github.com/solana-labs/solana/issues/25765 mentions that it might be tripping up cargo's cache checks, but the resolution to the issue simply consolidates cargo features. It might be worth a new issue
    – Jon C
    Commented Jan 25, 2023 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.