Skip to content

Commit 97ab125

Browse files
Switch to post-rust-1.84 wasm target wasm32v1-none (#1453)
Part of wrapping up bug #1428. Mostly this is just: - Switching rust version to 1.84 which supports `wasm32v1-none` - Switching the SDK to build with that, not `wasm32-unknown-unknown` But there are a couple minor subtle bits: - Some of the crates only build native, not wasm, and we weren't differentiating that in the Makefile right - There _used_ to be a workaround for a mis-feature of `alloc` that required `std` in order to register an OOM handler; this was actually fixed in March 2023 (https://releases.rs/docs/1.68.0/ which contained rust-lang/rust#102318) but the workaround was already committed to the SDK by January 2023. Anyway, it's long since fixed and we can just delete the workaround, which we _have_ to in this PR, because `wasm32v1-none` doesn't ship with `std` at all. Probably don't merge this until I have the other CI bits all switched over to `wasm32v1-none` as described in #1428 --------- Co-authored-by: Leigh McCulloch <[email protected]>
1 parent e6fbd3a commit 97ab125

File tree

13 files changed

+30
-58
lines changed

13 files changed

+30
-58
lines changed

.github/workflows/rust.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ jobs:
5757
steps:
5858
- uses: actions/checkout@v3
5959
- run: rustup update
60-
- uses: stellar/binaries@v30
60+
- uses: stellar/binaries@v37
6161
with:
6262
name: cargo-semver-checks
63-
version: 0.35.0
63+
version: 0.40.0
6464
- run: cargo semver-checks
6565

6666
build-and-test:
@@ -103,19 +103,19 @@ jobs:
103103
- run: rustup update
104104
- run: cargo version
105105
- run: rustup target add ${{ matrix.sys.target }}
106-
- run: rustup target add wasm32-unknown-unknown
107-
- uses: stellar/binaries@v18
106+
- run: rustup target add wasm32v1-none
107+
- uses: stellar/binaries@v37
108108
with:
109109
name: cargo-hack
110110
version: 0.5.28
111111
- if: startsWith(matrix.sys.target, 'x86_64')
112112
name: Clear test snapshots for checking no diffs exists after test run
113113
run: rm -fr **/test_snapshots
114114
- name: Build for wasm
115-
run: cargo-hack hack build --target wasm32-unknown-unknown --profile release
115+
run: cargo-hack hack build --target wasm32v1-none --profile release --workspace --exclude soroban-spec --exclude soroban-spec-rust --exclude soroban-ledger-snapshot
116116
- name: Wasm Size
117117
run: |
118-
cd target/wasm32-unknown-unknown/release/ && \
118+
cd target/wasm32v1-none/release/ && \
119119
for i in *.wasm ; do \
120120
ls -l "$i"; \
121121
done
@@ -138,10 +138,10 @@ jobs:
138138
- uses: actions/checkout@v3
139139
- uses: stellar/actions/rust-cache@main
140140
- run: rustup install nightly
141-
- uses: stellar/binaries@v15
141+
- uses: stellar/binaries@v37
142142
with:
143143
name: cargo-fuzz
144-
version: 0.11.2
144+
version: 0.12.0
145145
- run: make build-fuzz
146146
- name: Check no diffs exist
147147
run: git add -N . && git diff HEAD --exit-code
@@ -182,7 +182,7 @@ jobs:
182182
matrix:
183183
sys:
184184
- os: ubuntu-latest
185-
target: wasm32-unknown-unknown
185+
target: wasm32v1-none
186186
cargo-hack-feature-options: ''
187187
- os: ubuntu-latest
188188
target: x86_64-unknown-linux-gnu

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
1313
Install rust stable:
1414
```
1515
rustup install stable
16-
rustup +stable target add wasm32-unknown-unknown
16+
rustup +stable target add wasm32v1-none
1717
rustup +stable component add rust-src
1818
```
1919

2020
Install rust nightly:
2121
```
2222
rustup install nightly
23-
rustup +nightly target add wasm32-unknown-unknown
23+
rustup +nightly target add wasm32v1-none
2424
rustup +nightly component add rust-src
2525
```
2626

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ members = [
1313

1414
[workspace.package]
1515
version = "22.0.7"
16-
rust-version = "1.79.0"
16+
rust-version = "1.84.0"
1717

1818
[workspace.dependencies]
1919
soroban-sdk = { version = "22.0.7", path = "soroban-sdk" }

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ all: check test
33
export RUSTFLAGS=-Dwarnings
44

55
CARGO_DOC_ARGS?=--open
6+
NATIVE_ONLY_CRATES:=soroban-spec soroban-spec-rust soroban-ledger-snapshot
7+
NATIVE_PACKAGE_ARGS:=$(foreach i,$(NATIVE_ONLY_CRATES), --package $(i))
8+
WASM_EXCLUDE_ARGS:=$(foreach i,$(NATIVE_ONLY_CRATES), --exclude $(i))
69

710
doc: fmt
811
cargo test --doc -p soroban-sdk -p soroban-sdk-macros --features testutils,hazmat
@@ -12,15 +15,16 @@ test: fmt build
1215
cargo hack --feature-powerset --ignore-unknown-features --features testutils --exclude-features docs test
1316

1417
build: fmt
15-
cargo hack build --target wasm32-unknown-unknown --release
16-
cd target/wasm32-unknown-unknown/release/ && \
18+
cargo hack build --release $(NATIVE_PACKAGE_ARGS)
19+
cargo hack build --target wasm32v1-none --release --workspace $(WASM_EXCLUDE_ARGS)
20+
cd target/wasm32v1-none/release/ && \
1721
for i in *.wasm ; do \
1822
ls -l "$$i"; \
1923
done
2024

2125
check: build fmt
2226
cargo hack --feature-powerset --exclude-features docs check
23-
cargo hack check --release --target wasm32-unknown-unknown
27+
cargo hack check --release --target wasm32v1-none --workspace $(WASM_EXCLUDE_ARGS)
2428

2529
build-fuzz:
2630
cd tests/fuzz/fuzz && cargo +nightly fuzz check

deny.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# list here is effectively saying which targets you are building for.
2222
targets = [
2323
{ triple = "x86_64-unknown-linux-gnu" },
24-
{ triple = "wasm32-unknown-unknown" }
24+
{ triple = "wasm32v1-none" }
2525
# The triple can be any string, but only the target triples built in to
2626
# rustc (as of 1.40) can be checked against actual config expressions
2727
#{ triple = "x86_64-unknown-linux-musl" },

rust-toolchain.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "1.81"
3-
targets = ["wasm32-unknown-unknown"]
2+
channel = "stable"
3+
targets = ["wasm32v1-none"]
44
components = ["rustc", "cargo", "rustfmt", "clippy", "rust-src"]

soroban-sdk/src/alloc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub struct BumpPointer;
7676

7777
unsafe impl GlobalAlloc for BumpPointer {
7878
#[inline(always)]
79+
#[allow(static_mut_refs)]
7980
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
8081
let (bytes, align) = (layout.size(), layout.align());
8182
let ptr = LOCAL_ALLOCATOR.alloc(bytes, align);

soroban-sdk/src/lib.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,34 +59,12 @@ pub mod _migrating;
5959
compile_error!("'testutils' feature is not supported on 'wasm' target");
6060

6161
// When used in a no_std contract, provide a panic handler as one is required.
62-
#[cfg(all(not(feature = "alloc"), target_family = "wasm"))]
62+
#[cfg(target_family = "wasm")]
6363
#[panic_handler]
6464
fn handle_panic(_: &core::panic::PanicInfo) -> ! {
6565
core::arch::wasm32::unreachable()
6666
}
6767

68-
// This is a bit subtle: we want to provide a narrowly-scoped feature `"alloc"`
69-
// that provides support for the `alloc` crate and its types, while using our
70-
// allocator (defined below in module `alloc`). We want to do this without
71-
// changing the user-interface a lot (in particular keeping users writing
72-
// `#[no_std]` and mostly not-using the stdlib casually, because it has many
73-
// components that produce large code footprint).
74-
//
75-
// This is _almost_ possible without involving `std` but unfortunately there's
76-
// still an allocation-error handler (`alloc_error_handler`) that there's no
77-
// stable way to install if one only uses the `alloc` crate, so we pull in a
78-
// dependency on `std` here (for now). When the stabilization of the allocation
79-
// error handler registration function happens in some future Rust version, or
80-
// it gets removed which it looks like work is heading towards instead, we can
81-
// remove std.
82-
//
83-
// See these issues for more details:
84-
// - https://github.com/rust-lang/rust/issues/51540
85-
// - https://github.com/rust-lang/rust/issues/66740
86-
// - https://github.com/rust-lang/rust/issues/66741
87-
#[cfg(all(feature = "alloc", target_family = "wasm"))]
88-
extern crate std;
89-
9068
// Here we provide a `#[global_allocator]` that is a minimal non-freeing bump
9169
// allocator, appropriate for a WASM blob that runs a single contract call.
9270
#[cfg(all(feature = "alloc", target_family = "wasm"))]

soroban-sdk/src/tests/contractimport.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ use stellar_xdr::{ScSpecEntry, ScSpecFunctionInputV0, ScSpecFunctionV0, ScSpecTy
55

66
mod addcontract {
77
use crate as soroban_sdk;
8-
soroban_sdk::contractimport!(
9-
file = "../target/wasm32-unknown-unknown/release/test_add_u64.wasm"
10-
);
8+
soroban_sdk::contractimport!(file = "../target/wasm32v1-none/release/test_add_u64.wasm");
119
}
1210

1311
mod addcontract_u128 {
1412
use crate as soroban_sdk;
15-
soroban_sdk::contractimport!(
16-
file = "../target/wasm32-unknown-unknown/release/test_add_u128.wasm"
17-
);
13+
soroban_sdk::contractimport!(file = "../target/wasm32v1-none/release/test_add_u128.wasm");
1814
}
1915

2016
mod subcontract {

soroban-sdk/src/tests/contractimport_with_error.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use soroban_sdk::{contract, contractimpl, symbol_short, Address, Env, Symbol};
33

44
mod errcontract {
55
use crate as soroban_sdk;
6-
soroban_sdk::contractimport!(
7-
file = "../target/wasm32-unknown-unknown/release/test_errors.wasm"
8-
);
6+
soroban_sdk::contractimport!(file = "../target/wasm32v1-none/release/test_errors.wasm");
97
}
108

119
#[contract]

soroban-spec-rust/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ mod test {
123123
use super::{generate, ToFormattedString};
124124
use soroban_spec::read::from_wasm;
125125

126-
const EXAMPLE_WASM: &[u8] =
127-
include_bytes!("../../target/wasm32-unknown-unknown/release/test_udt.wasm");
126+
const EXAMPLE_WASM: &[u8] = include_bytes!("../../target/wasm32v1-none/release/test_udt.wasm");
128127

129128
#[test]
130129
fn example() {

tests/alloc/src/test.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use soroban_sdk::{testutils::EnvTestConfig, vec, Env};
44
use crate::{Contract, ContractClient};
55

66
mod imported {
7-
soroban_sdk::contractimport!(
8-
file = "../../target/wasm32-unknown-unknown/release/test_alloc.wasm"
9-
);
7+
soroban_sdk::contractimport!(file = "../../target/wasm32v1-none/release/test_alloc.wasm");
108
}
119

1210
macro_rules! tests {

tests/import_contract/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
use soroban_sdk::{contract, contractimpl, Address, Env};
33

44
mod addcontract {
5-
soroban_sdk::contractimport!(
6-
file = "../../target/wasm32-unknown-unknown/release/test_add_u64.wasm"
7-
);
5+
soroban_sdk::contractimport!(file = "../../target/wasm32v1-none/release/test_add_u64.wasm");
86
}
97

108
#[contract]

0 commit comments

Comments
 (0)