1
0

Makefile 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. NEBULA_CMD_PATH = "./cmd/nebula"
  2. CGO_ENABLED = 0
  3. export CGO_ENABLED
  4. # Set up OS specific bits
  5. ifeq ($(OS),Windows_NT)
  6. NEBULA_CMD_SUFFIX = .exe
  7. NULL_FILE = nul
  8. # RIO on windows does pointer stuff that makes go vet angry
  9. VET_FLAGS = -unsafeptr=false
  10. else
  11. NEBULA_CMD_SUFFIX =
  12. NULL_FILE = /dev/null
  13. endif
  14. # Only defined the build number if we haven't already
  15. ifndef BUILD_NUMBER
  16. ifeq ($(shell git describe --exact-match 2>$(NULL_FILE)),)
  17. BUILD_NUMBER = $(shell git describe --abbrev=0 --match "v*" | cut -dv -f2)-$(shell git branch --show-current)-$(shell git describe --long --dirty | cut -d- -f2-)
  18. else
  19. BUILD_NUMBER = $(shell git describe --exact-match --dirty | cut -dv -f2)
  20. endif
  21. endif
  22. DOCKER_IMAGE_REPO ?= nebulaoss/nebula
  23. DOCKER_IMAGE_TAG ?= latest
  24. LDFLAGS = -X main.Build=$(BUILD_NUMBER)
  25. ALL_LINUX = linux-amd64 \
  26. linux-386 \
  27. linux-ppc64le \
  28. linux-arm-5 \
  29. linux-arm-6 \
  30. linux-arm-7 \
  31. linux-arm64 \
  32. linux-mips \
  33. linux-mipsle \
  34. linux-mips64 \
  35. linux-mips64le \
  36. linux-mips-softfloat \
  37. linux-riscv64 \
  38. linux-loong64
  39. ALL_FREEBSD = freebsd-amd64 \
  40. freebsd-arm64
  41. ALL_OPENBSD = openbsd-amd64 \
  42. openbsd-arm64
  43. ALL_NETBSD = netbsd-amd64 \
  44. netbsd-arm64
  45. ALL = $(ALL_LINUX) \
  46. $(ALL_FREEBSD) \
  47. $(ALL_OPENBSD) \
  48. $(ALL_NETBSD) \
  49. darwin-amd64 \
  50. darwin-arm64 \
  51. windows-amd64 \
  52. windows-arm64
  53. # Cross-build shards used by .github/workflows/test.yml — same as ALL_*
  54. # but with the arch that has a native CI runner removed, so the cross-build
  55. # job is not duplicating coverage the native test jobs already give.
  56. ALL_CROSS_LINUX = $(filter-out linux-amd64,$(ALL_LINUX))
  57. # ALL_CROSS_LINUX further split into family sub-shards so each can run on
  58. # its own CI runner in parallel. Union of the three must equal
  59. # ALL_CROSS_LINUX; adding a new linux arch goes into the matching family.
  60. ALL_CROSS_LINUX_ARM = linux-arm-5 linux-arm-6 linux-arm-7 linux-arm64
  61. ALL_CROSS_LINUX_MIPS = linux-mips linux-mipsle linux-mips64 linux-mips64le linux-mips-softfloat
  62. ALL_CROSS_LINUX_OTHER = linux-386 linux-ppc64le linux-riscv64 linux-loong64
  63. e2e:
  64. $(TEST_ENV) go test -tags=e2e_testing -count=1 $(TEST_FLAGS) ./e2e
  65. e2ev: TEST_FLAGS += -v
  66. e2ev: e2e
  67. e2evv: TEST_ENV += TEST_LOGS=1
  68. e2evv: e2ev
  69. e2evvv: TEST_ENV += TEST_LOGS=2
  70. e2evvv: e2ev
  71. e2evvvv: TEST_ENV += TEST_LOGS=3
  72. e2evvvv: e2ev
  73. e2e-bench: TEST_FLAGS = -bench=. -benchmem -run=^$
  74. e2e-bench: e2e
  75. DOCKER_BIN = build/linux-amd64/nebula build/linux-amd64/nebula-cert
  76. all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
  77. all-linux: $(ALL_LINUX:%=build/%/nebula) $(ALL_LINUX:%=build/%/nebula-cert)
  78. all-freebsd: $(ALL_FREEBSD:%=build/%/nebula) $(ALL_FREEBSD:%=build/%/nebula-cert)
  79. all-openbsd: $(ALL_OPENBSD:%=build/%/nebula) $(ALL_OPENBSD:%=build/%/nebula-cert)
  80. all-netbsd: $(ALL_NETBSD:%=build/%/nebula) $(ALL_NETBSD:%=build/%/nebula-cert)
  81. all-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert build/darwin-arm64/nebula build/darwin-arm64/nebula-cert
  82. all-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
  83. # CI cross-build shards. darwin-arm64 is covered by the native macos-latest
  84. # job; windows-amd64 is covered by the native windows-latest job; both are
  85. # omitted here to avoid building them a second time. darwin-amd64 stays in
  86. # all-cross-darwin because intel mac is only a labeled/master-time native
  87. # job, so PRs still need cross-build coverage for it.
  88. all-cross-linux: $(ALL_CROSS_LINUX:%=build/%/nebula) $(ALL_CROSS_LINUX:%=build/%/nebula-cert)
  89. all-cross-linux-arm: $(ALL_CROSS_LINUX_ARM:%=build/%/nebula) $(ALL_CROSS_LINUX_ARM:%=build/%/nebula-cert)
  90. all-cross-linux-mips: $(ALL_CROSS_LINUX_MIPS:%=build/%/nebula) $(ALL_CROSS_LINUX_MIPS:%=build/%/nebula-cert)
  91. all-cross-linux-other: $(ALL_CROSS_LINUX_OTHER:%=build/%/nebula) $(ALL_CROSS_LINUX_OTHER:%=build/%/nebula-cert)
  92. all-cross-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  93. all-cross-windows: build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
  94. docker: docker/linux-$(shell go env GOARCH)
  95. release: $(ALL:%=build/nebula-%.tar.gz)
  96. release-linux: $(ALL_LINUX:%=build/nebula-%.tar.gz)
  97. release-freebsd: $(ALL_FREEBSD:%=build/nebula-%.tar.gz)
  98. release-openbsd: $(ALL_OPENBSD:%=build/nebula-%.tar.gz)
  99. release-netbsd: $(ALL_NETBSD:%=build/nebula-%.tar.gz)
  100. release-boringcrypto: build/nebula-linux-$(shell go env GOARCH)-boringcrypto.tar.gz
  101. BUILD_ARGS += -trimpath
  102. bin-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe
  103. mv $? .
  104. bin-windows-arm64: build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
  105. mv $? .
  106. bin-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  107. mv $? .
  108. bin-freebsd: build/freebsd-amd64/nebula build/freebsd-amd64/nebula-cert
  109. mv $? .
  110. bin-freebsd-arm64: build/freebsd-arm64/nebula build/freebsd-arm64/nebula-cert
  111. mv $? .
  112. bin-boringcrypto: build/linux-$(shell go env GOARCH)-boringcrypto/nebula build/linux-$(shell go env GOARCH)-boringcrypto/nebula-cert
  113. mv $? .
  114. bin-pkcs11: BUILD_ARGS += -tags pkcs11
  115. bin-pkcs11: CGO_ENABLED = 1
  116. bin-pkcs11: bin
  117. bin:
  118. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula${NEBULA_CMD_SUFFIX} ${NEBULA_CMD_PATH}
  119. go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula-cert${NEBULA_CMD_SUFFIX} ./cmd/nebula-cert
  120. install:
  121. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  122. go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  123. build/linux-arm-%: GOENV += GOARM=$(word 3, $(subst -, ,$*))
  124. build/linux-mips-%: GOENV += GOMIPS=$(word 3, $(subst -, ,$*))
  125. # Build an extra small binary for mips-softfloat
  126. build/linux-mips-softfloat/%: LDFLAGS += -s -w
  127. # boringcrypto
  128. build/linux-amd64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
  129. build/linux-arm64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
  130. build/linux-amd64-boringcrypto/%: LDFLAGS += -checklinkname=0
  131. build/linux-arm64-boringcrypto/%: LDFLAGS += -checklinkname=0
  132. build/%/nebula: .FORCE
  133. GOOS=$(firstword $(subst -, , $*)) \
  134. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  135. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  136. build/%/nebula-cert: .FORCE
  137. GOOS=$(firstword $(subst -, , $*)) \
  138. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  139. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  140. build/%/nebula.exe: build/%/nebula
  141. mv $< $@
  142. build/%/nebula-cert.exe: build/%/nebula-cert
  143. mv $< $@
  144. build/nebula-%.tar.gz: build/%/nebula build/%/nebula-cert
  145. tar -zcv -C build/$* -f $@ nebula nebula-cert
  146. build/nebula-%.zip: build/%/nebula.exe build/%/nebula-cert.exe
  147. cd build/$* && zip ../nebula-$*.zip nebula.exe nebula-cert.exe
  148. docker/%: build/%/nebula build/%/nebula-cert
  149. docker build . $(DOCKER_BUILD_ARGS) -f docker/Dockerfile --platform "$(subst -,/,$*)" --tag "${DOCKER_IMAGE_REPO}:${DOCKER_IMAGE_TAG}" --tag "${DOCKER_IMAGE_REPO}:$(BUILD_NUMBER)"
  150. vet:
  151. go vet $(VET_FLAGS) -v ./...
  152. test:
  153. go test -v ./...
  154. test-boringcrypto:
  155. GOEXPERIMENT=boringcrypto CGO_ENABLED=1 go test -ldflags "-checklinkname=0" -v ./...
  156. test-pkcs11:
  157. CGO_ENABLED=1 go test -v -tags pkcs11 ./...
  158. test-cov-html:
  159. go test -coverprofile=coverage.out
  160. go tool cover -html=coverage.out
  161. build-test-mobile:
  162. GOARCH=amd64 GOOS=ios go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  163. GOARCH=arm64 GOOS=ios go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  164. GOARCH=amd64 GOOS=android go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  165. GOARCH=arm64 GOOS=android go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  166. bench:
  167. go test -bench=.
  168. bench-cpu:
  169. go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
  170. go tool pprof go-audit.test cpu.pprof
  171. bench-cpu-long:
  172. go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
  173. go tool pprof go-audit.test cpu.pprof
  174. proto: nebula.pb.go cert/cert_v1.pb.go
  175. nebula.pb.go: nebula.proto .FORCE
  176. go build github.com/gogo/protobuf/protoc-gen-gogofaster
  177. PATH="$(CURDIR):$(PATH)" protoc --gogofaster_out=paths=source_relative:. $<
  178. rm protoc-gen-gogofaster
  179. cert/cert.pb.go: cert/cert.proto .FORCE
  180. $(MAKE) -C cert cert.pb.go
  181. service:
  182. @echo > $(NULL_FILE)
  183. $(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
  184. ifeq ($(words $(MAKECMDGOALS)),1)
  185. @$(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
  186. endif
  187. bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
  188. smoke-docker: bin-docker
  189. cd .github/workflows/smoke/ && ./build.sh
  190. cd .github/workflows/smoke/ && ./smoke.sh
  191. cd .github/workflows/smoke/ && NAME="smoke-p256" CURVE="P256" ./build.sh
  192. cd .github/workflows/smoke/ && NAME="smoke-p256" ./smoke.sh
  193. smoke-relay-docker: bin-docker
  194. cd .github/workflows/smoke/ && ./build-relay.sh
  195. cd .github/workflows/smoke/ && ./smoke-relay.sh
  196. smoke-docker-race: BUILD_ARGS = -race
  197. smoke-docker-race: CGO_ENABLED = 1
  198. smoke-docker-race: smoke-docker
  199. smoke-vagrant/%: bin-docker build/%/nebula
  200. cd .github/workflows/smoke/ && ./build.sh $*
  201. cd .github/workflows/smoke/ && ./smoke-vagrant.sh $*
  202. .FORCE:
  203. .PHONY: all all-linux all-freebsd all-openbsd all-netbsd all-darwin all-windows all-cross-linux all-cross-linux-arm all-cross-linux-mips all-cross-linux-other all-cross-darwin all-cross-windows bench bench-cpu bench-cpu-long bin build-test-mobile e2e e2ev e2evv e2evvv e2evvvv proto release service smoke-docker smoke-docker-race test test-cov-html smoke-vagrant/%
  204. .DEFAULT_GOAL := bin