-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzig
executable file
·73 lines (60 loc) · 1.51 KB
/
zig
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
#!/bin/bash
set -e
ARCH=$(uname -m)
BASEDIR="$(cd "$(dirname "$0")" && pwd)"
ZIGDIR=$BASEDIR/.cache/zig
VERSION=$(<build.zig.version)
OS=$(uname)
if [ "$OS" == "Linux" ]; then
OS=linux
elif [ "$OS" == "Darwin" ]; then
OS=macos
elif [ "$OS" == "FreeBSD" ]; then
OS=freebsd
if [ "$ARCH" == "amd64" ]; then
ARCH=x86_64
fi
fi
if [ "$ARCH" == "arm64" ]; then
ARCH=aarch64
fi
ZIGVER="zig-$OS-$ARCH-$VERSION"
ZIG=$ZIGDIR/$ZIGVER/zig
if [ "$1" == "update" ]; then
curl -L --silent https://ziglang.org/download/index.json | jq -r '.master | .version' >build.zig.version
NEWVERSION=$(<build.zig.version)
if [ "$VERSION" != "$NEWVERSION" ]; then
echo "zig version updated from $VERSION to $NEWVERSION"
echo "rebuilding to update cdb..."
$0 cdb
exit 0
fi
echo "zig version $VERSION is up-to-date"
exit 0
fi
get_zig() {
(
mkdir -p "$ZIGDIR"
cd "$ZIGDIR"
TARBALL="https://ziglang.org/download/$VERSION/$ZIGVER.tar.xz"
if echo "$VERSION" | grep '\-dev\.' >&/dev/null; then
TARBALL="https://ziglang.org/builds/$ZIGVER.tar.xz"
fi
if [ ! -d "$ZIGVER" ]; then
curl "$TARBALL" | tar -xJ
fi
)
}
get_zig
if [ "$1" == "cdb" ]; then
rm -rf .zig-cache
rm -rf .cache/cdb
$ZIG build
(
echo \[
cat .cache/cdb/*
echo {}\]
) | perl -0777 -pe 's/,\n\{\}//igs' | jq . | grep -v 'no-default-config' >compile_commands.json
exit 0
fi
exec $ZIG "$@"