forked from so-dang-cool/dt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·111 lines (91 loc) · 2.46 KB
/
build
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")" || exit 1
project_root="$(pwd)"
required_zig_version='0.11.0'
help() {
>&2 echo "USAGE: $(basename "$0") [clean|compile|release|test|cross-clean|cross-release|cross-tar]..."
>&2 echo "A simple build will be './build release'"
>&2 echo "Compiling requires Zig ${required_zig_version}, and tests require a recent Rust toolchain installation."
}
require-zig() {
# First we check Zig's available
if ! command -v zig > /dev/null; then
>&2 echo "Zig is not installed or not found on PATH."
>&2 echo "Building this project currently requires Zig ${required_zig_version}"
exit 1
fi
# Then we check Zig is a version we can build with
_zig_version="$(zig version)"
if [[ ! ${_zig_version} =~ ^${required_zig_version} ]]; then
>&2 echo "Zig ${_zig_version} was found, but only version ${required_zig_version} is supported."
exit 1
fi
}
clean() {
rm -rf ./zig-cache ./zig-out
cd "$project_root"/old-rust-tests || exit 1
cargo clean
}
compile() {
require-zig
zig build
}
test() {
require-zig
zig build test
cd "$project_root"/old-rust-tests || exit 1
cargo test
}
release() {
require-zig
zig build -Doptimize=ReleaseSmall
}
cross-clean() {
rm -rf ./target
}
cross-release() {
require-zig
local triples=(
aarch64-linux-gnu
aarch64-linux-musleabi
arm-linux-musleabi
arm-linux-musleabihf
x86-linux-gnu
x86-linux-musl
mips64el-linux-gnuabi64
mips64el-linux-musl
mips64-linux-gnuabi64
mips64-linux-musl
mipsel-linux-gnu
mipsel-linux-musl
mips-linux-gnu
mips-linux-musl
powerpc64le-linux-gnu
powerpc64le-linux-musl
powerpc-linux-gnu
powerpc-linux-musl
riscv64-linux-gnu
riscv64-linux-musl
wasm32-wasi-musl
x86_64-linux-gnu
x86_64-linux-musl
)
for triple in "${triples[@]}"; do
>&2 echo "** Cross-compiling for $triple"
local out="$project_root"/target/"$triple"
mkdir -p "$out"
zig build -Doptimize=ReleaseSmall -Dtarget="$triple" -p "$out"
done
}
cross-tar() {
cd "$project_root"/target || exit 1
for triple in *; do
>&2 echo "** Making archive for $triple"
tar -czvf "$triple".tgz "$triple"
done
}
for cmd in "$@"; do
cd "$project_root" || exit 1
eval "$cmd"
done