From 7bf18635f2ff2f4e78d568db6c3f21d8266c5937 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 27 Feb 2024 08:48:01 -0800 Subject: [PATCH] Add a WebAssembly build to release (#6351) Simply build wasm-opt with Emscripten and bundle that up. Example build: https://github.com/kripken/binaryen/releases/tag/wasm-build-1 Specifically binaryen-wasm-build-1-wasm.tar.gz Only 1.72 MB, as it's just wasm-opt and not any other tool, so it is much smaller than our other targets. Perhaps we will add more of the tools later as needed (wasm-metadce, wasm-split, etc.). Also update the readme regarding which toolchains use us as a library, that I noticed while editing it to add the release platforms. --- .github/workflows/create_release.yml | 66 ++++++++++++++++++++++++++++ README.md | 33 +++++++++++++- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 8b5bb8ac0fb..a5d1f459e56 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -168,3 +168,69 @@ jobs: files: | ${{ steps.archive.outputs.tarball }} ${{ steps.archive.outputs.shasum }} + + # Build using Emscripten to JavaScript+WebAssembly. + build-node: + name: node + runs-on: ubuntu-latest + defaults: + run: + shell: bash + steps: + - uses: actions/setup-python@v1 + with: + python-version: '3.x' + - uses: actions/checkout@v1 + with: + submodules: true + - name: install ninja + run: sudo apt-get install ninja-build + - name: emsdk install + run: | + mkdir $HOME/emsdk + git clone --depth 1 https://github.com/emscripten-core/emsdk.git $HOME/emsdk + $HOME/emsdk/emsdk update-tags + $HOME/emsdk/emsdk install tot + $HOME/emsdk/emsdk activate tot + - name: update path + run: echo "PATH=$PATH:$HOME/emsdk" >> $GITHUB_ENV + + # Configure with wasm EH and pthreads for maximal performance. + - name: cmake + run: | + source $HOME/emsdk/emsdk_env.sh + emcmake cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install -DEMSCRIPTEN_ENABLE_WASM_EH=ON -DEMSCRIPTEN_ENABLE_PTHREADS=ON + + # Build wasm-opt for now TODO add other tools as desired + - name: build + run: ninja -C out wasm-opt + + # Minimal smoke test: roundtrip a file. + # TODO: Add more testing here, but the full test suite is overkill as there + # is a 0.5 second cost to each run of wasm-opt.js + - name: test + run: | + node out/bin/wasm-opt.js test/hello_world.wat --print > out/t.wat + diff test/hello_world.wat out/t.wat + + - name: archive + id: archive + run: | + VERSION=$GITHUB_REF_NAME + PKGNAME="binaryen-$VERSION-node" + TARBALL=$PKGNAME.tar.gz + SHASUM=$PKGNAME.tar.gz.sha256 + mkdir binaryen-$VERSION + cp out/bin/wasm-opt* binaryen-$VERSION/ + tar -czf $TARBALL binaryen-$VERSION + cmake -E sha256sum $TARBALL > $SHASUM + echo "::set-output name=tarball::$TARBALL" + echo "::set-output name=shasum::$SHASUM" + + - name: upload tarball + uses: softprops/action-gh-release@v1 + with: + draft: true + files: | + ${{ steps.archive.outputs.tarball }} + ${{ steps.archive.outputs.shasum }} diff --git a/README.md b/README.md index e4b47e2c5b6..943da98a0b5 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,18 @@ effective**: wasm [minification], similar to minification for JavaScript, CSS, etc., all of which are language-specific. -Compilers using Binaryen include: +Toolchains using Binaryen as a **component** (typically running `wasm-opt`) include: + + * [`Emscripten`](http://emscripten.org) (C/C++) + * [`wasm-pack`](https://github.com/rustwasm/wasm-pack) (Rust) + * [`J2CL`](https://j2cl.io/) (Java; [`J2Wasm`](https://github.com/google/j2cl/tree/master/samples/wasm)) + * [`Kotlin`](https://kotl.in/wasmgc) (Kotlin/Wasm) + * [`Dart`](https://flutter.dev/wasm) (Flutter) + +For more on how some of those work, see the toolchain architecture parts of +the [V8 WasmGC porting blogpost](https://v8.dev/blog/wasm-gc-porting). + +Compilers using Binaryen as a **library** include: * [`AssemblyScript`](https://github.com/AssemblyScript/assemblyscript) which compiles a variant of TypeScript to WebAssembly * [`wasm2js`](https://github.com/WebAssembly/binaryen/blob/main/src/wasm2js.h) which compiles WebAssembly to JS @@ -387,6 +398,26 @@ Binaryen.js can be built using Emscripten, which can be installed via [the SDK]( CMake generates a project named "ALL_BUILD.vcxproj" for conveniently building all the projects. +## Releases + +Builds are distributed by the various toolchains that use Binaryen, like +Emscripten, `wasm-pack`, etc. There are also official releases on GitHub: + +https://github.com/WebAssembly/binaryen/releases + +Currently builds of the following platforms are included: + + * `Linux-x86_64` + * `Linux-arm64` + * `MacOS-x86_64` + * `MacOS-arm64` + * `Windows-x86_64` + * `Node.js` (experimental): A port of `wasm-opt` to JavaScript+WebAssembly. + Run `node wasm-opt.js` as a drop-in replacement for a native build of + `wasm-opt`, on any platform that Node.js runs on. Requires Node.js 18+ (for + Wasm EH and Wasm Threads). (Note that this build may also run in Deno, Bun, + or other JavaScript+WebAssembly environments, but is tested only on Node.js.) + ## Running ### wasm-opt