forked from elide-dev/elide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
487 lines (423 loc) · 14.9 KB
/
Makefile
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#
# Makefile: Elide
#
VERSION ?= $(shell cat .version)
STRICT ?= yes
RELOCK ?= no
SITE ?= no
DEFAULT_REPOSITORY ?= gcs://elide-snapshots/repository/v3
REPOSITORY ?= $(DEFAULT_REPOSITORY)
SAMPLES ?= no
SIGNING_KEY ?= F812016B
# Flags that control this makefile, along with their defaults:
#
# DEBUG ?= no
# STRICT ?= yes
# RELEASE ?= no
# JVMDEBUG ?= no
# NATIVE ?= no
# CI ?= no
# DRY ?= no
# SCAN ?= no
# IGNORE_ERRORS ?= no
# RELOCK ?= no
# SIGNING ?= no
# SIGNING_KEY ?= "F812016B"
GRADLE ?= ./gradlew
YARN ?= $(shell which yarn)
RM ?= $(shell which rm)
FIND ?= $(shell which find)
MKDIR ?= $(shell which mkdir)
CP ?= $(shell which cp)
RSYNC ?= $(shell which rsync)
UNZIP ?= $(shell which unzip)
TAR ?= $(shell which tar)
ZIP ?= $(shell which zip)
XZ ?= $(shell which xz)
ZSTD ?= $(shell which zstd)
BZIP2 ?= $(shell which bzip2)
GZIP ?= $(shell which gzip)
GPG2 ?= $(shell which gpg)
PWD ?= $(shell pwd)
TARGET ?= $(PWD)/build
DOCS ?= $(PWD)/docs
SITE_BUILD ?= $(PWD)/build/site
REPORTS ?= $(SITE_BUILD)/reports
JVM ?= 19
SYSTEM ?= $(shell uname -s)
JQ ?= $(shell which jq)
POSIX_FLAGS ?=
GRADLE_OPTS ?=
GRADLE_ARGS ?= -Pversions.java.language=$(JVM)
BUILD_ARGS ?=
NATIVE_TASKS ?= nativeCompile
DEP_HASH_ALGO ?= sha256,pgp
ARGS ?=
ifneq ($(REPOSITORY),$(DEFAULT_REPOSITORY))
PUBLISH_PROPS ?= -Pelide.publish.repo.maven.auth=true -Pelide.publish.repo.maven=$(REPOSITORY)
else
PUBLISH_PROPS ?=
endif
LOCAL_CLI_INSTALL_DIR ?= ~/bin
HASHSUM_SIZE ?= 256
HASHSUM_CLASS ?= sha
HASHSUM_ALGORITHM ?= $(HASHSUM_CLASS)$(HASHSUM_SIZE)
HASHSUM ?= shasum -a $(HASHSUM_SIZE)
ifeq ($(SAMPLES),yes)
BUILD_ARGS += -PbuildSamples=true
else
BUILD_ARGS += -PbuildSamples=false
endif
ifeq ($(SITE),yes)
BUILD_ARGS += -PbuildDocsSite=true
else
BUILD_ARGS += -PbuildDocsSite=false
endif
ifeq ($(RELOCK),yes)
BUILD_ARGS += --write-verification-metadata $(DEP_HASH_ALGO) --export-keys
endif
ifeq ($(CI),yes)
BUILD_ARGS += -Pelide.ci=true
endif
ifeq ($(STRICT),yes)
BUILD_ARGS += --warning-mode=none -Pelide.strict=true
endif
ifeq ($(SCAN),yes)
BUILD_ARGS += --scan
endif
ifeq ($(RELEASE),yes)
BUILD_MODE ?= release
NATIVE_TARGET_NAME ?= nativeOptimizedCompile
CLI_DISTPATH ?= ./packages/cli/build/dist/release
BUILD_ARGS += -Pelide.buildMode=prod -Pelide.stamp=true -Pelide.release=true -Pelide.strict=true
CLI_RELEASE_TARGETS ?= cli-local cli-release-artifacts
else
BUILD_MODE ?= dev
CLI_DISTPATH ?= ./packages/cli/build/dist/debug
NATIVE_TARGET_NAME ?= nativeCompile
CLI_RELEASE_TARGETS ?= cli-local
endif
ifeq ($(SIGNING),yes)
SIGNING_ON = true
else
SIGNING_ON = false
endif
OMIT_NATIVE ?= -x nativeCompile -x testNativeImage
ifneq ($(NATIVE),)
ifneq ($(NATIVE),no)
BUILD_ARGS += $(patsubst %,-d %,$(NATIVE_TASKS))
OMIT_NATIVE =
else
endif
endif
ifneq ($(VERBOSE),)
RULE ?=
POSIX_FLAGS +=v
GRADLE_LOGS ?= info
GRADLE_ARGS += --$(GRADLE_LOGS)
else
RULE ?= @
endif
ifeq ($(IGNORE_ERRORS),yes)
RULE += -
endif
ifeq ($(DRY),yes)
CMD ?= $(RULE)echo
CMD += " "
else
CMD ?= $(RULE)
endif
GRADLE_OMIT ?= $(OMIT_NATIVE)
_ARGS ?= $(GRADLE_ARGS) $(BUILD_ARGS) $(ARGS)
# ---- Targets ---- #
all: build test docs
build: ## Build the main library, and code-samples if SAMPLES=yes.
$(info Building Elide v3...)
$(CMD) $(GRADLE) build -x test -x check $(GRADLE_OMIT) $(_ARGS)
test: ## Run the library testsuite, and code-sample tests if SAMPLES=yes.
$(info Running testsuite...)
$(CMD)$(GRADLE) test $(_ARGS)
publish: ## Publish a new version of all Elide packages.
$(info Publishing packages for version "$(VERSION)"...)
$(CMD)$(GRADLE) \
:conventions:publish \
:substrate:compiler-util:publish \
:substrate:redakt:publish \
:substrate:injekt:publish \
:substrate:sekret:publish \
:substrate:interakt:publish \
:tools:processor:publish \
:packages:core:publish \
:packages:base:publish \
:packages:test:publish \
:packages:proto:proto-core:publish \
:packages:proto:proto-kotlinx:publish \
:packages:proto:proto-protobuf:publish \
:packages:proto:proto-flatbuffers:publish \
:packages:model:publish \
:packages:rpc:publish \
:packages:graalvm:publish \
:packages:graalvm-js:publish \
:packages:graalvm-react:publish \
:packages:ssr:publish \
:packages:server:publish \
:packages:ssg:publish \
:packages:platform:publish \
:packages:bom:publish \
:packages:cli:publish \
--no-daemon \
--warning-mode=none \
-Pversion=$(VERSION) \
-PbuildSamples=false \
-PbuildDocs=true \
-PbuildDocsSite=false \
-PenableSigning=$(SIGNING_ON) \
-Pelide.release=true \
-Pelide.buildMode=release \
$(PUBLISH_PROPS) \
-x test \
-x jvmTest \
-x jsTest;
clean-cli: ## Clean built CLI targets.
$(CMD)echo "Cleaning CLI targets..."
$(CMD)$(RM) -fr$(strip $(POSIX_FLAGS)) ./packages/cli/build/dist
cli: ## Build the Elide command-line tool (native target).
$(info Building Elide CLI tool...)
$(CMD)mkdir -p $(CLI_DISTPATH)
$(CMD)$(GRADLE) \
:packages:cli:$(NATIVE_TARGET_NAME) \
-Pversion=$(VERSION) \
-PbuildSamples=false \
-PbuildDocs=false \
-PbuildDocsSite=false \
-Pelide.buildMode=$(BUILD_MODE) \
-x test \
$(_ARGS);
$(CMD)$(MAKE) cli-distroot cli-sizereport
cli-distroot:
@echo "Built Elide CLI binary. Creating distroot..."
@$(MKDIR) -p $(CLI_DISTPATH) \
&& $(CP) ./packages/cli/build/native/$(NATIVE_TARGET_NAME)/elide $(CLI_DISTPATH)/elide;
$(CMD)cd $(CLI_DISTPATH) && du -h elide;
@echo "Compressing...";
$(CMD)cd $(CLI_DISTPATH) \
&& $(GZIP) --best --keep --verbose elide \
&& $(BZIP2) --best --keep --verbose elide \
&& $(XZ) --best --keep --verbose elide \
&& $(ZSTD) --ultra -22 -k -v elide \
&& $(ZIP) -9 --verbose elide.zip elide;
cli-sizereport:
@echo "\nSize report:" \
&& cd $(CLI_DISTPATH) && du -h elide* \
&& echo "\nChecksums:" \
&& $(HASHSUM) elide* \
&& echo "";
cli-local: cli ## Build the Elide command line tool and install it locally (into ~/bin, or LOCAL_CLI_INSTALL_DIR).
ifeq ($(RELEASE),yes)
$(CMD)$(MAKE) clean-cli
endif
$(CMD)$(MAKE) cli-install-local
cli-release-artifacts:
$(CMD)echo "Building release artifacts..." \
&& cd $(CLI_DISTPATH) \
&& $(HASHSUM) elide elide* > manifest.txt \
&& $(HASHSUM) elide | cut -d " " -f 1 > elide.$(HASHSUM_ALGORITHM) \
&& $(HASHSUM) elide.bz2 | cut -d " " -f 1 > elide.bz2.$(HASHSUM_ALGORITHM) \
&& $(HASHSUM) elide.gz | cut -d " " -f 1 > elide.gz.$(HASHSUM_ALGORITHM) \
&& $(HASHSUM) elide.xz | cut -d " " -f 1 > elide.xz.$(HASHSUM_ALGORITHM) \
&& $(HASHSUM) elide.zst | cut -d " " -f 1 > elide.xz.$(HASHSUM_ALGORITHM) \
&& $(HASHSUM) elide.zip | cut -d " " -f 1 > elide.zip.$(HASHSUM_ALGORITHM) \
&& $(HASHSUM) manifest.txt | cut -d " " -f 1 > manifest.txt.$(HASHSUM_ALGORITHM) \
&& $(TAR) -cvf elide.tar elide elide.sha256 $(SIGNATURE_FILE) \
&& $(GZIP) --best --verbose elide.tar;
ifeq ($(SIGNING),yes)
$(CMD)echo "Signing release artifacts..." \
&& cd $(CLI_DISTPATH) \
&& $(GPG2) --default-key "$(SIGNING_KEY)" --armor --detach-sign --output elide.asc elide;
else
@echo "Skipping signatures: signing is disabled.";
endif
$(CMD)echo "Building release descriptor..." \
&& $(HASHSUM) $(CLI_DISTPATH)/manifest.txt | cut -d " " -f 1 > $(CLI_DISTPATH)/manifest.txt.$(HASHSUM_ALGORITHM) \
&& MANIFEST_FINGERPRINT=$$(cat $(CLI_DISTPATH)/manifest.txt.$(HASHSUM_ALGORITHM)) \
&& RELEASE_SYSTEM=$$(echo "$(SYSTEM)" | tr A-Z a-z) \
&& RELEASE_ARCH=$$(uname -m | tr A-Z a-z) \
&& cat ./packages/cli/packaging/release.json | \
$(JQ) ".version = \"$(VERSION)\"" | \
$(JQ) ".platform = \"$${RELEASE_SYSTEM}\"" | \
$(JQ) ".fingerprint = \"$${MANIFEST_FINGERPRINT}\"" > $(CLI_DISTPATH)/release.json \
&& $(HASHSUM) $(CLI_DISTPATH)/release.json | cut -d " " -f 1 > $(CLI_DISTPATH)/release.json.$(HASHSUM_ALGORITHM) \
&& echo "Release manifest built for version '$(VERSION)'.";
ifeq ($(SIGNING),yes)
$(CMD)echo "Signing release descriptor..." \
&& cd $(CLI_DISTPATH) \
&& cat release.json.sha256 manifest.txt.sha256 | $(GPG2) --default-key "$(SIGNING_KEY)" --armor --detach-sign --output release.asc;
endif
$(CMD)echo "Building final release tarball..." \
&& cd $(CLI_DISTPATH) \
&& $(TAR) -cvf release.tar elide elide.* manifest.txt release.json;
cli-release: cli ## Build an Elide command-line release.
$(CMD)make $(CLI_RELEASE_TARGETS) RELEASE=yes
cli-install-local:
@echo "Installing CLI locally (location: \"$(LOCAL_CLI_INSTALL_DIR))\"..."
$(CMD)$(CP) -f$(strip $(POSIX_FLAGS)) \
./packages/cli/build/native/$(NATIVE_TARGET_NAME)/elide \
$(LOCAL_CLI_INSTALL_DIR)/elide
@echo ""; echo "Done. Testing CLI tool..."
$(CMD)elide --version
clean: clean-docs clean-site ## Clean build outputs and caches.
@echo "Cleaning targets..."
$(CMD)$(RM) -fr$(strip $(POSIX_FLAGS)) $(TARGET)
$(CMD)$(GRADLE) clean cleanTest $(_ARGS)
$(CMD)$(FIND) . -name .DS_Store -delete
clean-docs: ## Clean documentation targets.
@echo "Cleaning docs..."
$(CMD)$(RM) -fr$$(strip $(POSIX_FLAGS)) $(SITE_BUILD)/docs
clean-site: ## Clean site targets.
@echo "Cleaning site..."
$(CMD)$(RM) -fr$$(strip $(POSIX_FLAGS)) $(SITE_BUILD)
docs: $(DOCS) $(SITE_BUILD)/docs/kotlin $(SITE_BUILD)/docs/javadoc ## Generate docs for all library modules.
$(TARGET)/docs:
@echo "Generating docs..."
$(CMD)$(RM) -fr$(strip $(POSIX_FLAGS)) $(SITE_BUILD)/docs/kotlin $(SITE_BUILD)/docs/javadoc
$(CMD)$(GRADLE) docs $(_ARGS)
@echo "Docs build complete."
$(SITE_BUILD)/docs/kotlin $(SITE_BUILD)/docs/javadoc: $(TARGET)/docs
@echo "Assembling docs site..."
$(CMD)$(MKDIR) -p $(SITE_BUILD) $(SITE_BUILD)/docs/kotlin $(SITE_BUILD)/docs/javadoc
$(CMD)cd $(DOCS) \
&& $(RSYNC) -a$(strip $(POSIX_FLAGS)) --exclude="Makefile" --exclude="buf.work.yml" --exclude="README.md" "./" $(SITE_BUILD)/;
$(CMD)cd $(TARGET)/docs/kotlin/html \
&& $(RSYNC) -a$(strip $(POSIX_FLAGS)) ./* $(SITE_BUILD)/docs/kotlin/
$(CMD)cd packages/server/build/dokka \
&& $(MKDIR) $(SITE_BUILD)/docs/javadoc/server \
&& $(CP) -fr$(strip $(POSIX_FLAGS)) ./javadoc/* $(SITE_BUILD)/docs/javadoc/server/
@echo "Docs assemble complete."
api-check: ## Check API/ABI compatibility with current changes.
$(info Checking ABI compatibility...)
$(CMD)$(GRADLE) apiCheck -PbuildDocsSite=false -PbuildSamples=false -PbuildDocs=false
reports: $(REPORTS) ## Generate reports for tests, coverage, etc.
@$(RM) -f $(SITE_BUILD)/reports/project/properties.txt
$(REPORTS):
@echo "Generating reports..."
$(CMD)$(GRADLE) \
:reports \
:tools:reports:reports \
-x nativeCompile \
-x test \
-Pversions.java.language=$(JVM)
$(CMD)$(MKDIR) -p $(REPORTS)
@echo "Copying merged reports to '$(REPORTS)'..."
$(CMD)-cd $(TARGET)/reports && $(CP) -fr$(strip $(POSIX_FLAGS)) ./* $(REPORTS)/
@echo "Copying test reports to '$(REPORTS)'..."
$(CMD)$(MKDIR) -p tools/reports/build/reports
$(CMD)cd tools/reports/build/reports && $(CP) -fr$(strip $(POSIX_FLAGS)) ./* $(REPORTS)/
$(CMD)$(RM) -f docs/reports/project/properties.txt docs/reports/project/tasks.txt
@echo "Reports synced."
site-assets: $(SITE_BUILD)/creative
$(SITE_BUILD)/creative:
@echo "Copying site assets..."
$(CMD)$(MKDIR) -p $(SITE_BUILD)/creative/logo $(SITE_BUILD)/docs/kotlin/creative/logo/
$(CMD)cd creative/logo \
&& $(CP) -fr$(strip $(POSIX_FLAGS)) ./* $(SITE_BUILD)/creative/logo/ \
&& $(CP) -fr$(strip $(POSIX_FLAGS)) ./* $(SITE_BUILD)/docs/kotlin/creative/logo/
SITE_PKG_ZIP ?= $(PWD)/
site: docs reports site-assets site/docs/app/build site/docs/app/build/ssg-site.zip ## Generate the static Elide website.
@echo "Assembling Elide site..."
$(CMD)-$(UNZIP) -o -d $(SITE_BUILD) $(PWD)/site/docs/app/build/ssg-site.zip
site/docs/app/build:
@echo "Building Elide site..."
$(CMD)$(GRADLE) \
-PbuildDocsSite=true \
-PbuildDocs=true \
-PbuildSamples=false \
-Pversions.java.language=$(JVM) \
-x test \
-x check \
:site:docs:app:build
ifeq ($(CI),yes)
site/docs/app/build/ssg-site.zip:
@echo "Failed to locate Zip site output. Skipping."
else
site/docs/app/build/ssg-site.zip: site/docs/app/build
@echo "Starting Elide docs site for SSG build..."
$(CMD)$(RM) -fv server_pid.txt
-nohup $(GRADLE) \
--no-daemon \
:site:docs:app:run \
-Pelide.release=true \
-PbuildSamples=false \
-Pversions.java.language=$(JVM) \
> server_log.txt 2>&1 & \
echo $$! > server_pid.txt \
&& echo "Elide site server started at PID $(shell cat server_pid.txt)" \
&& echo "Waiting for server to be ready..." \
&& sleep 5 \
&& $(GRADLE) \
:packages:ssg:run \
--warning-mode=none \
--dependency-verification=lenient \
-Pelide.ci=true \
-Pelide.release=true \
-PbuildSamples=false \
-PbuildDocs=false \
-PbuildDocsSite=false \
-Pversions.java.language=$(JVM) \
--args="--http --ignore-cert-errors --verbose --no-crawl $(PWD)/site/docs/app/build/generated/ksp/main/resources/elide/runtime/generated/app.manifest.pb https://localhost:8443 $(PWD)/site/docs/app/build/ssg-site.zip" \
&& echo "Finishing up..." \
&& flush || echo "No flush needed." \
&& sleep 3 \
&& echo "Site SSG build complete.";
@echo "Killing server at PID $(shell cat server_pid.txt)..." \
&& sudo kill -9 `cat server_pid.txt` || echo "No process to kill." \
&& $(RM) -f server_pid.txt
endif
update-dep-hashes:
@echo "- Updating dependency hashes..."
$(CMD)$(GRADLE) \
-Pversions.java.language=$(JVM) \
--write-verification-metadata $(DEP_HASH_ALGO)
@echo "Dependency hashes updated."
update-dep-locks:
@echo "- Updating dependency locks (yarn)..."
$(CMD)$(YARN)
@echo ""
@echo "- Updating dependency locks (gradle)..."
$(CMD)$(GRADLE) resolveAndLockAll --write-locks
@echo "Dependency locks updated."
update-deps: ## Perform interactive dependency upgrades across Yarn and Gradle.
@echo "Upgrading dependencies..."
$(CMD)$(MAKE) update-jsdeps
@echo ""
$(CMD)$(MAKE) update-jdeps
update-jsdeps: ## Interactively update Yarn dependencies.
@echo "Running interactive update for Gradle..."
$(CMD)$(GRADLE) upgrade-gradle
update-jdeps: ## Interactively update Gradle dependencies.
@echo "Running interactive update for Gradle..."
$(CMD)$(GRADLE) upgrade-gradle
relock-deps: ## Update dependency locks and hashes across Yarn and Gradle.
@echo "Relocking dependencies..."
$(CMD)$(MAKE) update-dep-hashes update-dep-locks
serve-docs: ## Serve documentation locally.
@echo "Serving docs at http://localhost:8000..."
$(CMD)cd $(SITE_BUILD)/docs/kotlin \
&& open http://localhost:8000 \
&& python -m SimpleHTTPServer
serve-site: ## Serve Elide site locally.
@echo "Serving site at http://localhost:8000..."
$(CMD)cd $(SITE_BUILD) \
&& open http://localhost:8000 \
&& python -m SimpleHTTPServer
distclean: clean ## DANGER: Clean and remove any persistent caches. Drops changes.
@echo "Cleaning caches..."
$(CMD)$(RM) -fr$(strip $(POSIX_FLAGS)) kotlin-js-store .buildstate.tar.gz
forceclean: forceclean ## DANGER: Clean, distclean, and clear untracked files.
@echo "Resetting codebase..."
$(CMD)$(GIT) reset --hard
@echo "Cleaning untracked files..."
$(CMD)$(GIT) clean -xdf
help: ## Show this help text ('make help').
$(info Elide:)
@grep -E '^[a-z1-9A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: all build test clean distclean forceclean docs