build for multiple platforms only in CI, add s390x
Developers should not be forced to build for all platforms by default. We also don't want to copy-and-paste the go invocation for each new platform. To address both, the target platform(s) are now configurable via BUILD_PLATFORMS and additional platforms are only enabled in the Prow CI. For now this serves as a test that the source actually compiles for multiple platforms. Building images for different target platforms is a different problem.
This commit is contained in:
21
build.make
21
build.make
@@ -60,18 +60,25 @@ else
|
||||
TESTARGS =
|
||||
endif
|
||||
|
||||
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
|
||||
|
||||
# Specific packages can be excluded from each of the tests below by setting the *_FILTER_CMD variables
|
||||
# to something like "| grep -v 'github.com/kubernetes-csi/project/pkg/foobar'". See usage below.
|
||||
|
||||
# BUILD_PLATFORMS contains a set of <os> <arch> <suffix> triplets,
|
||||
# separated by semicolon. An empty variable or empty entry (= just a
|
||||
# semicolon) builds for the default platform of the current Go
|
||||
# toolchain.
|
||||
BUILD_PLATFORMS =
|
||||
|
||||
# This builds each command (= the sub-directories of ./cmd) for the target platform(s)
|
||||
# defined by BUILD_PLATFORMS.
|
||||
build-%: check-go-version-go
|
||||
mkdir -p bin
|
||||
CGO_ENABLED=0 GOOS=linux go build $(GOFLAGS_VENDOR) -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$* ./cmd/$*
|
||||
if [ "$$ARCH" = "amd64" ]; then \
|
||||
CGO_ENABLED=0 GOOS=windows go build $(GOFLAGS_VENDOR) -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$*.exe ./cmd/$* ; \
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build $(GOFLAGS_VENDOR) -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$*-ppc64le ./cmd/$* ; \
|
||||
fi
|
||||
echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch suffix; do \
|
||||
if ! (set -x; CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o "./bin/$*$$suffix" ./cmd/$*); then \
|
||||
echo "Building $* for GOOS=$$os GOARCH=$$arch failed, see error(s) above."; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
done
|
||||
|
||||
container-%: build-%
|
||||
docker build -t $*:latest -f $(shell if [ -e ./cmd/$*/Dockerfile ]; then echo ./cmd/$*/Dockerfile; else echo Dockerfile; fi) --label revision=$(REV) .
|
||||
|
Reference in New Issue
Block a user