| 1 | # todo-zig. Zig comes from the repo's scripts/env.sh; every Zig cache is |
| 2 | # kept under .cache/ so clean-deps can remove compiled artifacts without |
| 3 | # touching anything outside this directory. |
| 4 | |
| 5 | SHELL := bash |
| 6 | ZIG ?= zig |
| 7 | VERSION ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo dev) |
| 8 | |
| 9 | export ZIG_GLOBAL_CACHE_DIR := $(CURDIR)/.cache/zig |
| 10 | export ZIG_LOCAL_CACHE_DIR := $(CURDIR)/.cache/zig-local |
| 11 | export ZIG_LOCAL_PKG_DIR := $(CURDIR)/.cache/pkg |
| 12 | |
| 13 | BUILD = $(ZIG) build -Doptimize=ReleaseSafe -Dversion=$(VERSION) |
| 14 | SRC = build.zig build.zig.zon $(wildcard src/*.zig static/*) ../../shared/base.css ../../shared/index.css |
| 15 | |
| 16 | .PHONY: build build-arm64 test clean clean-deps bump unbump deploy |
| 17 | |
| 18 | build: $(SRC) |
| 19 | $(BUILD) -Dtarget=native-linux-musl --prefix .cache/out-native |
| 20 | install -D .cache/out-native/bin/app dist/app |
| 21 | |
| 22 | build-arm64: $(SRC) |
| 23 | $(BUILD) -Dtarget=aarch64-linux-musl --prefix .cache/out-arm64 |
| 24 | install -D .cache/out-arm64/bin/app dist/app-linux-arm64 |
| 25 | |
| 26 | test: |
| 27 | $(ZIG) build test -Dtarget=native-linux-musl --summary all |
| 28 | |
| 29 | clean: |
| 30 | rm -rf dist .cache/out-native .cache/out-arm64 |
| 31 | |
| 32 | # Keeps the downloaded SQLite sources (.cache/zig/p and .cache/pkg) and |
| 33 | # drops everything compiled from them. |
| 34 | clean-deps: clean |
| 35 | rm -rf .cache/zig-local .cache/zig/o .cache/zig/h .cache/zig/z .cache/zig/b .cache/zig/tmp |
| 36 | |
| 37 | bump: |
| 38 | sed -i 's/^const health_body = "ok";$$/const health_body = "ok (bumped)";/' src/app.zig |
| 39 | |
| 40 | unbump: |
| 41 | sed -i 's/^const health_body = "ok (bumped)";$$/const health_body = "ok";/' src/app.zig |
| 42 | |
| 43 | deploy: |
| 44 | carlos deploy --account bfj --app todo-zig --target linux-arm64 --version $(VERSION) \ |
| 45 | --message "$${MESSAGE:-todo-zig $(VERSION)}" dist/app-linux-arm64 |
| 46 | |