Skip to content

Commit

Permalink
popm/wasm: add wasm-opt target to optimise wasm binary (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuasing authored Jun 26, 2024
1 parent 27a5081 commit b5b5647
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions web/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,27 @@ WASM_BINARY=$(WEBAPP)/popminer.wasm
version = $(patsubst v%,%,$(shell git describe --tags 2>/dev/null || echo "v0.0.0"))
commit = $(shell git rev-parse --short HEAD)

.PHONY: all clean wasm www
.PHONY: all clean wasm wasm-opt www

all: wasm www

clean:
rm -rf ${WEBAPP}
rm -rf ${WASM_BINARY}

# TODO(joshuasing): research using binaryen (wasm-opt) to optimise output binary
wasm:
CGO_ENABLED=0 GOOS=js GOARCH=wasm go build -trimpath -tags "$(BUILD_TAGS)" \
-ldflags "-s -w -X main.version=${version} -X main.gitCommit=${commit}" \
-o ${WASM_BINARY} ${PROJECTPATH}/popminer/...

wasm-opt:
@which wasm-opt || {\
echo "wasm-opt: wasm-opt must be installed to use this target";\
echo "wasm-opt: https://github.com/WebAssembly/binaryen";\
exit 1; }
wasm-opt -Oz ${WASM_BINARY} -o ${WASM_BINARY}.opt --enable-bulk-memory --intrinsic-lowering
mv ${WASM_BINARY}.opt ${WASM_BINARY}

www: wasm
mkdir -p ${WEBAPP}
cp ${WWW_DIR}/index.html ${WEBAPP}
Expand Down

0 comments on commit b5b5647

Please sign in to comment.