Skip to content

Commit

Permalink
Fix wasm32-wasip1-threads: shared-memory disallowed due to not compil…
Browse files Browse the repository at this point in the history
…ed with 'atomics' or 'bulk-memory' features (#1221)
  • Loading branch information
NobodyXu authored Oct 1, 2024
1 parent e198c7f commit 94ca4d3
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,49 @@ jobs:
- run: cargo test --no-run --target ${{ matrix.target }} --release
- run: cargo test --no-run --target ${{ matrix.target }} --features parallel

test-wasm32-wasip1-thread:
name: Test wasm32-wasip1-thread
runs-on: ubuntu-latest
env:
TARGET: wasm32-wasip1-threads
steps:
- uses: actions/checkout@v4
- name: Install Rust (rustup)
run: |
rustup toolchain install nightly --no-self-update --profile minimal --target $TARGET
- name: Get latest version of wasi-sdk
env:
REPO: WebAssembly/wasi-sdk
GH_TOKEN: ${{ github.token }}
run: |
set -euxo pipefail
VERSION="$(gh release list --repo $REPO -L 1 --json tagName --jq '.[]|.tagName')"
echo "WASI_TOOLCHAIN_VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Install wasi-sdk
working-directory: /tmp
env:
REPO: WebAssembly/wasi-sdk
run: |
set -euxo pipefail
VERSION="$WASI_TOOLCHAIN_VERSION"
FILE="${VERSION}.0-x86_64-linux.deb"
wget "https://github.com/$REPO/releases/download/${VERSION}/${FILE}"
sudo dpkg -i "${FILE}"
WASI_SDK_PATH="/opt/wasi-sdk"
CC="${WASI_SDK_PATH}/bin/clang"
echo "WASI_SDK_PATH=$WASI_SDK_PATH" >> "$GITHUB_ENV"
echo "CC=$CC" >> "$GITHUB_ENV"
- uses: Swatinem/rust-cache@v2
with:
env-vars: "WASI_TOOLCHAIN_VERSION"
cache-all-crates: "true"

- name: Run tests
run: cargo +nightly build -p $TARGET-test --target $TARGET

cuda:
name: Test CUDA support
runs-on: ubuntu-20.04
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ members = [
"dev-tools/cc-test",
"dev-tools/gen-target-info",
"dev-tools/gen-windows-sys-binding",
"dev-tools/wasm32-wasip1-threads-test",
]

[patch.crates-io]
cc = { path = "." }
8 changes: 8 additions & 0 deletions dev-tools/wasm32-wasip1-threads-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "wasm32-wasip1-threads-test"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
rusqlite = { version = "0.32.0", features = ["bundled"] }
44 changes: 44 additions & 0 deletions dev-tools/wasm32-wasip1-threads-test/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use rusqlite::{Connection, Result};

#[derive(Debug)]
struct Person {
pub id: i32,
pub name: String,
pub data: Option<Vec<u8>>,
}

fn main() -> Result<()> {
let conn = Connection::open_in_memory()?;

conn.execute(
"CREATE TABLE person (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
data BLOB
)",
(), // empty list of parameters.
)?;
let me = Person {
id: 0,
name: "Steven".to_string(),
data: None,
};
conn.execute(
"INSERT INTO person (name, data) VALUES (?1, ?2)",
(&me.name, &me.data),
)?;

let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
let person_iter = stmt.query_map([], |row| {
Ok(Person {
id: row.get(0)?,
name: row.get(1)?,
data: row.get(2)?,
})
})?;

for person in person_iter {
println!("Found person {:?}", person.unwrap());
}
Ok(())
}
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,10 @@ impl Build {
format!("--sysroot={}", Path::new(&wasi_sysroot).display()).into(),
);
}

if target.contains("threads") {
cmd.push_cc_arg("-pthread".into());
}
}
}
}
Expand Down

0 comments on commit 94ca4d3

Please sign in to comment.