From 6c45fb952d61e5e7f519b3d729c91c667639eda1 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:48:13 +1000 Subject: [PATCH] Add compile errors when built with unsupported wasm features (#1353) ### What Add compile errors when built with unsupported wasm features reference-types and multivalue. ### Why Rust 1.82 is likely to ship with target feature reference-types and multivalue enabled on wasm builds. These target features are not supported by the Soroban Env in the current protocol 21 or next planned protocol 22. It's not trivial for developers to disable target features because of how the rustc compiler only exposes the ability to buildstd with nightly. These compile errors will prevent someone from building .wasm files with the sdk when either of those target features are enabled. A Rust version check is not being done because it's actually easier to do a target feature check, and in the off chain somehow Rust 1.82 shipped without the target features enabled then the sdk could still be used with 1.82. Links: - https://discord.com/channels/897514728459468821/1289090985569026048 - https://github.com/stellar/rs-soroban-env/issues/1469 - https://github.com/WebAssembly/tool-conventions/issues/233 ### Releasing This change will be merged to `main` targeting v22, then should be backported to a v21 patch release immediately following. --- soroban-sdk/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/soroban-sdk/src/lib.rs b/soroban-sdk/src/lib.rs index 95207d7a9..0a3d43874 100644 --- a/soroban-sdk/src/lib.rs +++ b/soroban-sdk/src/lib.rs @@ -47,6 +47,12 @@ #[cfg(all(target_family = "wasm", feature = "testutils"))] compile_error!("'testutils' feature is not supported on 'wasm' target"); +#[cfg(all(target_family = "wasm", target_feature = "reference-types"))] +compile_error!("Compiler configuration is unsupported by Soroban Environment, because a Wasm target-feature is enabled that is not yet supported: reference-types. Use Rust 1.81 or older to get a compatible default configuration."); + +#[cfg(all(target_family = "wasm", target_feature = "multivalue"))] +compile_error!("Compiler configuration is unsupported by Soroban Environment, because a Wasm target-feature is enabled that is not yet supported: multivalue. Use Rust 1.81 or older to get a compatible default configuration."); + // When used in a no_std contract, provide a panic handler as one is required. #[cfg(all(not(feature = "alloc"), target_family = "wasm"))] #[panic_handler]