Skip to content

Commit 350de08

Browse files
authored
fix: build on mac (#6)
1 parent 8c09273 commit 350de08

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

Makefile

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
include embedded-bins/Makefile.variables
44
include inttest/Makefile.variables
55

6+
ARCH ?= $(shell go env GOARCH)
7+
68
BIN_DIR := $(shell pwd)/bin
79
export PATH := $(BIN_DIR):$(PATH)
810

@@ -14,7 +16,15 @@ help: ## Display this help
1416

1517
##@ Build
1618

17-
GO_TAGS = -tags=''
19+
# runs on linux even if it's built on mac or windows
20+
TARGET_OS ?= linux
21+
BUILD_GO_FLAGS := -tags osusergo
22+
BUILD_GO_FLAGS += -asmflags "all=-trimpath=$(shell dirname $(PWD))"
23+
BUILD_GO_FLAGS += -gcflags "all=-trimpath=$(shell dirname $(PWD))"
24+
LD_FLAGS := -X main.goos=$(shell go env GOOS)
25+
LD_FLAGS += -X main.goarch=$(shell go env GOARCH)
26+
LD_FLAGS += -X main.gitCommit=$(shell git rev-parse HEAD)
27+
LD_FLAGS += -X main.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
1828

1929
GO_SRCS := $(shell find . -type f -name '*.go' -not -name '*_test.go' -not -name 'zz_generated*')
2030

@@ -31,44 +41,39 @@ clean: ## Clean the bin directory
3141
.PHONY: build
3242
build: static bin/helmbin ## Build helmbin binaries
3343

34-
GO_ASMFLAGS = -asmflags "all=-trimpath=$(shell dirname $(PWD))"
35-
GO_GCFLAGS = -gcflags "all=-trimpath=$(shell dirname $(PWD))"
36-
LD_FLAGS = -ldflags " \
37-
-X main.goos=$(shell go env GOOS) \
38-
-X main.goarch=$(shell go env GOARCH) \
39-
-X main.gitCommit=$(shell git rev-parse HEAD) \
40-
-X main.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
41-
"
42-
BIN = bin/helmbin
44+
bin/helmbin: BIN = bin/helmbin
45+
bin/helmbin: TARGET_OS = linux
46+
bin/helmbin: BUILD_GO_CGO_ENABLED = 0
4347
bin/helmbin: $(GO_SRCS) go.sum
4448
@mkdir -p bin
45-
CGO_ENABLED=0 go build $(GO_GCFLAGS) $(GO_ASMFLAGS) $(LD_FLAGS) $(GO_TAGS) -o $(BIN) ./cmd/helmbin
49+
CGO_ENABLED=$(BUILD_GO_CGO_ENABLED) GOOS=$(TARGET_OS) go build $(BUILD_GO_FLAGS) -ldflags='$(LD_FLAGS)' -o $(BIN) ./cmd/helmbin
4650

4751
static: static/bin/k0s static/helm/000-admin-console-$(admin_console_version).tgz ## Build static assets
4852

4953
static/bin/k0s:
5054
@mkdir -p static/bin
51-
@curl -fsSL -o static/bin/k0s https://github.com/k0sproject/k0s/releases/download/$(k0s_version)/k0s-$(k0s_version)-amd64
55+
curl -fsSL -o static/bin/k0s https://github.com/k0sproject/k0s/releases/download/$(k0s_version)/k0s-$(k0s_version)-$(ARCH)
5256
chmod +x static/bin/k0s
5357

5458
static/helm/000-admin-console-$(admin_console_version).tgz: helm
5559
@mkdir -p static/helm
56-
@helm pull oci://registry.replicated.com/library/admin-console --version=$(admin_console_version)
60+
helm pull oci://registry.replicated.com/library/admin-console --version=$(admin_console_version)
5761
mv admin-console-$(admin_console_version).tgz static/helm/000-admin-console-$(admin_console_version).tgz
5862

5963
##@ Development
6064

6165
.PHONY: lint
62-
lint: golangci-lint ## Run golangci-lint linter
66+
lint: golangci-lint go.sum ## Run golangci-lint linter
6367
golangci-lint run
6468

6569
.PHONY: lint-fix
6670
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
6771
golangci-lint run --fix
6872

6973
.PHONY: test
70-
test: ## Run the unit tests
71-
go test $(GO_TAGS) -race -v ./pkg/...
74+
test: GO_TEST_RACE ?= -race
75+
test: go.sum ## Run the unit tests
76+
go test $(GO_TEST_RACE) -ldflags='$(LD_FLAGS)' -v ./pkg/...
7277

7378
.PHONY: $(smoketests)
7479
$(smoketests): build
@@ -82,10 +87,15 @@ GOLANGCI_LINT = $(BIN_DIR)/golangci-lint
8287
golangci-lint:
8388
@[ -f $(GOLANGCI_LINT) ] || { \
8489
set -e ;\
85-
curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT));\
90+
curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
91+
sh -s -- -b $(shell dirname $(GOLANGCI_LINT));\
8692
}
8793

8894
.PHONY: helm
8995
helm:
9096
@mkdir -p $(BIN_DIR)
91-
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | DESIRED_VERSION=v$(helm_version) HELM_INSTALL_DIR=$(BIN_DIR) bash
97+
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | \
98+
DESIRED_VERSION=v$(helm_version) HELM_INSTALL_DIR=$(BIN_DIR) USE_SUDO=false bash
99+
100+
go.sum: go.mod
101+
$(GO) mod tidy && touch -c -- '$@'

embedded-bins/Makefile.variables

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ admin_console_version = 1.99.0
33

44
alpine_version = 3.17
55
alpine_patch_version = $(alpine_version).3
6-
golang_buildimage=docker.io/library/golang:$(go_version)-alpine$(alpine_version)
76
go_version = 1.20.4
7+
golang_buildimage=docker.io/library/golang:$(go_version)-alpine$(alpine_version)
8+
89
kubernetes_version = 1.27.2
910
helm_version = 3.11.1
1011
etcd_version = 3.5.9

0 commit comments

Comments
 (0)