1
0

Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. # Based on section 2.2 of the Go Cryptographic Module CVMP Security Policy #5247
  64. ALL_FIPS140 = linux-amd64-fips140 \
  65. linux-arm64-fips140 \
  66. windows-amd64-fips140 \
  67. windows-arm64-fips140 \
  68. darwin-arm64-fips140 \
  69. freebsd-amd64-fips140 \
  70. linux-arm-7-fips140 \
  71. linux-mips64-fips140 \
  72. linux-ppc64le-fips140
  73. e2e:
  74. $(TEST_ENV) go test -tags=e2e_testing -count=1 $(TEST_FLAGS) ./e2e
  75. e2ev: TEST_FLAGS += -v
  76. e2ev: e2e
  77. e2evv: TEST_ENV += TEST_LOGS=1
  78. e2evv: e2ev
  79. e2evvv: TEST_ENV += TEST_LOGS=2
  80. e2evvv: e2ev
  81. e2evvvv: TEST_ENV += TEST_LOGS=3
  82. e2evvvv: e2ev
  83. e2e-bench: TEST_FLAGS = -bench=. -benchmem -run=^$
  84. e2e-bench: e2e
  85. DOCKER_BIN = build/linux-amd64/nebula build/linux-amd64/nebula-cert
  86. all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
  87. all-linux: $(ALL_LINUX:%=build/%/nebula) $(ALL_LINUX:%=build/%/nebula-cert)
  88. all-freebsd: $(ALL_FREEBSD:%=build/%/nebula) $(ALL_FREEBSD:%=build/%/nebula-cert)
  89. all-openbsd: $(ALL_OPENBSD:%=build/%/nebula) $(ALL_OPENBSD:%=build/%/nebula-cert)
  90. all-netbsd: $(ALL_NETBSD:%=build/%/nebula) $(ALL_NETBSD:%=build/%/nebula-cert)
  91. all-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert build/darwin-arm64/nebula build/darwin-arm64/nebula-cert
  92. all-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
  93. # CI cross-build shards. darwin-arm64 is covered by the native macos-latest
  94. # job; windows-amd64 is covered by the native windows-latest job; both are
  95. # omitted here to avoid building them a second time. darwin-amd64 stays in
  96. # all-cross-darwin because intel mac is only a labeled/master-time native
  97. # job, so PRs still need cross-build coverage for it.
  98. all-cross-linux: $(ALL_CROSS_LINUX:%=build/%/nebula) $(ALL_CROSS_LINUX:%=build/%/nebula-cert)
  99. all-cross-linux-arm: $(ALL_CROSS_LINUX_ARM:%=build/%/nebula) $(ALL_CROSS_LINUX_ARM:%=build/%/nebula-cert)
  100. all-cross-linux-mips: $(ALL_CROSS_LINUX_MIPS:%=build/%/nebula) $(ALL_CROSS_LINUX_MIPS:%=build/%/nebula-cert)
  101. all-cross-linux-other: $(ALL_CROSS_LINUX_OTHER:%=build/%/nebula) $(ALL_CROSS_LINUX_OTHER:%=build/%/nebula-cert)
  102. all-cross-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  103. all-cross-windows: build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
  104. docker: docker/linux-$(shell go env GOARCH)
  105. release: $(ALL:%=build/nebula-%.tar.gz)
  106. release-linux: $(ALL_LINUX:%=build/nebula-%.tar.gz)
  107. release-freebsd: $(ALL_FREEBSD:%=build/nebula-%.tar.gz)
  108. release-openbsd: $(ALL_OPENBSD:%=build/nebula-%.tar.gz)
  109. release-netbsd: $(ALL_NETBSD:%=build/nebula-%.tar.gz)
  110. release-boringcrypto: build/nebula-linux-$(shell go env GOARCH)-boringcrypto.tar.gz
  111. release-fips140: $(ALL_FIPS140:%=build/nebula-%.tar.gz)
  112. BUILD_ARGS += -trimpath
  113. bin-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe
  114. mv $? .
  115. bin-windows-arm64: build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
  116. mv $? .
  117. bin-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
  118. mv $? .
  119. bin-freebsd: build/freebsd-amd64/nebula build/freebsd-amd64/nebula-cert
  120. mv $? .
  121. bin-freebsd-arm64: build/freebsd-arm64/nebula build/freebsd-arm64/nebula-cert
  122. mv $? .
  123. bin-boringcrypto: build/linux-$(shell go env GOARCH)-boringcrypto/nebula build/linux-$(shell go env GOARCH)-boringcrypto/nebula-cert
  124. mv $? .
  125. bin-fips140: build/linux-$(shell go env GOARCH)-fips140/nebula build/linux-$(shell go env GOARCH)-fips140/nebula-cert
  126. mv $? .
  127. bin-pkcs11: BUILD_ARGS += -tags pkcs11
  128. bin-pkcs11: CGO_ENABLED = 1
  129. bin-pkcs11: bin
  130. # Build with the pprof debug server (serves on :6060). See startPprofServer.
  131. debug: BUILD_ARGS += -tags debug
  132. debug: bin
  133. bin:
  134. $(GOENV) go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula${NEBULA_CMD_SUFFIX} ${NEBULA_CMD_PATH}
  135. $(GOENV) go build $(BUILD_ARGS) -ldflags "$(LDFLAGS)" -o ./nebula-cert${NEBULA_CMD_SUFFIX} ./cmd/nebula-cert
  136. install:
  137. $(GOENV) go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  138. $(GOENV) go install $(BUILD_ARGS) -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  139. build/linux-arm-%: GOENV += GOARM=$(word 3, $(subst -, ,$*))
  140. build/linux-mips-%: GOENV += GOMIPS=$(word 3, $(subst -, ,$*))
  141. # Build an extra small binary for mips-softfloat
  142. build/linux-mips-softfloat/%: LDFLAGS += -s -w
  143. # boringcrypto
  144. build/linux-amd64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
  145. build/linux-arm64-boringcrypto/%: GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1
  146. # fips140
  147. FIPSVERSION = v1.0.0
  148. $(foreach _rule, $(ALL_FIPS140), build/$(_rule)/%): GOENV += GOFIPS140=$(FIPSVERSION)
  149. $(foreach _rule, $(ALL_FIPS140), build/$(_rule)/%): BUILD_ARGS += -tags fips140enforce
  150. build/%/nebula: .FORCE
  151. GOOS=$(firstword $(subst -, , $*)) \
  152. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  153. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ${NEBULA_CMD_PATH}
  154. build/%/nebula-cert: .FORCE
  155. GOOS=$(firstword $(subst -, , $*)) \
  156. GOARCH=$(word 2, $(subst -, ,$*)) $(GOENV) \
  157. go build $(BUILD_ARGS) -o $@ -ldflags "$(LDFLAGS)" ./cmd/nebula-cert
  158. build/%/nebula.exe: build/%/nebula
  159. mv $< $@
  160. build/%/nebula-cert.exe: build/%/nebula-cert
  161. mv $< $@
  162. build/nebula-%.tar.gz: build/%/nebula build/%/nebula-cert
  163. tar -zcv -C build/$* -f $@ nebula nebula-cert
  164. build/nebula-%.zip: build/%/nebula.exe build/%/nebula-cert.exe
  165. cd build/$* && zip ../nebula-$*.zip nebula.exe nebula-cert.exe
  166. docker/%: build/%/nebula build/%/nebula-cert
  167. docker build . $(DOCKER_BUILD_ARGS) -f docker/Dockerfile --platform "$(subst -,/,$*)" --tag "${DOCKER_IMAGE_REPO}:${DOCKER_IMAGE_TAG}" --tag "${DOCKER_IMAGE_REPO}:$(BUILD_NUMBER)"
  168. vet:
  169. go vet $(VET_FLAGS) -v ./...
  170. test:
  171. $(TEST_ENV) go test $(TEST_FLAGS) -v ./...
  172. test-pkcs11:
  173. CGO_ENABLED=1 go test -v -tags pkcs11 ./...
  174. test-cov-html:
  175. go test -coverprofile=coverage.out
  176. go tool cover -html=coverage.out
  177. build-test-mobile:
  178. GOARCH=amd64 GOOS=ios go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  179. GOARCH=arm64 GOOS=ios go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  180. GOARCH=amd64 GOOS=android go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  181. GOARCH=arm64 GOOS=android go build $(shell go list ./... | grep -v '/cmd/\|/examples/')
  182. bench:
  183. go test -bench=.
  184. bench-cpu:
  185. go test -bench=. -benchtime=5s -cpuprofile=cpu.pprof
  186. go tool pprof go-audit.test cpu.pprof
  187. bench-cpu-long:
  188. go test -bench=. -benchtime=60s -cpuprofile=cpu.pprof
  189. go tool pprof go-audit.test cpu.pprof
  190. proto: nebula.pb.go cert/cert_v1.pb.go
  191. nebula.pb.go: nebula.proto .FORCE
  192. go build github.com/gogo/protobuf/protoc-gen-gogofaster
  193. PATH="$(CURDIR):$(PATH)" protoc --gogofaster_out=paths=source_relative:. $<
  194. rm protoc-gen-gogofaster
  195. cert/cert.pb.go: cert/cert.proto .FORCE
  196. $(MAKE) -C cert cert.pb.go
  197. service:
  198. @echo > $(NULL_FILE)
  199. $(eval NEBULA_CMD_PATH := "./cmd/nebula-service")
  200. ifeq ($(words $(MAKECMDGOALS)),1)
  201. @$(MAKE) service ${.DEFAULT_GOAL} --no-print-directory
  202. endif
  203. # Useful to chain together, like:
  204. # - make fips140 e2evv
  205. # - make fips140 smoke-docker
  206. # Use `release-fips140` to build release binaries
  207. fips140:
  208. @echo > $(NULL_FILE)
  209. ifeq ($(strip $(GOFIPS140)),)
  210. $(eval GOFIPS140 = $(FIPSVERSION))
  211. endif
  212. $(eval GOENV += GOFIPS140=$(GOFIPS140))
  213. $(eval BUILD_ARGS += -tags fips140enforce)
  214. $(eval TEST_ENV += $(GOENV))
  215. $(eval CURVE = P256)
  216. ifeq ($(words $(MAKECMDGOALS)),1)
  217. @$(MAKE) fips140 GOFIPS140=$(GOFIPS140) ${.DEFAULT_GOAL} --no-print-directory
  218. endif
  219. # To test the future pending module, use like `make fips140-latest test`
  220. ALL_GOFIPS140 = v1.0.0 v1.26.0 latest
  221. define FIPS140_rule
  222. fips140-$(1): GOFIPS140 = $(1)
  223. fips140-$(1): fips140
  224. endef
  225. $(foreach _rule, $(ALL_GOFIPS140), $(eval $(call FIPS140_rule,$(_rule))))
  226. # Iterate and run the goals for all fips versions, like `make fips140-all GOALS=test`
  227. fips140-all:
  228. @$(foreach _v,$(ALL_GOFIPS140),$(MAKE) fips140-$(_v) $(GOALS) &&) true
  229. # Useful to chain together, like:
  230. # - make boringcrypto e2evv
  231. # - make boringcrypto smoke-docker
  232. # Use `release-boringcrypto` or `bin-boringcrypto` to build release binaries
  233. boringcrypto:
  234. @echo > $(NULL_FILE)
  235. $(eval GOENV += GOEXPERIMENT=boringcrypto CGO_ENABLED=1)
  236. $(eval TEST_ENV += $(GOENV))
  237. $(eval CURVE = P256)
  238. ifeq ($(words $(MAKECMDGOALS)),1)
  239. @$(MAKE) boringcrypto ${.DEFAULT_GOAL} --no-print-directory
  240. endif
  241. bin-docker: bin build/linux-amd64/nebula build/linux-amd64/nebula-cert
  242. smoke-docker: BUILD_ARGS += -race
  243. smoke-docker: GOENV += CGO_ENABLED=1
  244. smoke-docker: bin-docker
  245. # This is so we can limit `fips140` smoke test to just P256 curve.
  246. if [ "$(CURVE)" != "P256" ]; then cd .github/workflows/smoke/ && $(GOENV) ./build.sh; fi
  247. if [ "$(CURVE)" != "P256" ]; then cd .github/workflows/smoke/ && $(GOENV) ./smoke.sh; fi
  248. cd .github/workflows/smoke/ && $(GOENV) NAME="smoke-p256" CURVE="P256" ./build.sh
  249. cd .github/workflows/smoke/ && $(GOENV) NAME="smoke-p256" ./smoke.sh
  250. smoke-relay-docker: BUILD_ARGS += -race
  251. smoke-relay-docker: GOENV += CGO_ENABLED=1
  252. smoke-relay-docker: bin-docker
  253. cd .github/workflows/smoke/ && $(GOENV) ./build-relay.sh
  254. cd .github/workflows/smoke/ && $(GOENV) ./smoke-relay.sh
  255. smoke-docker-ipv6: export SMOKE_OVERLAY_IPV6 = 1
  256. smoke-docker-ipv6: smoke-docker
  257. smoke-self: bin
  258. cd .github/workflows/smoke/ && ./smoke-self.sh
  259. smoke-vagrant/%: bin-docker build/%/nebula
  260. cd .github/workflows/smoke/ && ./build.sh $*
  261. cd .github/workflows/smoke/ && ./smoke-vagrant.sh $*
  262. .FORCE:
  263. .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 bin-windows bin-windows-arm64 bin-darwin bin-freebsd bin-freebsd-arm64 bin-boringcrypto bin-fips140 bin-pkcs11 bin-docker boringcrypto build-test-mobile debug docker e2e e2ev e2evv e2evvv e2evvvv e2e-bench fips140 fips140-all $(ALL_GOFIPS140:%=fips140-%) install proto release release-linux release-freebsd release-openbsd release-netbsd release-boringcrypto release-fips140 service smoke-docker smoke-relay-docker smoke-docker-ipv6 smoke-self test test-pkcs11 test-cov-html vet smoke-vagrant/%
  264. .DEFAULT_GOAL := bin