diff --git a/recipes/recipes_emscripten/libwgpu-native/build.sh b/recipes/recipes_emscripten/libwgpu-native/build.sh new file mode 100755 index 00000000000..21e629d50f6 --- /dev/null +++ b/recipes/recipes_emscripten/libwgpu-native/build.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +set -euo pipefail + +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="$(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}" + +# 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:+${RUSTFLAGS} }-C link-arg=-sSIDE_MODULE=2" + +mkdir -p .cargo +cat > .cargo/config.toml << 'EOF' +[target.wasm32-unknown-emscripten] +linker = "emcc" +EOF + +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 + +mkdir -p ${PREFIX}/lib ${PREFIX}/include/wgpu-native +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/ diff --git a/recipes/recipes_emscripten/libwgpu-native/recipe.yaml b/recipes/recipes_emscripten/libwgpu-native/recipe.yaml new file mode 100644 index 00000000000..09369282774 --- /dev/null +++ b/recipes/recipes_emscripten/libwgpu-native/recipe.yaml @@ -0,0 +1,47 @@ +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 + +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