From ddada99f525abc468df01339f9749bcd604a49bd Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 24 Oct 2024 07:27:05 +1000 Subject: [PATCH] Prevent use with rust 1.82+ (#1371) ### What Prevent use with rust 1.82+. And run CI builds with 1.81. ### Why https://github.com/stellar/rs-soroban-env/issues/1469 Discussion: https://stellarfoundation.slack.com/archives/C030Z9EHVQE/p1729217606684609 (cherry picked from commit 9e674f2e436b814350698d772d4570ce43be9f4f) --- Cargo.lock | 1 + rust-toolchain.toml | 2 +- soroban-sdk/Cargo.toml | 3 +++ soroban-sdk/build.rs | 8 ++++++++ soroban-sdk/src/lib.rs | 6 ------ 5 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 soroban-sdk/build.rs diff --git a/Cargo.lock b/Cargo.lock index cf6a12b06..8c4baec4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1218,6 +1218,7 @@ dependencies = [ "proptest", "proptest-arbitrary-interop", "rand", + "rustc_version", "serde", "serde_json", "soroban-env-guest", diff --git a/rust-toolchain.toml b/rust-toolchain.toml index e340b7641..90ff24e80 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "stable" +channel = "1.81" targets = ["wasm32-unknown-unknown"] components = ["rustc", "cargo", "rustfmt", "clippy", "rust-src"] diff --git a/soroban-sdk/Cargo.toml b/soroban-sdk/Cargo.toml index 2fbc0eb5f..5d7472bc6 100644 --- a/soroban-sdk/Cargo.toml +++ b/soroban-sdk/Cargo.toml @@ -15,6 +15,9 @@ exclude = ["test_snapshots/", "src/tests/"] [lib] doctest = false +[build-dependencies] +rustc_version = "0.4.1" + [dependencies] soroban-sdk-macros = { workspace = true } bytes-lit = "0.0.5" diff --git a/soroban-sdk/build.rs b/soroban-sdk/build.rs new file mode 100644 index 000000000..6bcb32fc6 --- /dev/null +++ b/soroban-sdk/build.rs @@ -0,0 +1,8 @@ +pub fn main() { + #[cfg(all(target_family = "wasm", target_os = "unknown"))] + if let Ok(version) = rustc_version::version() { + if version.major == 1 && version.minor >= 82 { + 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."); + } + } +} diff --git a/soroban-sdk/src/lib.rs b/soroban-sdk/src/lib.rs index bdca8668f..c032484ea 100644 --- a/soroban-sdk/src/lib.rs +++ b/soroban-sdk/src/lib.rs @@ -47,12 +47,6 @@ #[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]