-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
71 lines (61 loc) · 2.51 KB
/
Makefile
File metadata and controls
71 lines (61 loc) · 2.51 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
SHELL := /bin/bash
BIN := runbeam
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
TMP := ./tmp
VERSION := $(shell sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
.DEFAULT_GOAL := help
.PHONY: help
help:
@echo "Common targets:"
@echo " make build # Debug build"
@echo " make release # Release build (optimized)"
@echo " make package-macos # Package macOS binary (current arch) into ./tmp"
@echo " make package-linux # Package Linux (x86_64 musl) into ./tmp (requires musl toolchain)"
@echo " make package-windows # Package Windows (x86_64 msvc) into ./tmp (builds only on Windows)"
@echo " make clean-artifacts # Remove ./tmp artifacts"
$(TMP):
@mkdir -p $(TMP)
.PHONY: build
build:
cargo build
.PHONY: release
release:
cargo build --release
# macOS packaging (current host arch)
.PHONY: package-macos
package-macos: release $(TMP)
@OUT=$(TMP)/$(BIN)-macos-$(UNAME_M)-v$(VERSION); \
cp target/release/$(BIN) $$OUT; \
if [ "$(UNAME_S)" = "Darwin" ]; then strip -x $$OUT || true; fi; \
tar -C $(TMP) -czf $$OUT.tar.gz $$(basename $$OUT); \
shasum -a 256 $$OUT.tar.gz > $$OUT.tar.gz.sha256; \
ls -lh $$OUT*
# Linux static build/package (x86_64 musl). Requires: rustup target add x86_64-unknown-linux-musl and musl tools (or cargo-zigbuild).
.PHONY: package-linux
package-linux: $(TMP)
rustup target add x86_64-unknown-linux-musl || true
@if command -v cargo zigbuild >/dev/null 2>&1; then \
cargo zigbuild --release --target x86_64-unknown-linux-musl; \
else \
cargo build --release --target x86_64-unknown-linux-musl; \
fi
@OUT=$(TMP)/$(BIN)-linux-x86_64-v$(VERSION); \
cp target/x86_64-unknown-linux-musl/release/$(BIN) $$OUT; \
strip --strip-unneeded $$OUT || true; \
tar -C $(TMP) -czf $$OUT.tar.gz $$(basename $$OUT); \
shasum -a 256 $$OUT.tar.gz > $$OUT.tar.gz.sha256; \
ls -lh $$OUT*
# Windows packaging (x86_64 msvc). Typically run on Windows.
.PHONY: package-windows
package-windows: $(TMP)
rustup target add x86_64-pc-windows-msvc || true
cargo build --release --target x86_64-pc-windows-msvc
@OUT=$(TMP)/$(BIN)-windows-x86_64-v$(VERSION).exe; \
cp target/x86_64-pc-windows-msvc/release/$(BIN).exe $$OUT; \
cd $(TMP) && zip -9 $$(basename $$OUT .exe).zip $$(basename $$OUT); \
cd $(TMP) && certutil -hashfile $$(basename $$OUT .exe).zip SHA256 | sed -n '2p' > $$(basename $$OUT .exe).zip.sha256 || shasum -a 256 $$(basename $$OUT .exe).zip > $$(basename $$OUT .exe).zip.sha256; \
ls -lh $(TMP)/*windows*
.PHONY: clean-artifacts
clean-artifacts:
rm -rf $(TMP)