Skip to content

Commit 4449d59

Browse files
committed
use tinigo to generate wasm (6MB -> 3MB)
1 parent 9380e10 commit 4449d59

File tree

5 files changed

+325
-334
lines changed

5 files changed

+325
-334
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
build: sqldef.wasm
2+
.PHONY: build
3+
14
sqldef.wasm: go.mod go.sum sqldef-wasm.go wasm_exec.js
2-
GOOS=js GOARCH=wasm go build $(GOFLAGS) -o sqldef.wasm ./sqldef-wasm.go
5+
tinygo build -x -o sqldef.wasm -target=wasm ./sqldef-wasm.go
36

47
wasm_exec.js:
5-
cp $$(go env GOROOT)/lib/wasm/wasm_exec.js .
8+
cp $$(tinygo env TINYGOROOT)/targets/wasm_exec.js .
69

710
dev: sqldef.wasm
811
@echo "Starting HTTP server at http://localhost:6543"

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,19 @@ The Go source (`sqldef-wasm.go`) compiles to WebAssembly and exposes a `diff` fu
1414

1515
## Development
1616

17+
### Prerequisites
18+
19+
Install [TinyGo](https://tinygo.org/):
20+
21+
```sh
22+
brew tap tinygo-org/tools && brew install tinygo
23+
```
24+
25+
### Build
26+
1727
```sh
1828
# Build the WASM file
19-
make
29+
make build
2030

2131
# Start local dev server at http://localhost:6543
2232
make dev

sqldef-wasm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func main() {
7474
c := make(chan bool)
7575

7676
exports := map[string]any{
77-
"diff": js.FuncOf(sqldefDiff),
77+
"diff": js.FuncOf(sqldefDiff),
7878
"getFullVersion": js.FuncOf(sqldefGetFullVersion),
7979
}
8080
js.Global().Set("_SQLDEF", js.ValueOf(exports))

sqldef.wasm

100755100644
-2.97 MB
Binary file not shown.

0 commit comments

Comments
 (0)