-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
build.mk
88 lines (71 loc) · 2.33 KB
/
build.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
GO ?= go
YARN ?= yarn
GOROOT ?= $(shell $(GO) env GOROOT)
TOOLS ?= ./tools
PUBLIC_DIR ?= $(UI)/public
MIN_GO_VERSION ?= 1.23
WASM_API_VER ?= $(shell cat ./cmd/wasm/api-version.txt)
define build_wasm_worker
@echo ":: Building WebAssembly worker '$(1)' ..."
GOOS=js GOARCH=wasm $(GO) build -buildvcs=false -ldflags "-s -w" -trimpath \
$(2) -o $(PUBLIC_DIR)/wasm/$(1)@$(WASM_API_VER).wasm ./cmd/wasm/$(1)
endef
define check_tool
@if ! command -v $(1) >/dev/null 2>&1 ; then\
echo "ERROR: '$(1)' binary not found. Please ensure that tool is installed or specify binary path with '$(2)' variable." && \
exit 1; \
fi;
endef
.PHONY: clean
clean:
@echo ":: Cleanup..." && rm -rf $(TARGET) && rm -rf $(UI)/build
.PHONY:check-go
check-go:
$(call check_tool,$(GO),'GO')
@if [ "$$(printf '%s\n' "$$($(GO) version)" $(MIN_GO_VERSION) | sort -V | head -n1)" != "1.21" ]; then \
echo "Error: Go version should be $(MIN_GO_VERSION) or above"; \
exit 1; \
fi
.PHONY: imports-index
imports-index:
@echo ":: Generating Go imports index..." && \
$(GO) run ./tools/pkgindexer imports -o $(UI)/public/data/imports.json $(OPTS)
.PHONY: go-index
go-index:
@echo ":: Generating Go symbols index..." && \
$(GO) run ./tools/pkgindexer index -o $(UI)/public/data/go-index.json $(OPTS)
.PHONY:check-yarn
check-yarn:
$(call check_tool,$(YARN),'YARN')
.PHONY:preinstall
preinstall:
@echo ":: Checking and installing dependencies..." && \
$(YARN) --cwd="$(UI)" install --silent
.PHONY:build-server
build-server:
@echo ":: Building server..." && \
$(GO) build -o $(TARGET)/playground $(PKG)
.PHONY:build-ui
build-ui:
@echo ":: Building UI..." && \
$(YARN) --cwd="$(UI)" build
.PHONY: wasm_exec.js
wasm_exec.js:
@cp "$(GOROOT)/misc/wasm/wasm_exec.js" $(UI)/src/lib/go/wasm_exec.js
.PHONY:build-webworker
analyzer.wasm:
$(call build_wasm_worker,analyzer)
.PHONY:wasm
wasm: wasm_exec.js analyzer.wasm
.PHONY: build
build: check-go check-yarn clean preinstall gen build-server wasm go-index imports-index build-ui
@echo ":: Copying assets..." && \
cp -rfv ./data $(TARGET)/data && \
mv -v $(UI)/build $(TARGET)/public && \
echo ":: Build done - $(TARGET)"
# WASM and generated JSON files are build on CI outside of Docker to speedup build.
.PHONY: ci-assets
ci-assets: wasm go-index imports-index
.PHONY:gen
gen:
@find . -name 'generate.go' -exec go generate -v {} \;