Describe the bug
When a cargo package has a hyphen in its name (e.g., nimbus-contracts) and does not explicitly set the [lib] target name in Cargo.toml using underscores, cargo stylus check / cargo stylus deploy fails with the error:
error: build did not generate wasm file
Root Cause
In stylus-tools/src/core/project/contract.rs (under Contract::try_from), the library target name is extracted by looking for TargetKind::Lib inside the package targets:
let name = package
.targets
.iter()
.find_map(|t| t.kind.contains(&TargetKind::Lib).then(|| t.name.clone()))
// If that doesn't work, then we can use the package name, and break normally.
.unwrap_or_else(|| package.name.to_string());
However:
- In a Stylus project, the crate type must be
cdylib (e.g., crate-type = ["cdylib", "rlib"]).
- In
cargo-metadata, the target kind of a cdylib target maps to TargetKind::CDylib, not TargetKind::Lib.
- Consequently,
t.kind.contains(&TargetKind::Lib) evaluates to false for cdylib targets.
- The code falls back to
package.name.to_string(), which preserves hyphens (e.g., nimbus-contracts).
cargo-stylus then checks for a WASM file named nimbus-contracts.wasm inside target/wasm32-unknown-unknown/release/deps/.
- But Cargo always replaces hyphens with underscores for library outputs, producing
nimbus_contracts.wasm.
- This causes a file-not-found mismatch, failing the build check.
Suggested Fix
Update the targets finder in stylus-tools/src/core/project/contract.rs to search for TargetKind::CDylib as well:
let name = package
.targets
.iter()
.find_map(|t| {
let is_lib = t.kind.contains(&TargetKind::Lib) || t.kind.contains(&TargetKind::CDylib);
is_lib.then(|| t.name.clone())
})
.unwrap_or_else(|| package.name.to_string());
Alternatively, normalize hyphens to underscores when looking up the compiled library file path.
Describe the bug
When a cargo package has a hyphen in its name (e.g.,
nimbus-contracts) and does not explicitly set the[lib]targetnameinCargo.tomlusing underscores,cargo stylus check/cargo stylus deployfails with the error:error: build did not generate wasm fileRoot Cause
In
stylus-tools/src/core/project/contract.rs(underContract::try_from), the library target name is extracted by looking forTargetKind::Libinside the package targets:However:
cdylib(e.g.,crate-type = ["cdylib", "rlib"]).cargo-metadata, the target kind of acdylibtarget maps toTargetKind::CDylib, notTargetKind::Lib.t.kind.contains(&TargetKind::Lib)evaluates tofalseforcdylibtargets.package.name.to_string(), which preserves hyphens (e.g.,nimbus-contracts).cargo-stylusthen checks for a WASM file namednimbus-contracts.wasminsidetarget/wasm32-unknown-unknown/release/deps/.nimbus_contracts.wasm.Suggested Fix
Update the targets finder in
stylus-tools/src/core/project/contract.rsto search forTargetKind::CDylibas well:Alternatively, normalize hyphens to underscores when looking up the compiled library file path.