Skip to content

Commit

Permalink
Add a WebAssembly build to release (WebAssembly#6351)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kripken authored and radekdoulik committed Jul 12, 2024
1 parent 9d15944 commit 7bf1863
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
66 changes: 66 additions & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7bf1863

Please sign in to comment.