Skip to content

Commit 7bf1863

Browse files
kripkenradekdoulik
authored andcommitted
Add a WebAssembly build to release (WebAssembly#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.
1 parent 9d15944 commit 7bf1863

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

.github/workflows/create_release.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,69 @@ jobs:
168168
files: |
169169
${{ steps.archive.outputs.tarball }}
170170
${{ steps.archive.outputs.shasum }}
171+
172+
# Build using Emscripten to JavaScript+WebAssembly.
173+
build-node:
174+
name: node
175+
runs-on: ubuntu-latest
176+
defaults:
177+
run:
178+
shell: bash
179+
steps:
180+
- uses: actions/setup-python@v1
181+
with:
182+
python-version: '3.x'
183+
- uses: actions/checkout@v1
184+
with:
185+
submodules: true
186+
- name: install ninja
187+
run: sudo apt-get install ninja-build
188+
- name: emsdk install
189+
run: |
190+
mkdir $HOME/emsdk
191+
git clone --depth 1 https://github.com/emscripten-core/emsdk.git $HOME/emsdk
192+
$HOME/emsdk/emsdk update-tags
193+
$HOME/emsdk/emsdk install tot
194+
$HOME/emsdk/emsdk activate tot
195+
- name: update path
196+
run: echo "PATH=$PATH:$HOME/emsdk" >> $GITHUB_ENV
197+
198+
# Configure with wasm EH and pthreads for maximal performance.
199+
- name: cmake
200+
run: |
201+
source $HOME/emsdk/emsdk_env.sh
202+
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
203+
204+
# Build wasm-opt for now TODO add other tools as desired
205+
- name: build
206+
run: ninja -C out wasm-opt
207+
208+
# Minimal smoke test: roundtrip a file.
209+
# TODO: Add more testing here, but the full test suite is overkill as there
210+
# is a 0.5 second cost to each run of wasm-opt.js
211+
- name: test
212+
run: |
213+
node out/bin/wasm-opt.js test/hello_world.wat --print > out/t.wat
214+
diff test/hello_world.wat out/t.wat
215+
216+
- name: archive
217+
id: archive
218+
run: |
219+
VERSION=$GITHUB_REF_NAME
220+
PKGNAME="binaryen-$VERSION-node"
221+
TARBALL=$PKGNAME.tar.gz
222+
SHASUM=$PKGNAME.tar.gz.sha256
223+
mkdir binaryen-$VERSION
224+
cp out/bin/wasm-opt* binaryen-$VERSION/
225+
tar -czf $TARBALL binaryen-$VERSION
226+
cmake -E sha256sum $TARBALL > $SHASUM
227+
echo "::set-output name=tarball::$TARBALL"
228+
echo "::set-output name=shasum::$SHASUM"
229+
230+
- name: upload tarball
231+
uses: softprops/action-gh-release@v1
232+
with:
233+
draft: true
234+
files: |
235+
${{ steps.archive.outputs.tarball }}
236+
${{ steps.archive.outputs.shasum }}

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@ effective**:
2424
wasm [minification], similar to minification for JavaScript, CSS, etc., all
2525
of which are language-specific.
2626

27-
Compilers using Binaryen include:
27+
Toolchains using Binaryen as a **component** (typically running `wasm-opt`) include:
28+
29+
* [`Emscripten`](http://emscripten.org) (C/C++)
30+
* [`wasm-pack`](https://github.com/rustwasm/wasm-pack) (Rust)
31+
* [`J2CL`](https://j2cl.io/) (Java; [`J2Wasm`](https://github.com/google/j2cl/tree/master/samples/wasm))
32+
* [`Kotlin`](https://kotl.in/wasmgc) (Kotlin/Wasm)
33+
* [`Dart`](https://flutter.dev/wasm) (Flutter)
34+
35+
For more on how some of those work, see the toolchain architecture parts of
36+
the [V8 WasmGC porting blogpost](https://v8.dev/blog/wasm-gc-porting).
37+
38+
Compilers using Binaryen as a **library** include:
2839

2940
* [`AssemblyScript`](https://github.com/AssemblyScript/assemblyscript) which compiles a variant of TypeScript to WebAssembly
3041
* [`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](
387398

388399
CMake generates a project named "ALL_BUILD.vcxproj" for conveniently building all the projects.
389400

401+
## Releases
402+
403+
Builds are distributed by the various toolchains that use Binaryen, like
404+
Emscripten, `wasm-pack`, etc. There are also official releases on GitHub:
405+
406+
https://github.com/WebAssembly/binaryen/releases
407+
408+
Currently builds of the following platforms are included:
409+
410+
* `Linux-x86_64`
411+
* `Linux-arm64`
412+
* `MacOS-x86_64`
413+
* `MacOS-arm64`
414+
* `Windows-x86_64`
415+
* `Node.js` (experimental): A port of `wasm-opt` to JavaScript+WebAssembly.
416+
Run `node wasm-opt.js` as a drop-in replacement for a native build of
417+
`wasm-opt`, on any platform that Node.js runs on. Requires Node.js 18+ (for
418+
Wasm EH and Wasm Threads). (Note that this build may also run in Deno, Bun,
419+
or other JavaScript+WebAssembly environments, but is tested only on Node.js.)
420+
390421
## Running
391422

392423
### wasm-opt

0 commit comments

Comments
 (0)