Skip to content

Commit

Permalink
chore: Update TinyGo to version 0.31.1
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Mar 2, 2024
1 parent 1d0d327 commit 03b9303
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 56 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ jobs:
registry-url: "https://registry.npmjs.org"

- run: |
wget -P ${{ runner.temp }} https://github.com/tinygo-org/tinygo/releases/download/v0.30.0/tinygo_0.30.0_amd64.deb
yes | sudo dpkg -i ${{ runner.temp }}/tinygo_0.30.0_amd64.deb
- name: Install wasm-opt
run: |
npm install -g binaryen
wget -P ${{ runner.temp }} https://github.com/tinygo-org/tinygo/releases/download/v0.31.1/tinygo_0.31.1_amd64.deb
yes | sudo dpkg -i ${{ runner.temp }}/tinygo_0.31.1_amd64.deb
- name: Build
run: scripts/build.sh
shell: bash
env:
WASM_OPT: 1

- name: Publish to npmjs
run: npm publish --provenance
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
node-version-file: ".node-version"

- run: |
wget -P ${{ runner.temp }} https://github.com/tinygo-org/tinygo/releases/download/v0.30.0/tinygo_0.30.0_amd64.deb
yes | sudo dpkg -i ${{ runner.temp }}/tinygo_0.30.0_amd64.deb
wget -P ${{ runner.temp }} https://github.com/tinygo-org/tinygo/releases/download/v0.31.1/tinygo_0.31.1_amd64.deb
yes | sudo dpkg -i ${{ runner.temp }}/tinygo_0.31.1_amd64.deb
- name: Build
run: scripts/build.sh
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/wasm-fmt/gofmt

go 1.21
go 1.22
47 changes: 18 additions & 29 deletions gofmt.patch
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
diff --git a/gofmt.js b/gofmt.js
index 5dfc67c..96e8a3f 100644
index a7f8c31..dcb950c 100644
--- a/gofmt.js
+++ b/gofmt.js
@@ -3,137 +3,12 @@
// license that can be found in the LICENSE file.
@@ -4,136 +4,12 @@
//
// This file has been modified for use by the TinyGo compiler.
-

-(() => {
- // Map multiple JavaScript environments to a single common API,
- // preferring web standards over Node.js API.
Expand Down Expand Up @@ -135,13 +134,13 @@ index 5dfc67c..96e8a3f 100644
const decoder = new TextDecoder("utf-8");
let reinterpretBuf = new DataView(new ArrayBuffer(8));
var logLine = [];

- global.Go = class {
+ class Go {
constructor() {
this._callbackTimeouts = new Map();
this._nextCallbackTimeoutID = 1;
@@ -239,50 +114,7 @@
@@ -239,50 +115,7 @@
this.importObject = {
wasi_snapshot_preview1: {
// https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#fd_write
Expand Down Expand Up @@ -189,14 +188,14 @@ index 5dfc67c..96e8a3f 100644
- crypto.getRandomValues(loadSlice(bufPtr, bufLen));
- return 0;
- },
+ fd_write() {},
+ fd_write: () => 0, // dummy
},
gojs: {
// func ticks() float64
@@ -290,17 +122,21 @@
@@ -290,17 +123,21 @@
return timeOrigin + performance.now();
},

- // func sleepTicks(timeout float64)
- "runtime.sleepTicks": (timeout) => {
- // Do not sleep, only reactivate scheduler after the given timeout.
Expand All @@ -222,12 +221,12 @@ index 5dfc67c..96e8a3f 100644
+ this._idPool.push(id);
+ }
},

// func stringVal(value string) ref
@@ -325,13 +161,6 @@
@@ -325,13 +162,6 @@
Reflect.set(v, p, x);
},

- // func valueDelete(v ref, p string)
- "syscall/js.valueDelete": (v_ref, p_ptr, p_len) => {
- const v = unboxValue(v_ref);
Expand All @@ -238,10 +237,10 @@ index 5dfc67c..96e8a3f 100644
// func valueIndex(v ref, i int) ref
"syscall/js.valueIndex": (v_ref, i) => {
return boxValue(Reflect.get(unboxValue(v_ref), i));
@@ -357,19 +186,6 @@
@@ -357,19 +187,6 @@
}
},

- // func valueInvoke(v ref, args []ref) (ref, bool)
- "syscall/js.valueInvoke": (ret_addr, v_ref, args_ptr, args_len, args_cap) => {
- try {
Expand All @@ -258,7 +257,7 @@ index 5dfc67c..96e8a3f 100644
// func valueNew(v ref, args []ref) (ref, bool)
"syscall/js.valueNew": (ret_addr, v_ref, args_ptr, args_len, args_cap) => {
const v = unboxValue(v_ref);
@@ -401,47 +217,6 @@
@@ -401,47 +218,6 @@
const str = unboxValue(v_ref);
loadSlice(slice_ptr, slice_len, slice_cap).set(str);
},
Expand Down Expand Up @@ -305,8 +304,8 @@ index 5dfc67c..96e8a3f 100644
- },
}
};
@@ -458,7 +233,12 @@

@@ -458,7 +234,12 @@
null,
true,
false,
Expand All @@ -320,20 +319,10 @@ index 5dfc67c..96e8a3f 100644
this,
];
this._goRefCounts = []; // number of references that Go has to a JS value, indexed by reference id
@@ -466,8 +246,6 @@
this._idPool = []; // unused ids that have been garbage collected
this.exited = false; // whether the Go program has exited

- const mem = new DataView(this._inst.exports.memory.buffer)
-
while (true) {
const callbackPromise = new Promise((resolve) => {
this._resolveCallbackPromise = () => {
@@ -505,25 +283,71 @@
};
@@ -504,24 +285,71 @@
}
}
-

- if (
- global.require &&
- global.require.main === module &&
Expand Down
17 changes: 1 addition & 16 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
set -Eeo pipefail

echo "Building..."
tinygo build -o=gofmt.wasm -target=wasm -no-debug -stack-size=64kb ./src/lib.go

if [[ ! -z "${WASM_OPT}" ]]; then
echo "Optimizing..."

tmp_dir=$(mktemp -d)
cp gofmt.wasm $tmp_dir/gofmt.wasm

wasm-opt gofmt.wasm -Os -o $tmp_dir/gofmt_os.wasm
wasm-opt gofmt.wasm -Oz -o $tmp_dir/gofmt_oz.wasm

smallest_wasm=$(ls -Sr $tmp_dir/*.wasm | head -1)

mv $smallest_wasm gofmt.wasm
rm -rf $tmp_dir
fi
tinygo build -o=gofmt.wasm -target=wasm -no-debug ./src/lib.go

echo "Generating JS..."
cp $(tinygo env TINYGOROOT)/targets/wasm_exec.js ./gofmt.js
Expand Down

0 comments on commit 03b9303

Please sign in to comment.