Skip to content

Commit 94ca4d3

Browse files
authored
Fix wasm32-wasip1-threads: shared-memory disallowed due to not compiled with 'atomics' or 'bulk-memory' features (#1221)
1 parent e198c7f commit 94ca4d3

File tree

5 files changed

+103
-0
lines changed

5 files changed

+103
-0
lines changed

.github/workflows/main.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,49 @@ jobs:
192192
- run: cargo test --no-run --target ${{ matrix.target }} --release
193193
- run: cargo test --no-run --target ${{ matrix.target }} --features parallel
194194

195+
test-wasm32-wasip1-thread:
196+
name: Test wasm32-wasip1-thread
197+
runs-on: ubuntu-latest
198+
env:
199+
TARGET: wasm32-wasip1-threads
200+
steps:
201+
- uses: actions/checkout@v4
202+
- name: Install Rust (rustup)
203+
run: |
204+
rustup toolchain install nightly --no-self-update --profile minimal --target $TARGET
205+
206+
- name: Get latest version of wasi-sdk
207+
env:
208+
REPO: WebAssembly/wasi-sdk
209+
GH_TOKEN: ${{ github.token }}
210+
run: |
211+
set -euxo pipefail
212+
VERSION="$(gh release list --repo $REPO -L 1 --json tagName --jq '.[]|.tagName')"
213+
echo "WASI_TOOLCHAIN_VERSION=$VERSION" >> "$GITHUB_ENV"
214+
215+
- name: Install wasi-sdk
216+
working-directory: /tmp
217+
env:
218+
REPO: WebAssembly/wasi-sdk
219+
run: |
220+
set -euxo pipefail
221+
VERSION="$WASI_TOOLCHAIN_VERSION"
222+
FILE="${VERSION}.0-x86_64-linux.deb"
223+
wget "https://github.com/$REPO/releases/download/${VERSION}/${FILE}"
224+
sudo dpkg -i "${FILE}"
225+
WASI_SDK_PATH="/opt/wasi-sdk"
226+
CC="${WASI_SDK_PATH}/bin/clang"
227+
echo "WASI_SDK_PATH=$WASI_SDK_PATH" >> "$GITHUB_ENV"
228+
echo "CC=$CC" >> "$GITHUB_ENV"
229+
230+
- uses: Swatinem/rust-cache@v2
231+
with:
232+
env-vars: "WASI_TOOLCHAIN_VERSION"
233+
cache-all-crates: "true"
234+
235+
- name: Run tests
236+
run: cargo +nightly build -p $TARGET-test --target $TARGET
237+
195238
cuda:
196239
name: Test CUDA support
197240
runs-on: ubuntu-20.04

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ members = [
4242
"dev-tools/cc-test",
4343
"dev-tools/gen-target-info",
4444
"dev-tools/gen-windows-sys-binding",
45+
"dev-tools/wasm32-wasip1-threads-test",
4546
]
47+
48+
[patch.crates-io]
49+
cc = { path = "." }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "wasm32-wasip1-threads-test"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[dependencies]
8+
rusqlite = { version = "0.32.0", features = ["bundled"] }
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use rusqlite::{Connection, Result};
2+
3+
#[derive(Debug)]
4+
struct Person {
5+
pub id: i32,
6+
pub name: String,
7+
pub data: Option<Vec<u8>>,
8+
}
9+
10+
fn main() -> Result<()> {
11+
let conn = Connection::open_in_memory()?;
12+
13+
conn.execute(
14+
"CREATE TABLE person (
15+
id INTEGER PRIMARY KEY,
16+
name TEXT NOT NULL,
17+
data BLOB
18+
)",
19+
(), // empty list of parameters.
20+
)?;
21+
let me = Person {
22+
id: 0,
23+
name: "Steven".to_string(),
24+
data: None,
25+
};
26+
conn.execute(
27+
"INSERT INTO person (name, data) VALUES (?1, ?2)",
28+
(&me.name, &me.data),
29+
)?;
30+
31+
let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
32+
let person_iter = stmt.query_map([], |row| {
33+
Ok(Person {
34+
id: row.get(0)?,
35+
name: row.get(1)?,
36+
data: row.get(2)?,
37+
})
38+
})?;
39+
40+
for person in person_iter {
41+
println!("Found person {:?}", person.unwrap());
42+
}
43+
Ok(())
44+
}

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,10 @@ impl Build {
20192019
format!("--sysroot={}", Path::new(&wasi_sysroot).display()).into(),
20202020
);
20212021
}
2022+
2023+
if target.contains("threads") {
2024+
cmd.push_cc_arg("-pthread".into());
2025+
}
20222026
}
20232027
}
20242028
}

0 commit comments

Comments
 (0)