Skip to content

Commit 26a3616

Browse files
Fix rust and wasm target check for sdk (#1771)
### What Replace `#[cfg(target_family = "wasm")]` with `CARGO_CFG_TARGET_FAMILY` and `CARGO_CFG_TARGET_OS` environment variable checks in `build.rs`. Update the error message to recommend `wasm32v1-none` as an alternative target available since Rust 1.84. ### Why `#[cfg(...)]` in `build.rs` evaluates against the build script's host target, not the compilation target. During cross-compilation from a non-wasm host, the condition is always false, so the Rust 1.82+ check never fires and contracts compile silently producing Wasm binaries with unsupported `reference-types` and `multi-value` features. This has created some confusiong in the community recently when folks were trying to build for wasm32-unknown-unknown. We should also now promote wasm32v1-none. That's the target most folks should be using. Close #1770 Co-authored-by: mootz12 <38118608+mootz12@users.noreply.github.com>
1 parent 7847eae commit 26a3616

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

soroban-sdk/build.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ pub fn main() {
55
// hash.
66
println!("cargo::rustc-check-cfg=cfg(soroban_sdk_internal_no_rssdkver_meta)");
77

8-
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
9-
if let Ok(version) = rustc_version::version() {
10-
if version.major == 1 && version.minor >= 82 {
11-
panic!("Rust compiler 1.82+ with target 'wasm32-unknown-unknown' is unsupported by the Soroban Environment, because the 'wasm32-unknown-unknown' target in Rust 1.82+ has features enabled that are not yet supported and not easily disabled: reference-types, multi-value. Use Rust 1.81 to build for the 'wasm32-unknown-unknown' target.");
8+
// Check if we're building for wasm32-unknown-unknown target (cross-compilation safe)
9+
if std::env::var("CARGO_CFG_TARGET_FAMILY").as_deref() == Ok("wasm")
10+
&& std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("unknown")
11+
{
12+
if let Ok(version) = rustc_version::version() {
13+
if version.major == 1 && version.minor >= 82 {
14+
panic!("Rust compiler 1.82+ with target 'wasm32-unknown-unknown' is unsupported by the Soroban Environment, use 'wasm32v1-none' available with Rust 1.84+. The 'wasm32-unknown-unknown' target in Rust 1.82+ has features enabled that are not yet supported and not easily disabled: reference-types, multi-value. If you must build for the 'wasm32-unknown-unknown' use Rust 1.81 or earlier.");
15+
}
1216
}
1317
}
1418

0 commit comments

Comments
 (0)