11.DEFAULT_GOAL := fast-build
22VERSION := dev-$(shell git rev-parse HEAD | cut -c 1-8)
33
4+ # Cross-compilation via Docker (golang:1.24 native Linux container).
5+ # When arch=<GOOS>/<GOARCH> is provided, spin up a container that matches
6+ # the target platform so CGO uses the native Linux gcc/GNU ld toolchain
7+ _GOMODCACHE := $(shell go env GOMODCACHE)
8+ ifdef arch
9+ _CROSS_GOOS := $(word 1,$(subst /, ,$(arch ) ) )
10+ _CROSS_GOARCH := $(word 2,$(subst /, ,$(arch ) ) )
11+ _BUILD_PREFIX := docker run --rm \
12+ --platform $(_CROSS_GOOS ) /$(_CROSS_GOARCH ) \
13+ -v $(CURDIR ) :/app \
14+ -v $(_GOMODCACHE ) :/go/pkg/mod \
15+ -e CGO_ENABLED=1 \
16+ -e GOPRIVATE=github.com/brevdev/* \
17+ -e GONOSUMDB=github.com/brevdev/* \
18+ -w /app \
19+ golang:1.24
20+ else
21+ _BUILD_PREFIX := CGO_ENABLED=1
22+ endif
23+
424.PHONY : fast-build
525fast-build : # # go build -o brev
626 $(call print-target)
727 echo ${VERSION}
8- CGO_ENABLED=0 go build -o brev -ldflags " -X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION} "
28+ CGO_ENABLED=1 go build -o brev -ldflags " -X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION} "
929
1030.PHONY : local
1131local : # # build with env wrapper (use: make local env=dev0|dev1|dev2|stg arch=linux/amd64, or make local for defaults)
1232 $(call print-target)
1333ifdef env
1434 @echo "Building with env=$(env) wrapper..."
1535 @echo ${VERSION}
16- $(if $(arch),GOOS=$(word 1,$(subst /, ,$(arch))) GOARCH=$(word 2,$(subst /, ,$(arch))),) CGO_ENABLED=0 go build -o brev-local -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}"
36+ $(_BUILD_PREFIX) go build -o brev-local -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}"
1737 @echo '# !/bin/sh' > brev
1838 @echo '# Auto-generated wrapper with environment overrides' >> brev
1939 @echo 'export BREV_CONSOLE_URL="https://localhost.nvidia.com:3000"' >> brev
@@ -26,7 +46,7 @@ ifdef env
2646 @chmod +x brev
2747else
2848 @echo "Building without environment overrides (using config.go defaults)..."
29- $(if $(arch),GOOS=$(word 1,$(subst /, ,$(arch))) GOARCH=$(word 2,$(subst /, ,$(arch))),) CGO_ENABLED=0 go build -o brev -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}"
49+ $(_BUILD_PREFIX) go build -o brev -ldflags "-X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION}"
3050endif
3151
3252.PHONY : install-dev
@@ -104,18 +124,42 @@ diff: ## git diff
104124 git diff --exit-code
105125 RES=$$(git status --porcelain ) ; if [ -n " $$ RES" ]; then echo $$ RES && exit 1 ; fi
106126
107- .PHONY : build
108- build : # # goreleaser --snapshot --skip-publish --rm-dist
109- build : install-tools
110- $(call print-target)
111- goreleaser --snapshot --skip-publish --rm-dist
112-
113127.PHONY : release
114128release : # # goreleaser --rm-dist
115129release : install-tools
116130 $(call print-target)
117131 goreleaser --rm-dist
118132
133+ # Docker-based build/release using goreleaser-cross.
134+ # See: https://goreleaser.com/limitations/cgo (goreleaser needs explicit instructions for CGO builds)
135+ # See: https://github.com/goreleaser/goreleaser-cross (docker image with cross-compilers for CGO builds)
136+ # See: https://github.com/goreleaser/example-cross (example of using goreleaser-cross)
137+ GOLANG_CROSS_VERSION ?= v1.24.5
138+ BREV_MODULE ?= github.com/brevdev/brev-cli
139+
140+ # Dry-run build using goreleaser-cross
141+ .PHONY : build-cross
142+ build-cross :
143+ $(call print-target)
144+ docker run --rm \
145+ -e CGO_ENABLED=1 \
146+ -v " $$ (pwd):/go/src/$( BREV_MODULE) " \
147+ -w " /go/src/$( BREV_MODULE) " \
148+ ghcr.io/goreleaser/goreleaser-cross:$(GOLANG_CROSS_VERSION ) \
149+ --clean --skip=validate --skip=publish
150+
151+ # Release using goreleaser-cross. Requires GITHUB_TOKEN to be set.
152+ .PHONY : release-cross
153+ release-cross :
154+ $(call print-target)
155+ docker run --rm \
156+ -e CGO_ENABLED=1 \
157+ -e " GITHUB_TOKEN=$$ GITHUB_TOKEN" \
158+ -v " $$ (pwd):/go/src/$( BREV_MODULE) " \
159+ -w " /go/src/$( BREV_MODULE) " \
160+ ghcr.io/goreleaser/goreleaser-cross:$(GOLANG_CROSS_VERSION ) \
161+ release --clean
162+
119163.PHONY : run
120164run : # # go run
121165 @go run -race .
@@ -169,7 +213,7 @@ full-smoke-test: ci fast-build
169213build-linux-amd :
170214 $(call print-target)
171215 echo ${VERSION}
172- GOOS=linux GOARCH=amd64 go build -o brev -ldflags " -X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION} "
216+ CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o brev -ldflags " -X github.com/brevdev/brev-cli/pkg/cmd/version.Version=${VERSION} "
173217
174218.PHONY : build-darwin-amd
175219build-darwin-amd :
@@ -305,8 +349,8 @@ develop-with-nix:
305349update-devplane-deps : # # update devplane dependencies (use: make update-devplane-deps commit=<hash-or-tag>, defaults to latest)
306350 @COMMIT=$$ {commit:-latest}; \
307351 echo " Updating devplane dependencies to: $$ COMMIT" ; \
308- go get -u github.com/brevdev/dev-plane@$$ COMMIT; \
352+ GOPRIVATE=github.com/brevdev/ * go get -u github.com/brevdev/dev-plane@$$ COMMIT; \
309353 go get buf.build/gen/go/brevdev/devplane/grpc/go@$$ COMMIT; \
310354 go get buf.build/gen/go/brevdev/devplane/protocolbuffers/go@$$ COMMIT; \
311- go mod tidy; \
355+ GOPRIVATE=github.com/brevdev/ * go mod tidy; \
312356 echo " Successfully updated to $$ COMMIT"
0 commit comments