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# todo-swift: see README.md.
2#
3# Everything SwiftPM fetches or compiles stays under .cache/ (sources in
4# .cache/swiftpm and .cache/build/checkouts, compiled output in
5# .cache/build/<triple>), so `make clean-deps` can remove the compiled
6# part without touching any other project.
7
8SHELL := bash
9ROOT := $(abspath ../..)
10SWIFT := source $(ROOT)/scripts/env.sh && swift
11SWIFTPM := --scratch-path .cache/build --cache-path .cache/swiftpm
12ARM64_SDK := aarch64-swift-linux-musl
13DIRTY := $(shell git status --porcelain -- . 2>/dev/null | grep -q . && echo -dirty)
14VERSION ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo dev)$(DIRTY)
15MSG ?= todo-swift $(VERSION)
16
17.PHONY: build build-arm64 test clean clean-deps bump unbump deploy generate run
18
19# Embeds the CSS and JS into the binary and stamps the build version.
20# Each file is only rewritten when its content changes.
21generate:
22 @tools/embed.sh $(ROOT)/shared static Sources/TodoApp/Assets.swift
23 @mkdir -p .cache
24 @printf '// GENERATED by make. The build version /api/version reports.\npublic let buildVersion = "%s"\n' '$(VERSION)' > .cache/Version.swift.new
25 @if cmp -s .cache/Version.swift.new Sources/TodoApp/Version.swift; then rm .cache/Version.swift.new; \
26 else mv .cache/Version.swift.new Sources/TodoApp/Version.swift; fi
27
28build: generate
29 $(SWIFT) build -c release $(SWIFTPM)
30 @mkdir -p dist
31 cp .cache/build/release/todo dist/app.new && mv dist/app.new dist/app
32
33build-arm64: generate
34 $(SWIFT) build -c release $(SWIFTPM) --swift-sdk $(ARM64_SDK) -Xlinker --strip-all
35 @mkdir -p dist
36 cp .cache/build/$(ARM64_SDK)/release/todo dist/app-linux-arm64.new && mv dist/app-linux-arm64.new dist/app-linux-arm64
37 echo '$(VERSION)' > dist/app-linux-arm64.version
38 @file dist/app-linux-arm64 | grep -q 'ARM aarch64.*statically linked' \
39 || { echo "dist/app-linux-arm64 is not a static arm64 binary"; file dist/app-linux-arm64; exit 1; }
40
41test: generate
42 $(SWIFT) test $(SWIFTPM)
43
44# Runs the local build on 127.0.0.1 for the shared suite.
45PORT ?= 8080
46run: build
47 dist/app --listen 127.0.0.1:$(PORT) --db $${TMPDIR:-/tmp}/todo-swift.db
48
49clean:
50 rm -rf dist
51
52# Removes every compiled artifact, ours and the dependencies', and keeps the
53# downloaded sources (.cache/swiftpm, .cache/build/checkouts and
54# .cache/build/repositories), so the next build compiles everything again.
55clean-deps: clean
56 @[ ! -d .cache/build ] || find .cache/build -mindepth 1 -maxdepth 1 \
57 ! -name checkouts ! -name repositories ! -name artifacts ! -name workspace-state.json \
58 -exec rm -rf {} +
59
60bump:
61 sed -i 's/^let bumpNote = "unbumped"$$/let bumpNote = "bumped"/' Sources/TodoApp/Routes.swift
62 grep -q '^let bumpNote = "bumped"$$' Sources/TodoApp/Routes.swift
63
64unbump:
65 sed -i 's/^let bumpNote = "bumped"$$/let bumpNote = "unbumped"/' Sources/TodoApp/Routes.swift
66 grep -q '^let bumpNote = "unbumped"$$' Sources/TodoApp/Routes.swift
67
68# Ships dist/app-linux-arm64. Build it from a clean commit first: the
69# version it reports is that commit's short SHA.
70deploy:
71 @[ -f dist/app-linux-arm64 ] || { echo "run make build-arm64 first"; exit 1; }
72 @case "$(VERSION)" in *-dirty) echo "commit first: the tree has changes"; exit 1;; esac
73 @[ "$$(cat dist/app-linux-arm64.version)" = '$(VERSION)' ] \
74 || { echo "dist/app-linux-arm64 wasn't built at $(VERSION); run make build-arm64"; exit 1; }
75 carlos deploy --account bfj --app todo-swift --target linux-arm64 --message "$(MSG)" dist/app-linux-arm64
76