From 91ab2f056112448662b15230098ddc7c40adac48 Mon Sep 17 00:00:00 2001 From: Alexis Placet Date: Wed, 29 Jul 2026 18:19:17 +0200 Subject: [PATCH 1/3] Add libwgpu-native --- .../libwgpu-native/build.sh | 63 +++++++++++++++++++ .../libwgpu-native/recipe.yaml | 56 +++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100755 recipes/recipes_emscripten/libwgpu-native/build.sh create mode 100644 recipes/recipes_emscripten/libwgpu-native/recipe.yaml diff --git a/recipes/recipes_emscripten/libwgpu-native/build.sh b/recipes/recipes_emscripten/libwgpu-native/build.sh new file mode 100755 index 00000000000..7017898a299 --- /dev/null +++ b/recipes/recipes_emscripten/libwgpu-native/build.sh @@ -0,0 +1,63 @@ +#!/bin/bash +set -ex + +export PATH=$(echo "$PATH" | tr ':' '\n' | grep -v "\.cargo/bin" | grep -v "\.rustup" | tr '\n' ':' | sed 's/:$//') + +EMCC=$(which emcc) +export EMSDK="${EMSCRIPTEN_FORGE_EMSDK_DIR}" +export PATH="${EMSDK}/upstream/bin:${PATH}" +EMSCRIPTEN_SYSTEM="${EMSDK}/upstream/emscripten/system" + +rustup target add wasm32-unknown-emscripten +export CC="${EMCC}" +export CXX="${EMCC}++" +export AR="$(which emar)" +export RANLIB="$(which emranlib)" + +echo "Checking for webgpu.h..." +ls -la ffi/webgpu-headers/webgpu.h + +# bindgen include paths +BINDGEN_ARGS="--target=wasm32-unknown-emscripten \ + -I${EMSCRIPTEN_SYSTEM}/include \ + -I${EMSCRIPTEN_SYSTEM}/include/compat \ + -I${EMSCRIPTEN_SYSTEM}/include/libc \ + -I${EMSCRIPTEN_SYSTEM}/lib/libc/musl/include \ + -I${EMSCRIPTEN_SYSTEM}/lib/libc/musl/arch/emscripten \ + -Iffi/webgpu-headers \ + -I." +export BINDGEN_EXTRA_CLANG_ARGS="${BINDGEN_ARGS}" +export BINDGEN_EXTRA_CLANG_ARGS_wasm32_unknown_emscripten="${BINDGEN_ARGS}" + +# Emscripten side modules contain Rust-mangled exports, which are valid Wasm +# names but not JavaScript identifiers. Do not validate those names as JS. +sed -i 's/if not n.isidentifier():/if not n.isidentifier() and not settings.SIDE_MODULE:/' \ + "${EMSDK}/upstream/emscripten/tools/emscripten.py" + +# Cargo only forwards linker arguments from RUSTFLAGS. +export RUSTFLAGS="${RUSTFLAGS:-} -C link-arg=-sSIDE_MODULE=2" + +mkdir -p .cargo +cat > .cargo/config.toml << 'EOF' +[target.wasm32-unknown-emscripten] +linker = "emcc" +EOF + +# Patch Cargo.toml for Send/Sync on wasm +sed -i '/^\[features\]/a fragile-send-sync-non-atomic-wasm = ["wgc/fragile-send-sync-non-atomic-wasm", "hal/fragile-send-sync-non-atomic-wasm"]' Cargo.toml + +cargo build --release \ + --target wasm32-unknown-emscripten \ + --no-default-features \ + --features wgsl,gles,fragile-send-sync-non-atomic-wasm + +# Install +mkdir -p ${PREFIX}/lib ${PREFIX}/include/wgpu-native +cp target/wasm32-unknown-emscripten/release/libwgpu_native.so ${PREFIX}/lib/ 2>/dev/null || \ + cp target/wasm32-unknown-emscripten/release/wgpu_native.wasm ${PREFIX}/lib/libwgpu_native.wasm + +cp ffi/webgpu-headers/webgpu.h ${PREFIX}/include/wgpu-native/ +cp ffi/wgpu.h ${PREFIX}/include/wgpu-native/ + +echo "Build complete" +ls -la ${PREFIX}/lib/ diff --git a/recipes/recipes_emscripten/libwgpu-native/recipe.yaml b/recipes/recipes_emscripten/libwgpu-native/recipe.yaml new file mode 100644 index 00000000000..1f26d129d81 --- /dev/null +++ b/recipes/recipes_emscripten/libwgpu-native/recipe.yaml @@ -0,0 +1,56 @@ +context: + version: "29.0.1.1" + +package: + name: libwgpu-native + version: ${{ version }} + +source: +- url: https://github.com/gfx-rs/wgpu-native/archive/refs/tags/v${{ version }}.tar.gz + sha256: 6008651e1d10022d4ded15b69405b4ba88577be5d623938ba98ad241b2cbf818 +- url: https://raw.githubusercontent.com/webgpu-native/webgpu-headers/main/webgpu.h + sha256: 2dc6334582e2a85fc81bd5b1dc1cc131b48da9f91b89075e2bd59b3f1c9f81c1 + target_directory: ffi/webgpu-headers + +build: + number: 0 + script: build.sh + + dynamic_linking: + binary_relocation: false + +requirements: + build: + - rust-nightly + - emscripten_emscripten-wasm32 + - clang + - libclang + - make + +tests: +- package_contents: + files: + - lib/libwgpu_native.wasm + - include/wgpu-native/webgpu.h + - include/wgpu-native/wgpu.h +- script: pytester + files: + recipe: + - test_libwgpu_native.py + requirements: + build: + - pytester + run: + - pytester-run + +about: + license: MIT OR Apache-2.0 + license_file: + - LICENSE.MIT + - LICENSE.APACHE + summary: Native WebGPU implementation in Rust (emscripten-wasm32) + homepage: https://github.com/gfx-rs/wgpu-native + +extra: + recipe-maintainers: + - Alex-PLACET From fce0b2eb0aece61c9fe3ab19b20ea312d20433b9 Mon Sep 17 00:00:00 2001 From: Alexis Placet Date: Wed, 29 Jul 2026 21:06:03 +0200 Subject: [PATCH 2/3] fix --- recipes/recipes_emscripten/libwgpu-native/recipe.yaml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/recipes/recipes_emscripten/libwgpu-native/recipe.yaml b/recipes/recipes_emscripten/libwgpu-native/recipe.yaml index 1f26d129d81..09369282774 100644 --- a/recipes/recipes_emscripten/libwgpu-native/recipe.yaml +++ b/recipes/recipes_emscripten/libwgpu-native/recipe.yaml @@ -33,15 +33,6 @@ tests: - lib/libwgpu_native.wasm - include/wgpu-native/webgpu.h - include/wgpu-native/wgpu.h -- script: pytester - files: - recipe: - - test_libwgpu_native.py - requirements: - build: - - pytester - run: - - pytester-run about: license: MIT OR Apache-2.0 From 10b4313c0cc9d5466f2a6f2930f3467b26426b25 Mon Sep 17 00:00:00 2001 From: Alexis Placet Date: Wed, 29 Jul 2026 21:41:22 +0200 Subject: [PATCH 3/3] wip --- .../libwgpu-native/build.sh | 41 ++++++------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/recipes/recipes_emscripten/libwgpu-native/build.sh b/recipes/recipes_emscripten/libwgpu-native/build.sh index 7017898a299..21e629d50f6 100755 --- a/recipes/recipes_emscripten/libwgpu-native/build.sh +++ b/recipes/recipes_emscripten/libwgpu-native/build.sh @@ -1,31 +1,20 @@ -#!/bin/bash -set -ex +#!/usr/bin/env bash +set -euo pipefail -export PATH=$(echo "$PATH" | tr ':' '\n' | grep -v "\.cargo/bin" | grep -v "\.rustup" | tr '\n' ':' | sed 's/:$//') - -EMCC=$(which emcc) -export EMSDK="${EMSCRIPTEN_FORGE_EMSDK_DIR}" +PATH=$(tr ':' '\n' <<<"$PATH" | grep -vE '/\.(cargo|rustup)/bin' | paste -sd:) +export PATH EMSDK="${EMSCRIPTEN_FORGE_EMSDK_DIR}" export PATH="${EMSDK}/upstream/bin:${PATH}" + +EMCC=$(command -v emcc) EMSCRIPTEN_SYSTEM="${EMSDK}/upstream/emscripten/system" rustup target add wasm32-unknown-emscripten export CC="${EMCC}" export CXX="${EMCC}++" -export AR="$(which emar)" -export RANLIB="$(which emranlib)" - -echo "Checking for webgpu.h..." -ls -la ffi/webgpu-headers/webgpu.h - -# bindgen include paths -BINDGEN_ARGS="--target=wasm32-unknown-emscripten \ - -I${EMSCRIPTEN_SYSTEM}/include \ - -I${EMSCRIPTEN_SYSTEM}/include/compat \ - -I${EMSCRIPTEN_SYSTEM}/include/libc \ - -I${EMSCRIPTEN_SYSTEM}/lib/libc/musl/include \ - -I${EMSCRIPTEN_SYSTEM}/lib/libc/musl/arch/emscripten \ - -Iffi/webgpu-headers \ - -I." +export AR="$(command -v emar)" +export RANLIB="$(command -v emranlib)" + +BINDGEN_ARGS="--target=wasm32-unknown-emscripten -I${EMSCRIPTEN_SYSTEM}/include -I${EMSCRIPTEN_SYSTEM}/include/compat -I${EMSCRIPTEN_SYSTEM}/include/libc -I${EMSCRIPTEN_SYSTEM}/lib/libc/musl/include -I${EMSCRIPTEN_SYSTEM}/lib/libc/musl/arch/emscripten -Iffi/webgpu-headers -I." export BINDGEN_EXTRA_CLANG_ARGS="${BINDGEN_ARGS}" export BINDGEN_EXTRA_CLANG_ARGS_wasm32_unknown_emscripten="${BINDGEN_ARGS}" @@ -35,7 +24,7 @@ sed -i 's/if not n.isidentifier():/if not n.isidentifier() and not settings.SIDE "${EMSDK}/upstream/emscripten/tools/emscripten.py" # Cargo only forwards linker arguments from RUSTFLAGS. -export RUSTFLAGS="${RUSTFLAGS:-} -C link-arg=-sSIDE_MODULE=2" +export RUSTFLAGS="${RUSTFLAGS:+${RUSTFLAGS} }-C link-arg=-sSIDE_MODULE=2" mkdir -p .cargo cat > .cargo/config.toml << 'EOF' @@ -43,7 +32,6 @@ cat > .cargo/config.toml << 'EOF' linker = "emcc" EOF -# Patch Cargo.toml for Send/Sync on wasm sed -i '/^\[features\]/a fragile-send-sync-non-atomic-wasm = ["wgc/fragile-send-sync-non-atomic-wasm", "hal/fragile-send-sync-non-atomic-wasm"]' Cargo.toml cargo build --release \ @@ -51,13 +39,8 @@ cargo build --release \ --no-default-features \ --features wgsl,gles,fragile-send-sync-non-atomic-wasm -# Install mkdir -p ${PREFIX}/lib ${PREFIX}/include/wgpu-native -cp target/wasm32-unknown-emscripten/release/libwgpu_native.so ${PREFIX}/lib/ 2>/dev/null || \ - cp target/wasm32-unknown-emscripten/release/wgpu_native.wasm ${PREFIX}/lib/libwgpu_native.wasm +cp target/wasm32-unknown-emscripten/release/wgpu_native.wasm ${PREFIX}/lib/libwgpu_native.wasm cp ffi/webgpu-headers/webgpu.h ${PREFIX}/include/wgpu-native/ cp ffi/wgpu.h ${PREFIX}/include/wgpu-native/ - -echo "Build complete" -ls -la ${PREFIX}/lib/