Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
216 lines (197 loc) · 11.2 KB
/
Copy pathMakefile
File metadata and controls
216 lines (197 loc) · 11.2 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# Local development: build the kernel jar, build rig, and run the test
# suites. The kernel, runner, and nREPL jars ship embedded in the rig
# binary: 'make rig' copies the built jars into internal/kernel/embed/
# and go:embed pulls them in. See README.md, "Local development".
#
# The embed jars are not committed: 'make embed' materializes
# rig/internal/kernel/embed/ — 0-byte placeholders for the kernel and
# runner jars, and the vendored nREPL jar fetched from Clojars at its
# pinned sha256. go:embed needs every file to exist, so a clean tree
# builds a placeholder rig that cannot run kernel ops. 'make kernel' then
# builds the resolver with the rig on PATH (a release binary, as
# 'lock-refresh' does); every later build self-hosts on dist/rig, which
# embeds the previous cycle's jars.
#
# V: version for the kernel jar and release artifacts, in release tag form
# (vX.Y.Z). Local dev defaults to the contents of resolver/VERSION (what
# the local tests look for). The kernel builds are stamped from that file
# (the rig build reads it), so V must equal it: 'make release' stamps it
# from the tag itself (the 'prepare' target), and the release workflow
# pushes that stamp to main after publishing.
V ?= $(shell cat resolver/VERSION 2>/dev/null || echo v0.1.0)
REPO := brutasse/rig
JAR := resolver/target/rig-resolver-$(V).jar
RUNNER := resolver/runner/target/rig-runner-$(V).jar
BIN := rig/dist/rig
RIG ?= rig
EMBED := rig/internal/kernel/embed
GITSHA ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo dev)
# The vendored nREPL jar, fetched from Clojars by 'embed' at its pinned
# sha256. A version bump moves the URL, the pin, and the embed filename
# (the //go:embed line, NreplVersion).
NREPL_URL := https://clojars.org/repo/nrepl/nrepl/1.8.0/nrepl-1.8.0.jar
NREPL_SHA := 8419c4aa7f56e2dfe6c1907dc18207c0177110c99d4d5d8742460f7efaeca1a8
# The rig that builds the kernel jars: the embedded one once a build has
# filled it, the release rig on PATH for the bootstrap of a clean tree.
KBOOT = $(shell test -s $(EMBED)/rig-resolver.jar && echo "$(abspath $(BIN))" || echo "$(RIG)")
.DEFAULT_GOAL := dev
# dev: the whole local story in one command.
dev: kernel rig
# embed: materialize $(EMBED)/ on this tree — the jars are build inputs of
# the go build, not source. The kernel and runner jars are 0-byte
# placeholders until 'make kernel' produces the real ones ('make rig' then
# copies them over); the vendored nREPL jar is fetched from Clojars and
# verified against its pin. Idempotent: existing files are never touched
# or overwritten.
embed:
@mkdir -p $(EMBED)
@test -s $(EMBED)/nrepl-1.8.0.jar || curl -fsSL $(NREPL_URL) -o $(EMBED)/nrepl-1.8.0.jar
@echo "$(NREPL_SHA) $(EMBED)/nrepl-1.8.0.jar" | sha256sum -c --status
@touch $(EMBED)/rig-resolver.jar $(EMBED)/rig-runner.jar
# kernel: build the resolver uberjar and the runner uberjar
# (resolver/target/ and resolver/runner/target/) with the rig selected by
# KBOOT — the previous cycle's dist/rig once it embeds the jars, the rig on
# PATH for the bootstrap of a clean tree. The builder's op shapes the
# artifact, so an op fix must be
# released before it can shape its successor's build (v0.3.0 shipped the
# link-closure fix precisely so it could build what comes next). The jar
# version comes from resolver/VERSION (rig's version-file), so V must
# match it; 'make release' stamps VERSION from the tag first ('prepare').
# The lock is a build input: rig build fails (exit 3) when it is stale, so
# a dependency bump that skipped 'rig lock' fails here instead of building
# green and leaving the drift uncommitted.
# No 'rig' prerequisite: KBOOT is computed at recipe time, and 'dev' runs
# the rig target after this one, embedding the jars it just built.
kernel:
@test "$$(cat resolver/VERSION)" = "$(V)" || { \
echo "resolver/VERSION ($$(cat resolver/VERSION)) != V ($(V)): run 'make prepare V=$(V)'" >&2; exit 1; }
cd resolver && $(KBOOT) build --uber
cd resolver && $(KBOOT) build -p runner --uber
# rig: build the rig binary (rig/dist/rig) with the local kernel jars
# embedded (a clean tree embeds the placeholders until 'make kernel'
# produces the first real jars; 'make dev' runs both in order).
rig: embed
test ! -f $(JAR) || cp $(JAR) $(EMBED)/rig-resolver.jar
test ! -f $(RUNNER) || cp $(RUNNER) $(EMBED)/rig-runner.jar
cd rig && go build -o dist/rig ./cmd/rig
# lock-refresh: re-bake resolver/deps.lock from the manifests. One 'rig lock'
# at the workspace root covers every module of the workspace — it rewrites the
# root and the runner module in the same file, so there is no '-p runner'
# variant and no second lock. It runs the rig on PATH, not a build of these
# sources: the lock records which rig wrote it, and the CI re-lock on
# renovate/* branches should stamp a release there, not a dev build of the
# branch it is fixing.
lock-refresh:
cd resolver && $(RIG) lock
# check: rig's own workspace against its own lock. Stage 1 re-hashes every
# locked artifact (a mismatch exits 4). Stage 2 is the kernel consistency
# report (conflicts, drift, floating versions, unknown repos) and names a
# stale manifest (the build already refuses a stale lock; check reports
# it). Stage 3 loads and compiles every module's namespaces.
check: dev
cd resolver && $(abspath $(BIN)) check
# test: full local verification — rig check on this workspace, the kernel
# suite (rig test: the runner runs the :test alias's exec-fn on the locked
# test classpath, on the workspace's managed Temurin 8) + Go suite (E2E tests
# run against the just-built jars; the cli package runs under the race
# detector). No Clojure CLI, no host JDK: rig runs everything.
test: dev check
cd resolver && CLOJURE_CLI_ALLOW_HTTP_REPO=1 $(abspath $(BIN)) test
cd rig && RIG_TEST_KERNEL_JAR=$(abspath $(JAR)) RIG_TEST_RUNNER_JAR=$(abspath $(RUNNER)) \
go test -race ./internal/cli/
cd rig && RIG_TEST_KERNEL_JAR=$(abspath $(JAR)) RIG_TEST_RUNNER_JAR=$(abspath $(RUNNER)) \
go test $(shell cd rig && go list ./... | grep -v 'internal/cli$$')
# fixture-pins: keep the Go suite's fixture pin set
# (rig/internal/cli/testdata/pins.json) in sync with upstream — by default
# it verifies every pinned artifact byte against its sha256, and
# ADD=group/name:version resolves a new coordinate's closure into the set
# (run it when a test fixture's pinned versions change).
fixture-pins:
scripts/sync-testdata-pins $(if $(ADD),--add $(ADD))
# test-pier: Pier E2E — rig lock/publish/check against a live OIDC-gated
# Maven repo. The Pier test env must be running (see the checkout's .scratch:
# fake OIDC issuer on :8090, pier on :8089, S3 on :9000).
# Usage: make test-pier PIER=/path/to/pier-checkout
PIER ?= $(HOME)/code/brutasse/rig-s3
test-pier: embed
cd rig && RIG_TEST_PIER=$(abspath $(PIER)) RIG_TEST_KERNEL_JAR=$(abspath $(JAR)) \
RIG_TEST_RUNNER_JAR=$(abspath $(RUNNER)) \
go test -count=1 -v -run 'TestPier' ./internal/cli/
# test-native: native-image E2E — builds the testdata/native fixture into a
# GraalVM native binary and runs it. GRAALVM must point at a GraalVM home
# (bin/native-image); the target fails with a hint when it is unset.
# Usage: make test-native GRAALVM=/opt/graalvm
GRAALVM ?=
test-native: embed
@test -n "$(GRAALVM)" || { echo "set GRAALVM=/path/to/graalvm"; exit 1; }
cd rig && RIG_TEST_GRAALVM=$(abspath $(GRAALVM)) RIG_TEST_KERNEL_JAR=$(abspath $(JAR)) \
go test -count=1 -v -timeout 30m -run 'TestHotBuildNative' ./internal/cli/
# run: execute the locally built rig in a workspace.
# Usage: make run WS=<workspace-dir> ARGS="lock"
run:
@test -f $(JAR) && test -f $(RUNNER) && test -f $(BIN) \
|| { echo "make dev first (missing kernel jar, runner jar, or rig binary)"; exit 1; }
cd $(or $(WS),.) && RIG_KERNEL_JAR=$(abspath $(JAR)) RIG_RUNNER_JAR=$(abspath $(RUNNER)) $(abspath $(BIN)) $(ARGS)
# prepare: stamp V into the version file and re-bake the lock, so the
# module version snapshot and the jar names follow the tag. 'release' runs
# it first: pushing a tag is the whole release ceremony, no prepare-release
# commit. The rig on PATH writes the lock (a release build, per
# lock-refresh). The kernel gate stays strict: a dev build whose VERSION
# drifted from the lock still fails.
prepare:
echo "$(V)" > resolver/VERSION
cd resolver && $(RIG) lock
# release: package a release — version stamp (prepare), kernel jar, runner
# jar, cross-compiled binaries with the jars and version stamps embedded,
# SHA256SUMS — in rig/dist/release/. The release workflow publishes that
# directory and lands the version stamp on main; locally it doubles as a
# packaging dry-run (clean the worktree afterwards: VERSION, deps.lock).
# The kernel and runner jars are still published as release assets: older
# rig binaries (pre-embedding) fetch them at runtime.
# Usage: make release V=vX.Y.Z
release: prepare kernel release-binaries
mkdir -p rig/dist/release
cp rig/dist/rig-linux-amd64 rig/dist/rig-linux-arm64 rig/dist/rig-darwin-amd64 rig/dist/rig-darwin-arm64 rig/dist/release/
cp $(JAR) rig/dist/release/
cp $(RUNNER) rig/dist/release/
cd rig/dist/release && sha256sum rig-linux-amd64 rig-linux-arm64 rig-darwin-amd64 rig-darwin-arm64 rig-resolver-$(V).jar rig-runner-$(V).jar > SHA256SUMS
@echo "release artifacts in rig/dist/release/ — publish with:"
@echo " (cd rig/dist/release && sha256sum -c SHA256SUMS) && gh release create $(V) rig/dist/release/*"
# release-binaries: cross-compile rig for the release matrix with version
# stamps (cli and kernel identity via ldflags; the kernel build ran first,
# so the embedded jars are the ones built from this tag). Each artifact is
# checked against its declared architecture: a wrong-arch binary would be
# packaged silently and break the cross-arch Docker build.
release-binaries: embed
test ! -f $(JAR) || cp $(JAR) $(EMBED)/rig-resolver.jar
test ! -f $(RUNNER) || cp $(RUNNER) $(EMBED)/rig-runner.jar
@for t in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64; do \
os=$${t%%/*}; arch=$${t#*/}; \
(cd rig && GOOS=$$os GOARCH=$$arch go build -trimpath \
-ldflags "-s -w -X github.com/brutasse/rig/internal/cli.Version=$(V) -X github.com/brutasse/rig/internal/cli.GitSHA=$(GITSHA) -X github.com/brutasse/rig/internal/kernel.Version=$(V) -X github.com/brutasse/rig/internal/kernel.GitSHA=$(GITSHA)" \
-o dist/rig-$$os-$$arch ./cmd/rig) || exit 1; \
case "$$t" in \
linux/amd64) want=x86-64 ;; \
linux/arm64) want=aarch64 ;; \
darwin/amd64) want=x86_64 ;; \
darwin/arm64) want=arm64 ;; \
esac; \
file rig/dist/rig-$$os-$$arch | grep -q "$$want" \
|| { echo "release-binaries: rig-$$os-$$arch: wrong architecture (want $$want)" >&2; file rig/dist/rig-$$os-$$arch >&2; exit 1; } \
done
IMAGE ?= ghcr.io/brutasse/rig
# image: build the Docker image locally (no push) from the release artifacts.
# The rig binary embeds its kernel/runner/nREPL jars, and the image
# pre-materializes them into the store at build time: no first-run extract.
# Usage: make image # tags $(IMAGE):local
image: release
arch=$$(uname -m); \
case "$$arch" in \
x86_64) arch=amd64 ;; \
aarch64) arch=arm64 ;; \
*) echo "unsupported arch: $$arch" >&2; exit 1 ;; \
esac; \
docker build \
--build-arg TARGETARCH=$$arch \
-t $(IMAGE):local .
.PHONY: dev embed kernel lock-refresh prepare rig check test test-pier fixture-pins run release release-binaries image