| 1 | VERSION := $(shell git describe --tags --always 2>/dev/null || echo dev) |
| 2 | BUILD_TIME_UTC := $(shell date -u +%Y-%m-%dT%H:%M:%SZ) |
| 3 | GIT_COMMIT := $(shell git rev-parse --short=12 HEAD 2>/dev/null || echo unknown) |
| 4 | LDFLAGS := -s -w \ |
| 5 | -X main.version=$(VERSION) \ |
| 6 | -X main.gitCommit=$(GIT_COMMIT) \ |
| 7 | -X main.buildTimeUTC=$(BUILD_TIME_UTC) |
| 8 | GOEXE := $(shell go env GOEXE) |
| 9 | # One pin for the Makefile and the CI lint job; see .github/workflows/ci.yml. |
| 10 | GOLANGCI_VERSION := $(shell cat .golangci-version) |
| 11 | |
| 12 | .PHONY: build vet fmt lint lint-go lint-install lint-cross lint-update test desktop-test desktop-test-short desktop-test-times sdk-test sdk-test-race hooks cross clean |
| 13 | |
| 14 | build: |
| 15 | CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o bin/reasonix$(GOEXE) ./cmd/reasonix |
| 16 | CGO_ENABLED=0 go build -ldflags "$(LDFLAGS)" -o bin/reasonix-plugin-example$(GOEXE) ./cmd/reasonix-plugin-example |
| 17 | |
| 18 | vet: |
| 19 | go vet ./... |
| 20 | |
| 21 | fmt: |
| 22 | gofmt -w . |
| 23 | |
| 24 | # Both gates CI runs, at the version CI pins. Skipping golangci-lint locally |
| 25 | # trades a second here for a ten-minute CI round trip: `modernize` findings in |
| 26 | # particular never surface in `go vet`. |
| 27 | lint: lint-go |
| 28 | go run ./tools/repolint |
| 29 | |
| 30 | lint-go: |
| 31 | @command -v golangci-lint >/dev/null || { echo "golangci-lint not installed; run: make lint-install"; exit 1; } |
| 32 | @have=$$(golangci-lint version --short 2>/dev/null); want=$$(echo "$(GOLANGCI_VERSION)" | sed 's/^v//'); \ |
| 33 | [ "$$have" = "$$want" ] || echo "warning: local golangci-lint $$have, CI pins $$want (make lint-install)" |
| 34 | golangci-lint run --timeout=5m ./... |
| 35 | |
| 36 | # CGO_ENABLED=0 keeps the install working where a stray clang on PATH shadows |
| 37 | # the toolchain and breaks runtime/cgo. |
| 38 | lint-install: |
| 39 | CGO_ENABLED=0 go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_VERSION) |
| 40 | |
| 41 | lint-update: |
| 42 | go run ./tools/repolint -update |
| 43 | |
| 44 | # Linting one GOOS leaves every //go:build windows and darwin file unchecked. |
| 45 | lint-cross: |
| 46 | @for t in "linux ." "darwin ." "windows ." "linux desktop" "windows desktop"; do \ |
| 47 | set -- $$t; \ |
| 48 | echo "== golangci-lint GOOS=$$1 ($$2)"; \ |
| 49 | (cd $$2 && GOOS=$$1 golangci-lint run --timeout=5m ./...) || exit 1; \ |
| 50 | done |
| 51 | |
| 52 | test: |
| 53 | go test ./... |
| 54 | |
| 55 | desktop-test: |
| 56 | cd desktop && go test . |
| 57 | |
| 58 | desktop-test-short: |
| 59 | cd desktop && go test -short . |
| 60 | |
| 61 | desktop-test-times: |
| 62 | cd desktop && go test -count=1 -json . | python3 ../scripts/desktop-test-times.py |
| 63 | |
| 64 | sdk-test: |
| 65 | cd sdk/go && go test ./... |
| 66 | |
| 67 | sdk-test-race: |
| 68 | cd sdk/go && go test -race ./... |
| 69 | |
| 70 | hooks: |
| 71 | @git config core.hooksPath .githooks |
| 72 | @echo "installed: core.hooksPath -> .githooks (pre-push runs go vet)" |
| 73 | |
| 74 | cross: |
| 75 | @mkdir -p dist |
| 76 | @for p in darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 windows/amd64 windows/arm64; do \ |
| 77 | os=$${p%/*}; arch=$${p#*/}; ext=; [ $$os = windows ] && ext=.exe; \ |
| 78 | echo "build $$os/$$arch"; \ |
| 79 | CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -ldflags "$(LDFLAGS)" -o dist/reasonix-$$os-$$arch$$ext ./cmd/reasonix; \ |
| 80 | done |
| 81 | |
| 82 | clean: |
| 83 | rm -rf bin dist |
| 84 |