Skip to content

Commit c2f05db

Browse files
authored
Strip debug symbols in WASM files (#239)
* fix: strip debug symbols from wasm binaries in Makefile * chore: refactor tool check in Makefile * chore: trim debug symbols in Dockerfiles
1 parent 844530e commit c2f05db

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

build.mk

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,31 @@ PUBLIC_DIR ?= $(UI)/public
66
WEBWORKER_PKG ?= ./cmd/webworker
77
INTERPRETER_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
1024
clean:
1125
@echo ":: Cleanup..." && rm -rf $(TARGET) && rm -rf $(UI)/build
1226

1327
.PHONY:check-go
1428
check-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
2132
check-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
5361
build-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
5865
go-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
6369
build-wasm: copy-wasm-exec build-webworker go-repl

build/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ COPY go.sum .
2121
ARG APP_VERSION=1.0.0
2222
RUN echo "Building server with version $APP_VERSION" && \
2323
go build -o server -ldflags="-X 'main.Version=$APP_VERSION'" ./cmd/playground && \
24-
GOOS=js GOARCH=wasm go build -o ./go-repl.wasm ./cmd/go-repl && \
25-
GOOS=js GOARCH=wasm go build -o ./worker.wasm ./cmd/webworker && \
24+
GOOS=js GOARCH=wasm go build -ldflags "-s -w" -trimpath -o ./go-repl.wasm ./cmd/go-repl && \
25+
GOOS=js GOARCH=wasm go build -ldflags "-s -w" -trimpath -o ./worker.wasm ./cmd/webworker && \
2626
cp $(go env GOROOT)/misc/wasm/wasm_exec.js .
2727

2828
FROM golang:1.19-alpine as production

build/release.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ COPY go.sum .
1717
ARG APP_VERSION=1.0.0
1818
RUN echo "Building server with version $APP_VERSION" && \
1919
go build -o server -ldflags="-X 'main.Version=$APP_VERSION'" ./cmd/playground && \
20-
GOOS=js GOARCH=wasm go build -o ./worker.wasm ./cmd/webworker && \
21-
GOOS=js GOARCH=wasm go build -o ./go-repl.wasm ./cmd/go-repl && \
20+
GOOS=js GOARCH=wasm go build -ldflags "-s -w" -trimpath -o ./worker.wasm ./cmd/webworker && \
21+
GOOS=js GOARCH=wasm go build -ldflags "-s -w" -trimpath -o ./go-repl.wasm ./cmd/go-repl && \
2222
cp $(go env GOROOT)/misc/wasm/wasm_exec.js .
2323

2424
FROM golang:1.19-alpine as production

0 commit comments

Comments
 (0)