From c4e707be45a5874383022f65c416776628de20dc Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Thu, 29 Jan 2026 18:10:52 +1100 Subject: [PATCH] refactor: simplify just build --- CONTRIBUTING.md | 2 +- Justfile | 31 ++++++++++--------------------- docker/Justfile | 2 +- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9d7e9f6..d5c0d8d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,8 +19,8 @@ just docker run debug # Run with debug logging ```bash just build # Build for current platform -just build-linux # Build for Linux just build-all # Build all platforms +just build GOOS=linux GOARCH=amd64 # Build for linux/amd64 just test # Run tests just lint # Lint code just fmt # Format code diff --git a/Justfile b/Justfile index 58c7a85..c3cc711 100644 --- a/Justfile +++ b/Justfile @@ -10,6 +10,8 @@ VERSION := `git describe --tags --always --dirty 2>/dev/null || echo "dev"` GIT_COMMIT := `git rev-parse HEAD 2>/dev/null || echo "unknown"` TAG := `git rev-parse --short HEAD 2>/dev/null || echo "dev"` RELEASE := "dist" +GOARCH := env("GOARCH", `go env GOARCH`) +GOOS := env("GOOS", `go env GOOS`) _help: @just -l @@ -34,36 +36,23 @@ fmt: # ============================================================================ # Build for current platform -build: - @mkdir -p {{ RELEASE }} - @go build -trimpath -o {{ RELEASE }}/cachewd \ - -ldflags "-s -w -X main.version={{ VERSION }} -X main.gitCommit={{ GIT_COMMIT }}" \ - ./cmd/cachewd - @echo "✓ Built {{ RELEASE }}/cachewd" - -# Build for Linux (current arch) -build-linux: +build GOOS=(GOOS) GOARCH=(GOARCH): #!/usr/bin/env bash - set -e mkdir -p {{ RELEASE }} - ARCH=$(uname -m) - [[ "$ARCH" == "x86_64" ]] && ARCH="amd64" - [[ "$ARCH" == "aarch64" || "$ARCH" == "arm64" ]] && ARCH="arm64" - echo "Building for linux/${ARCH}..." - GOOS=linux GOARCH=${ARCH} go build -trimpath \ - -o {{ RELEASE }}/cachewd-linux-${ARCH} \ + go build -trimpath -o {{ RELEASE }}/cachewd-{{ GOOS }}-{{ GOARCH }} \ -ldflags "-s -w -X main.version={{ VERSION }} -X main.gitCommit={{ GIT_COMMIT }}" \ ./cmd/cachewd - echo "✓ Built {{ RELEASE }}/cachewd-linux-${ARCH}" + test "{{ GOOS }}-{{ GOARCH }}" = "$(go env GOOS)-$(go env GOARCH)" && (cd {{ RELEASE }} && ln -sf cachewd-{{ GOOS }}-{{ GOARCH }} cachewd) + echo "✓ Built {{ RELEASE }}/cachewd-{{ GOOS }}-{{ GOARCH }}" # Build all platforms build-all: @mkdir -p {{ RELEASE }} @echo "Building all platforms..." - @GOOS=darwin GOARCH=arm64 go build -trimpath -o {{ RELEASE }}/cachewd-darwin-arm64 -ldflags "-s -w -X main.version={{ VERSION }} -X main.gitCommit={{ GIT_COMMIT }}" ./cmd/cachewd - @GOOS=darwin GOARCH=amd64 go build -trimpath -o {{ RELEASE }}/cachewd-darwin-amd64 -ldflags "-s -w -X main.version={{ VERSION }} -X main.gitCommit={{ GIT_COMMIT }}" ./cmd/cachewd - @GOOS=linux GOARCH=arm64 go build -trimpath -o {{ RELEASE }}/cachewd-linux-arm64 -ldflags "-s -w -X main.version={{ VERSION }} -X main.gitCommit={{ GIT_COMMIT }}" ./cmd/cachewd - @GOOS=linux GOARCH=amd64 go build -trimpath -o {{ RELEASE }}/cachewd-linux-amd64 -ldflags "-s -w -X main.version={{ VERSION }} -X main.gitCommit={{ GIT_COMMIT }}" ./cmd/cachewd + just build darwin arm64 + just build darwin amd64 + just build linux arm64 + just build linux amd64 @echo "✓ Built all platforms" # ============================================================================ diff --git a/docker/Justfile b/docker/Justfile index d6e4704..cdb3252 100644 --- a/docker/Justfile +++ b/docker/Justfile @@ -2,7 +2,7 @@ set positional-arguments := true set shell := ["bash", "-c"] # Configuration -ROOT := `git rev-parse --show-toplevel 2>/dev/null || echo "."` +ROOT := `git rev-parse --show-toplevel 2>/dev/null || echo "."` TAG := `git rev-parse --short HEAD 2>/dev/null || echo "dev"` VERSION := `git describe --tags --always --dirty 2>/dev/null || echo "dev"` GIT_COMMIT := `git rev-parse HEAD 2>/dev/null || echo "unknown"`