Skip to content

build.rs: skip wasm32-wasip2 test fixture build for non-test builds #543

@chenrui333

Description

@chenrui333

Problem

crates/icp-sync-plugin/build.rs unconditionally calls build_test_fixture(), which runs cargo build --target wasm32-wasip2 to compile a test fixture. This fails when the wasm32-wasip2 target is not installed:

error[E0463]: can't find crate for `core`
  = note: the `wasm32-wasip2` target may not be installed

thread 'main' panicked at crates/icp-sync-plugin/build.rs:33:5:
cargo build --target wasm32-wasip2 failed for test fixture

The TEST_PLUGIN_WASM env var set by this build step is only used in #[test] functions in runtime.rs, so the fixture is not needed for regular cargo build or cargo install.

Suggested fix

Gate build_test_fixture() behind a check so it only runs during test builds, e.g.:

fn main() {
    println!("cargo:rerun-if-changed=sync-plugin.wit");
    println!("cargo:rerun-if-changed=tests/fixtures/test-plugin/src/lib.rs");
    println!("cargo:rerun-if-changed=tests/fixtures/test-plugin/Cargo.toml");

    // Only build the wasm test fixture when running tests
    if std::env::var("CARGO_CFG_TEST").is_ok() {
        build_test_fixture();
    }
}

Context

This came up while packaging icp-cli 0.2.6 for Homebrew (Homebrew/homebrew-core#280458). The Homebrew Rust toolchain does not include the wasm32-wasip2 target. We are currently working around this with an inreplace in the formula.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions