diff --git a/Cargo.lock b/Cargo.lock index ce20cbb80816..6f0c626612db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11844,6 +11844,7 @@ dependencies = [ name = "test-parachain-halt" version = "0.9.40" dependencies = [ + "rustversion", "substrate-wasm-builder", ] diff --git a/parachain/test-parachains/adder/src/lib.rs b/parachain/test-parachains/adder/src/lib.rs index 096c5eac969c..0674e565b86f 100644 --- a/parachain/test-parachains/adder/src/lib.rs +++ b/parachain/test-parachains/adder/src/lib.rs @@ -17,10 +17,6 @@ //! Basic parachain that adds a number as part of its state. #![no_std] -#![cfg_attr( - not(feature = "std"), - feature(core_intrinsics, lang_items, core_panic_info, alloc_error_handler) -)] use parity_scale_codec::{Decode, Encode}; use tiny_keccak::{Hasher as _, Keccak}; diff --git a/parachain/test-parachains/halt/Cargo.toml b/parachain/test-parachains/halt/Cargo.toml index 27180136d936..fe3ac9ce794e 100644 --- a/parachain/test-parachains/halt/Cargo.toml +++ b/parachain/test-parachains/halt/Cargo.toml @@ -10,6 +10,7 @@ edition.workspace = true [build-dependencies] substrate-wasm-builder = { git = "https://github.com/moondance-labs/substrate", branch = "tanssi-polkadot-v0.9.40" } +rustversion = "1.0.6" [features] default = [ "std" ] diff --git a/parachain/test-parachains/halt/build.rs b/parachain/test-parachains/halt/build.rs index 1725943d37ad..373ef6ac6805 100644 --- a/parachain/test-parachains/halt/build.rs +++ b/parachain/test-parachains/halt/build.rs @@ -17,5 +17,17 @@ use substrate_wasm_builder::WasmBuilder; fn main() { - WasmBuilder::new().with_current_project().export_heap_base().build() + WasmBuilder::new().with_current_project().export_heap_base().build(); + + enable_alloc_error_handler(); +} + +#[rustversion::before(1.68)] +fn enable_alloc_error_handler() { + if !cfg!(feature = "std") { + println!("cargo:rustc-cfg=enable_alloc_error_handler"); + } } + +#[rustversion::since(1.68)] +fn enable_alloc_error_handler() {} diff --git a/parachain/test-parachains/halt/src/lib.rs b/parachain/test-parachains/halt/src/lib.rs index 3c1416f3c6e9..c6820b493e81 100644 --- a/parachain/test-parachains/halt/src/lib.rs +++ b/parachain/test-parachains/halt/src/lib.rs @@ -17,10 +17,7 @@ //! Basic parachain that executes forever. #![no_std] -#![cfg_attr( - not(feature = "std"), - feature(core_intrinsics, lang_items, core_panic_info, alloc_error_handler) -)] +#![cfg_attr(enable_alloc_error_handler, feature(alloc_error_handler))] // Make the WASM binary available. #[cfg(feature = "std")] @@ -39,10 +36,10 @@ pub fn wasm_binary_unwrap() -> &'static [u8] { #[panic_handler] #[no_mangle] pub fn panic(_info: &core::panic::PanicInfo) -> ! { - core::intrinsics::abort() + core::arch::wasm32::unreachable(); } -#[cfg(not(feature = "std"))] +#[cfg(enable_alloc_error_handler)] #[alloc_error_handler] #[no_mangle] pub fn oom(_: core::alloc::Layout) -> ! { diff --git a/parachain/test-parachains/undying/src/lib.rs b/parachain/test-parachains/undying/src/lib.rs index 2ca878593f74..021843292cea 100644 --- a/parachain/test-parachains/undying/src/lib.rs +++ b/parachain/test-parachains/undying/src/lib.rs @@ -17,10 +17,6 @@ //! Basic parachain that adds a number as part of its state. #![no_std] -#![cfg_attr( - not(feature = "std"), - feature(core_intrinsics, lang_items, core_panic_info, alloc_error_handler) -)] use parity_scale_codec::{Decode, Encode}; use sp_std::vec::Vec;