@@ -6,23 +6,31 @@ PUBLIC_DIR ?= $(UI)/public
66WEBWORKER_PKG ?= ./cmd/webworker
77INTERPRETER_PKG ?= ./cmd/go-repl
88
9+ define build_wasm_worker
10+ @echo ":: Building WebAssembly worker '$(1 ) ' ..."
11+ GOOS=js GOARCH=wasm $(GO ) build -ldflags "-s -w" -trimpath \
12+ $(3 ) -o $(PUBLIC_DIR ) /$(2 ) $(1 )
13+ endef
14+
15+ define check_tool
16+ @if ! command -v $(1 ) >/dev/null 2>&1 ; then\
17+ echo "ERROR: '$(1 ) ' binary not found. Please ensure that tool is installed or specify binary path with '$(2 ) ' variable." && \
18+ exit 1; \
19+ fi;
20+ endef
21+
22+
923.PHONY : clean
1024clean :
1125 @echo " :: Cleanup..." && rm -rf $(TARGET ) && rm -rf $(UI ) /build
1226
1327.PHONY :check-go
1428check-go :
15- @if ! command -v $(GO ) > /dev/null 2>&1 ; then\
16- echo " ERROR: '$( GO) ' binary not found. Please ensure that Go is installed or specify binary path with 'GO' variable." && \
17- exit 1; \
18- fi ;
29+ $(call check_tool,$(GO ) ,'GO')
1930
2031.PHONY :check-yarn
2132check-yarn :
22- @if ! command -v $(YARN ) > /dev/null 2>&1 ; then\
23- echo " ERROR: '$( YARN) ' binary not found. Please ensure that Node.js and Yarn are installed or specify binary path with 'YARN' variable." && \
24- exit 1; \
25- fi ;
33+ $(call check_tool,$(YARN ) ,'YARN')
2634
2735# Build targets
2836.PHONY : collect-meta
@@ -51,13 +59,11 @@ copy-wasm-exec:
5159
5260.PHONY :build-webworker
5361build-webworker :
54- @echo " :: Building Go Webworker module..." && \
55- GOOS=js GOARCH=wasm $(GO ) build -o $(PUBLIC_DIR ) /worker.wasm $(WEBWORKER_PKG )
62+ $(call build_wasm_worker,$(WEBWORKER_PKG ) ,'worker.wasm')
5663
5764.PHONY :go-repl
5865go-repl :
59- @echo " :: Building Go interpreter module..." && \
60- GOOS=js GOARCH=wasm $(GO ) build -o $(PUBLIC_DIR ) /go-repl.wasm $(INTERPRETER_PKG )
66+ $(call build_wasm_worker,$(INTERPRETER_PKG ) ,'go-repl.wasm')
6167
6268.PHONY :build-wasm
6369build-wasm : copy-wasm-exec build-webworker go-repl
0 commit comments