-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMakefile
More file actions
93 lines (76 loc) · 3.75 KB
/
Copy pathMakefile
File metadata and controls
93 lines (76 loc) · 3.75 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
ROOT_DIR := $(CURDIR)
PROTO_DIR := $(ROOT_DIR)/protocol
PROTO_FILE := $(PROTO_DIR)/codegrinder.proto
DIST_DIR ?= $(ROOT_DIR)/www
MACOS_SDK_DIR ?= $(ROOT_DIR)/macos-minimal-sdk
MACOS_AMD64_SDKROOT ?= $(MACOS_SDK_DIR)/sysroot-macos-x86_64
MACOS_ARM64_SDKROOT ?= $(MACOS_SDK_DIR)/sysroot-macos-arm64
MACOSX_DEPLOYMENT_TARGET ?= 11.0
.PHONY: all setup build server grind web web-check exam test end2end clean \
grind-dist grind-linux-amd64 grind-linux-arm64 \
grind-macos-amd64 grind-macos-arm64
all: build
setup:
@missing=0; \
for tool in cargo protoc; do \
if ! command -v $$tool >/dev/null 2>&1; then \
echo "Missing tool: $$tool"; \
missing=1; \
fi; \
done; \
if [ $$missing -ne 0 ]; then \
echo "One or more required tools are missing. Skipping dependency setup."; \
exit 0; \
fi
cargo fetch
build:
cargo build --release --workspace
server:
cargo build --release -p codegrinder
grind:
cargo build --release -p grind
web:
npm --prefix www/web run build
web-check:
npm --prefix www/web run typecheck
exam:
npm --prefix www/exam run build
grind-dist: grind-linux-amd64 grind-linux-arm64 grind-macos-amd64 grind-macos-arm64
grind-linux-amd64: build
mkdir -p $(DIST_DIR)
cp target/release/grind $(DIST_DIR)/grind.linux_amd64
@if readelf -l $(DIST_DIR)/grind.linux_amd64 | grep -q INTERP; then echo "Linux AMD64 grind is dynamically linked" >&2; exit 1; fi
grind-linux-arm64:
@command -v cargo-zigbuild >/dev/null 2>&1 || { echo "Missing cargo-zigbuild" >&2; exit 1; }
@command -v readelf >/dev/null 2>&1 || { echo "Missing readelf (usually provided by binutils)" >&2; exit 1; }
@target_libdir="$$(rustc --print target-libdir --target aarch64-unknown-linux-musl)"; ls "$$target_libdir"/libstd-*.rlib >/dev/null 2>&1 || { echo "Missing Rust target aarch64-unknown-linux-musl; run: rustup target add aarch64-unknown-linux-musl" >&2; exit 1; }
cargo zigbuild --release -p grind --target aarch64-unknown-linux-musl
mkdir -p $(DIST_DIR)
cp target/aarch64-unknown-linux-musl/release/grind $(DIST_DIR)/grind.linux_arm64
@if readelf -l $(DIST_DIR)/grind.linux_arm64 | grep -q INTERP; then echo "Linux ARM64 grind is dynamically linked" >&2; exit 1; fi
cargo clean --target aarch64-unknown-linux-musl
grind-macos-amd64:
@command -v cargo-zigbuild >/dev/null 2>&1 || { echo "Missing cargo-zigbuild" >&2; exit 1; }
@target_libdir="$$(rustc --print target-libdir --target x86_64-apple-darwin)"; ls "$$target_libdir"/libstd-*.rlib >/dev/null 2>&1 || { echo "Missing Rust target x86_64-apple-darwin; run: rustup target add x86_64-apple-darwin" >&2; exit 1; }
$(MAKE) -C $(MACOS_SDK_DIR) sysroot-macos-x86_64
SDKROOT=$(MACOS_AMD64_SDKROOT) MACOSX_DEPLOYMENT_TARGET=$(MACOSX_DEPLOYMENT_TARGET) cargo zigbuild --release -p grind --target x86_64-apple-darwin
mkdir -p $(DIST_DIR)
cp target/x86_64-apple-darwin/release/grind $(DIST_DIR)/grind.darwin_amd64
cargo clean --target x86_64-apple-darwin
grind-macos-arm64:
@command -v cargo-zigbuild >/dev/null 2>&1 || { echo "Missing cargo-zigbuild" >&2; exit 1; }
@target_libdir="$$(rustc --print target-libdir --target aarch64-apple-darwin)"; ls "$$target_libdir"/libstd-*.rlib >/dev/null 2>&1 || { echo "Missing Rust target aarch64-apple-darwin; run: rustup target add aarch64-apple-darwin" >&2; exit 1; }
$(MAKE) -C $(MACOS_SDK_DIR) sysroot-macos-arm64
SDKROOT=$(MACOS_ARM64_SDKROOT) MACOSX_DEPLOYMENT_TARGET=$(MACOSX_DEPLOYMENT_TARGET) cargo zigbuild --release -p grind --target aarch64-apple-darwin
mkdir -p $(DIST_DIR)
cp target/aarch64-apple-darwin/release/grind $(DIST_DIR)/grind.darwin_arm64
cargo clean --target aarch64-apple-darwin
test:
cargo test --release --workspace
cargo clippy --release --workspace -- -D warnings
cargo fmt --all --check
end2end:
python3 tests/e2e.py
clean:
cargo clean
$(MAKE) -C $(MACOS_SDK_DIR) clean