-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
install-zig
executable file
·75 lines (64 loc) · 1.86 KB
/
install-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
74
75
#!/usr/bin/env bash
set -eo pipefail
version='0.11.0' # 2023-08-04
case "$(uname)" in
Darwin*) os='macos' ;;
Linux*) os='linux' ;;
Windows*) os='windows' ;;
MINGW*) os='windows' ;;
MSYS_NT-*) os='windows' ;;
*) os='linux' ;;
esac
case "${os}" in
windows*) ext='zip' ;;
*) ext='tar.xz' ;;
esac
release_name="zig-${os}-x86_64-${version}"
archive="${release_name}.${ext}"
url="https://ziglang.org/download/${version}/${archive}"
curlopts=(
--silent
--show-error
--fail
--location
--retry 3
)
# Download the release archive.
echo "Downloading Zig release archive..." >&2
curl "${curlopts[@]}" --output "${archive}" "${url}"
# Check that the archive has the expected hash.
echo "Verifying archive..." >&2
case "${os}" in
linux)
archive_sha256='2d00e789fec4f71790a6e7bf83ff91d564943c5ee843c5fd966efc474b423047'
echo "${archive_sha256} ${archive}" | sha256sum -c -
;;
macos)
archive_sha256='1c1c6b9a906b42baae73656e24e108fd8444bb50b6e8fd03e9e7a3f8b5f05686'
shasum -a 256 -c <<< "${archive_sha256} *${archive}"
;;
*)
echo "${os} not yet supported" >&2
exit 1
;;
esac
# Extract the archive, then remove it.
echo "Extracting archive..." >&2
case "${ext}" in
*zip) unzip "${archive}" ;;
*) tar xJf "${archive}" ;;
esac
rm "${archive}"
# Add zig directory to `GITHUB_PATH`.
zig_dir="$(pwd)/${release_name}"
echo "${zig_dir}" >> "${GITHUB_PATH}"
# Install `zigcc`, which is just a wrapper for `zig cc`. We need this because
# the value of e.g. `--clang.exe` cannot contain a space (Nim requires the value
# to be an executable, not a command).
zigcc_path="${zig_dir}/zigcc"
printf '#!/usr/bin/env sh\nzig cc $@\n' > "${zigcc_path}"
chmod +x "${zigcc_path}"
# Print the versions of Zig and Clang.
"${zig_dir}"/zig version
"${zig_dir}"/zig cc --version
echo "Successfully installed Zig ${version}."