-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (115 loc) · 4.13 KB
/
Makefile
File metadata and controls
138 lines (115 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
.PHONY: all test test-coverage lint clean install release patch minor major
.PHONY: linux-x64 linux-arm64 darwin-x64 darwin-arm64 win32-x64 win32-arm64
.PHONY: docs docs-dev
BINARY_NAME := asimonim
DIST_DIR := dist/bin
GO_BUILD_FLAGS := -ldflags="$(shell scripts/ldflags.sh)"
# Extract version from goals if present (e.g., "make release v0.1.0" or "make release patch")
VERSION ?= $(filter v% patch minor major,$(MAKECMDGOALS))
# Optional path to release notes file for gh release create
RELEASE_NOTES ?=
# Workaround for Gentoo Linux "hole in findfunctab" error with race detector
# See: https://bugs.gentoo.org/961618
ifeq ($(shell test -f /etc/gentoo-release && echo yes),yes)
RACE_LDFLAGS := -ldflags="-linkmode=external"
else
RACE_LDFLAGS :=
endif
all:
@mkdir -p $(DIST_DIR)
go build $(GO_BUILD_FLAGS) -o $(DIST_DIR)/$(BINARY_NAME) .
docs:
hugo --source docs --gc --minify
docs-dev:
hugo server --source docs
install: all
cp $(DIST_DIR)/$(BINARY_NAME) ~/.local/bin/$(BINARY_NAME)
clean:
rm -rf $(DIST_DIR)/
go clean -cache -testcache
test:
go test -race $(RACE_LDFLAGS) ./...
COVERPKGS := $(shell go list ./... | grep -v '/testutil' | grep -v '/internal/mapfs' | grep -v '/internal/logger' | grep -v '/internal/version' | grep -v '/lsp/test/' | grep -vx 'bennypowers.dev/asimonim' | paste -sd, -)
test-coverage:
go test -race $(RACE_LDFLAGS) -coverprofile=coverage.out -coverpkg=$(COVERPKGS) ./...
lint:
go vet ./...
release:
@if [ -z "$(VERSION)" ]; then \
echo "Error: VERSION or bump type is required"; \
echo "Usage: make release <version|patch|minor|major>"; \
echo " make release v0.1.0 - Release explicit version"; \
echo " make release patch - Bump patch version (0.0.x)"; \
echo " make release minor - Bump minor version (0.x.0)"; \
echo " make release major - Bump major version (x.0.0)"; \
exit 1; \
fi
@RELEASE_NOTES="$(RELEASE_NOTES)" ./scripts/release.sh $(VERSION)
# Prevent make from treating version args as file targets
patch minor major:
@:
# Catch version tags like v0.1.0
v%:
@:
# Shared Windows cross-compilation image (from go-release-workflows)
SHARED_WINDOWS_CC_IMAGE := asimonim-shared-windows-cc
# Cross-compilation targets (CGO_ENABLED=1 required for tree-sitter)
linux-x64:
@mkdir -p $(DIST_DIR)
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
go build $(GO_BUILD_FLAGS) \
-o $(DIST_DIR)/$(BINARY_NAME)-linux-x64 .
linux-arm64:
@mkdir -p $(DIST_DIR)
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 \
CC=aarch64-linux-gnu-gcc \
go build $(GO_BUILD_FLAGS) \
-o $(DIST_DIR)/$(BINARY_NAME)-linux-arm64 .
darwin-x64:
@mkdir -p $(DIST_DIR)
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 \
CC="clang -arch x86_64" \
CGO_CFLAGS="-arch x86_64" CGO_LDFLAGS="-arch x86_64" \
go build $(GO_BUILD_FLAGS) \
-o $(DIST_DIR)/$(BINARY_NAME)-darwin-x64 .
darwin-arm64:
@mkdir -p $(DIST_DIR)
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 \
CC="clang -arch arm64" \
CGO_CFLAGS="-arch arm64" CGO_LDFLAGS="-arch arm64" \
go build $(GO_BUILD_FLAGS) \
-o $(DIST_DIR)/$(BINARY_NAME)-darwin-arm64 .
build-shared-windows-image:
@if ! podman image exists $(SHARED_WINDOWS_CC_IMAGE); then \
echo "Building shared Windows cross-compilation image..."; \
curl -fsSL https://raw.githubusercontent.com/bennypowers/go-release-workflows/main/.github/actions/setup-windows-build/Containerfile \
| podman build -t $(SHARED_WINDOWS_CC_IMAGE) -f - .; \
else \
echo "Image $(SHARED_WINDOWS_CC_IMAGE) already exists, skipping build."; \
fi
win32-x64: build-shared-windows-image
@mkdir -p $(DIST_DIR)
podman run --rm \
-v $(PWD):/src:Z \
-w /src \
-e GOOS=windows \
-e GOARCH=amd64 \
-e CGO_ENABLED=1 \
-e CC=x86_64-w64-mingw32-gcc \
-e CXX=x86_64-w64-mingw32-g++ \
$(SHARED_WINDOWS_CC_IMAGE) \
go build $(GO_BUILD_FLAGS) \
-o $(DIST_DIR)/$(BINARY_NAME)-win32-x64.exe .
win32-arm64: build-shared-windows-image
@mkdir -p $(DIST_DIR)
podman run --rm \
-v $(PWD):/src:Z \
-w /src \
-e GOOS=windows \
-e GOARCH=arm64 \
-e CGO_ENABLED=1 \
-e CC=aarch64-w64-mingw32-gcc \
-e CXX=aarch64-w64-mingw32-g++ \
$(SHARED_WINDOWS_CC_IMAGE) \
go build $(GO_BUILD_FLAGS) \
-o $(DIST_DIR)/$(BINARY_NAME)-win32-arm64.exe .