Skip to content

Fix: ASM test compilation when binaries are missing - #118

Merged
mikemaccana merged 2 commits into
mainfrom
fix/asm-test-missing-artifact
Aug 1, 2026
Merged

Fix: ASM test compilation when binaries are missing#118
mikemaccana merged 2 commits into
mainfrom
fix/asm-test-missing-artifact

Conversation

@mikemaccana

@mikemaccana mikemaccana commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Problem

Four ASM examples (transfer-sol, create-account, checking-accounts, hello-solana) failed to compile whenever the SBPF .so artifacts were absent:

error: couldn't read `basics/transfer-sol/asm/deploy/transfer-sol-cpi.so`: No such file or directory

The tests embed the assembled program with include_bytes!, which resolves at compile time. Those binaries are gitignored build artifacts produced by sbpf 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.rs per ASM crate checks for that crate's binary and sets a has_asm_binary cfg when it is present. Each test module is gated on #[cfg(all(test, has_asm_binary))]:

  • Binary present (after sbpf build): the tests compile and run exactly as before.
  • Binary absent: the test module is left out, the crate builds, and two cargo::warning lines point at sbpf build.

Each script also emits cargo::rerun-if-changed for its binary, so the cfg is re-evaluated as soon as the file appears rather than going stale.

Changes

  • build.rs added to 4 ASM crates, each naming the binary its own crate embeds
  • build = "build.rs" added to the 4 Cargo.toml files
  • test modules gated #[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 warnings promotes unexpected_cfgs to an error. Introducing a custom cfg is not enough; it has to be declared, or cargo clippy -- -D warnings fails on every crate that uses it. Each script emits cargo::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.so and hello-solana-asm-program.so respectively. An earlier revision of this branch probed deploy/program.so in three of them, which would have left the cfg unset after a real sbpf build and 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:

# CI's exact invocation
cargo clippy -- -D warnings -A clippy::diverging_sub_expression   # clean

# binary absent: crate builds, tests excluded
cargo test --lib --no-run                                          # clean

# binary present: tests come back
cargo test --lib -- --list                                         # tests::test_transfer_sol: test

claude added 2 commits July 31, 2026 14:17
…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
@mikemaccana
mikemaccana merged commit 59000a4 into main Aug 1, 2026
27 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