diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3c635f9..df21535 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 169ba13..3c052f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/go.mod b/go.mod index 4dc22ec..2051f4e 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/wasm-fmt/gofmt -go 1.21 +go 1.22 diff --git a/gofmt.patch b/gofmt.patch index 950e6af..0b989c5 100644 --- a/gofmt.patch +++ b/gofmt.patch @@ -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. @@ -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 @@ -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. @@ -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); @@ -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 { @@ -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); }, @@ -305,8 +304,8 @@ index 5dfc67c..96e8a3f 100644 - }, } }; - -@@ -458,7 +233,12 @@ + +@@ -458,7 +234,12 @@ null, true, false, @@ -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 && diff --git a/scripts/build.sh b/scripts/build.sh index f872ab3..f367f20 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -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