Fix: ASM test compilation when binaries are missing - #118
Merged
Conversation
…xistence Four ASM examples (transfer-sol, create-account, checking-accounts, hello-solana) had tests that failed to compile when the SBPF .so files were missing. These binaries are build artifacts (listed in .gitignore) that must be generated with `sbpf build` before tests can run. Solution: Add build.rs scripts that set a has_asm_binary cfg when the .so file exists, then gate the test modules with #[cfg(all(test, has_asm_binary))]. This allows the crate to compile cleanly and provides helpful build warnings when the binary is missing, without breaking CI. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BDUxWXgCA5TsoPPxHzRNen
Two defects in the previous commit: Clippy runs with -D warnings, which promotes unexpected_cfgs to an error, so introducing a custom cfg without declaring it broke the build. The build scripts now emit cargo::rustc-check-cfg for it. Three of the four build scripts probed deploy/program.so, but those crates embed create-account-asm-program.so, checking-account-asm-program.so and hello-solana-asm-program.so. After a real `sbpf build` the cfg would have stayed unset and the tests would have silently never run, which is worse than the failure this was fixing. Each script now names the file its own crate embeds, and re-runs when that file changes so the cfg cannot go stale. Verified both directions: with a binary present the test module compiles and `--list` reports the test; with it absent the crate builds clean. `cargo clippy -- -D warnings -A clippy::diverging_sub_expression` passes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BDUxWXgCA5TsoPPxHzRNen
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Four ASM examples (transfer-sol, create-account, checking-accounts, hello-solana) failed to compile whenever the SBPF
.soartifacts were absent:The tests embed the assembled program with
include_bytes!, which resolves at compile time. Those binaries are gitignored build artifacts produced bysbpf build, so a fresh clone has none and the crate cannot build at all — the failure is a compile error, not a skipped test.Solution
A
build.rsper ASM crate checks for that crate's binary and sets ahas_asm_binarycfg when it is present. Each test module is gated on#[cfg(all(test, has_asm_binary))]:sbpf build): the tests compile and run exactly as before.cargo::warninglines point atsbpf build.Each script also emits
cargo::rerun-if-changedfor its binary, so the cfg is re-evaluated as soon as the file appears rather than going stale.Changes
build.rsadded to 4 ASM crates, each naming the binary its own crate embedsbuild = "build.rs"added to the 4Cargo.tomlfiles#[cfg(test)]→#[cfg(all(test, has_asm_binary))]Notes for reviewers
Two things surfaced while getting CI green, both worth knowing since they are easy to reproduce:
-D warningspromotesunexpected_cfgsto an error. Introducing a custom cfg is not enough; it has to be declared, orcargo clippy -- -D warningsfails on every crate that uses it. Each script emitscargo::rustc-check-cfg=cfg(has_asm_binary).The binary names differ per crate. The four crates embed
transfer-sol-cpi.so,create-account-asm-program.so,checking-account-asm-program.soandhello-solana-asm-program.sorespectively. An earlier revision of this branch probeddeploy/program.soin three of them, which would have left the cfg unset after a realsbpf buildand silently switched those tests off — quieter than the bug being fixed, and worse. Each script now names the file its own crate embeds.Testing
Both directions verified locally, not just the one CI exercises: