carlos / todomvc-bakeoff Public

Clone
git clone https://amadan.net/carlos/todomvc-bakeoff

Plain git — no account needed to clone.

Download

Download this file

1# TodoMVC in Nim. See README.md.
2SHELL := bash
3REPO := $(abspath ../..)
4ZIGCC := $(REPO)/scripts/zigcc-aarch64-musl
5CACHE := $(CURDIR)/.cache
6
7VERSION ?= $(shell git rev-parse --short HEAD)
8SQLITE := sqlite-amalgamation-3540100
9SQLITE_URL := https://sqlite.org/2026/$(SQLITE).zip
10SQLITE_SHA256 := 0a9c8e34352dad46006aa82836d5383bff9dc6bc9ce5a60553c05aa30e6ad1f9
11SQLITE_C := $(CACHE)/sqlite/sqlite3.c
12NIMBLE_DIR := $(CACHE)/nimble
13DEPS_STAMP := $(NIMBLE_DIR)/.installed
14
15# zig cc (the arm64 C compiler) keeps compiled musl, compiler-rt and every
16# object it builds in its caches; keep them here so clean-deps reaches them.
17export ZIG_GLOBAL_CACHE_DIR := $(CACHE)/zig-global
18export ZIG_LOCAL_CACHE_DIR := $(CACHE)/zig-local
19
20# Every library is compiled from source into a nimcache under .cache/.
21NIMFLAGS := --hints:off -d:release --opt:speed \
22 --noNimblePath $$(for p in $(NIMBLE_DIR)/pkgs2/*/; do echo --path:$$p; done) \
23 --dynlibOverride:sqlite3 -d:sqliteSource=$(SQLITE_C) \
24 -d:appVersion=$(VERSION)
25ARM64FLAGS := --cpu:arm64 --os:linux --cc:clang \
26 --clang.exe=$(ZIGCC) --clang.linkerexe=$(ZIGCC) --passL:-static --passL:-s
27
28SOURCES := $(wildcard src/*.nim src/*.nimf static/*) $(REPO)/shared/base.css $(REPO)/shared/index.css
29
30.PHONY: build build-arm64 test clean clean-deps deps bump unbump deploy
31
32build: dist/app
33build-arm64: dist/app-linux-arm64
34deps: $(DEPS_STAMP) $(SQLITE_C)
35
36dist/app: $(SOURCES) deps .FORCE
37 nim c $(NIMFLAGS) --nimcache:$(CACHE)/nimcache-host -o:$@ src/app.nim
38
39dist/app-linux-arm64: $(SOURCES) deps .FORCE
40 nim c $(NIMFLAGS) $(ARM64FLAGS) --nimcache:$(CACHE)/nimcache-arm64 -o:$@ src/app.nim
41
42test: deps
43 nim c -r $(NIMFLAGS) -d:testing --nimcache:$(CACHE)/nimcache-test -o:$(CACHE)/test_app tests/test_app.nim
44
45$(DEPS_STAMP): todo.nimble
46 source $(REPO)/scripts/env.sh && nimble --nimbleDir:$(NIMBLE_DIR) install --depsOnly -y
47 touch $@
48
49$(SQLITE_C):
50 mkdir -p $(CACHE)/dl $(CACHE)/sqlite
51 [ -f $(CACHE)/dl/$(SQLITE).zip ] || curl -sSfL -o $(CACHE)/dl/$(SQLITE).zip $(SQLITE_URL)
52 echo "$(SQLITE_SHA256) $(CACHE)/dl/$(SQLITE).zip" | sha256sum -c --quiet
53 unzip -q -o -j $(CACHE)/dl/$(SQLITE).zip '$(SQLITE)/sqlite3.c' '$(SQLITE)/sqlite3.h' -d $(CACHE)/sqlite
54 touch $@
55
56clean:
57 rm -rf dist
58
59# Compiled output only: downloaded sources (.cache/nimble, .cache/dl,
60# .cache/sqlite) stay, so the next build compiles every library again,
61# musl and compiler-rt included.
62clean-deps: clean
63 rm -rf $(CACHE)/nimcache-host $(CACHE)/nimcache-arm64 $(CACHE)/nimcache-test $(CACHE)/test_app \
64 $(CACHE)/zig-global $(CACHE)/zig-local
65
66bump:
67 sed -i 's/serverName = "todo-nim"/serverName = "todo-nim bumped"/' src/app.nim
68
69unbump:
70 sed -i 's/serverName = "todo-nim bumped"/serverName = "todo-nim"/' src/app.nim
71
72deploy:
73 source $(REPO)/scripts/env.sh && carlos deploy --account bfj --app todo-nim \
74 --target linux-arm64 --no-prompt --message "$${MESSAGE:-Deploy todo-nim $(VERSION)}" \
75 dist/app-linux-arm64
76
77.FORCE:
78