Skip to content

Commit b5c5d95

Browse files
aykevldeadprogram
authored andcommitted
wasm: use newer WebAssembly features
This commit will start to use a few more WebAssembly features, such as bulk memory operations. This results in a significant code size saving. How much it saves varies a lot but it's typically around 1300 bytes. This change is possible by bumping our minimum Node.js version to 14. The previous LTS version (12) has been marked end of life, so we can start to depend on features in the current oldest LTS version, which is version 14. Browsers have been supporting these features for a long time now, it's just Node.js that prevented us doing this before.
1 parent 633fe95 commit b5c5d95

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

.github/workflows/linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ jobs:
167167
- name: Install Node.js
168168
uses: actions/setup-node@v2
169169
with:
170-
node-version: '12'
170+
node-version: '14'
171171
- name: Install wasmtime
172172
run: |
173173
curl https://wasmtime.dev/install.sh -sSf | bash

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ endif
234234
wasi-libc: lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a
235235
lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a:
236236
@if [ ! -e lib/wasi-libc/Makefile ]; then echo "Submodules have not been downloaded. Please download them using:\n git submodule update --init"; exit 1; fi
237-
cd lib/wasi-libc && make -j4 WASM_CFLAGS="-O2 -g -DNDEBUG" MALLOC_IMPL=none CC=$(CLANG) AR=$(LLVM_AR) NM=$(LLVM_NM)
237+
cd lib/wasi-libc && make -j4 WASM_CFLAGS="-O2 -g -DNDEBUG -mnontrapping-fptoint -msign-ext" MALLOC_IMPL=none CC=$(CLANG) AR=$(LLVM_AR) NM=$(LLVM_NM)
238238

239239

240240
# Build the Go compiler.

targets/wasi.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
{
22
"llvm-target": "wasm32-unknown-wasi",
33
"cpu": "generic",
4+
"features": "+bulk-memory,+nontrapping-fptoint,+sign-ext",
45
"build-tags": ["tinygo.wasm", "wasi"],
56
"goos": "linux",
67
"goarch": "arm",
78
"linker": "wasm-ld",
89
"libc": "wasi-libc",
910
"scheduler": "asyncify",
1011
"default-stack-size": 16384,
12+
"cflags": [
13+
"-mbulk-memory",
14+
"-mnontrapping-fptoint",
15+
"-msign-ext"
16+
],
1117
"ldflags": [
1218
"--allow-undefined",
1319
"--stack-first",

targets/wasm.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
{
22
"llvm-target": "wasm32-unknown-wasi",
33
"cpu": "generic",
4+
"features": "+bulk-memory,+nontrapping-fptoint,+sign-ext",
45
"build-tags": ["tinygo.wasm"],
56
"goos": "js",
67
"goarch": "wasm",
78
"linker": "wasm-ld",
89
"libc": "wasi-libc",
910
"scheduler": "asyncify",
1011
"default-stack-size": 16384,
12+
"cflags": [
13+
"-mbulk-memory",
14+
"-mnontrapping-fptoint",
15+
"-msign-ext"
16+
],
1117
"ldflags": [
1218
"--allow-undefined",
1319
"--stack-first",

0 commit comments

Comments
 (0)