| ... | ... | @@ -16,6 +16,20 @@ if [ -z "$ZIG_LOCAL_CACHE_DIR" ]; then |
| 16 | 16 | fi |
| 17 | 17 | |
| 18 | 18 | ZIG="$ZIG_LOCAL_CACHE_DIR/zig/$ZIG_VERSION/zig" |
| 19 | |
| 20 | if [ "$1" == "--fmt" ]; then |
| 21 | # dprint.jsonc is configured to run this, however it runs in parallel. |
| 22 | # only one installation should happen, not one per file. since there |
| 23 | # is no concise way to acquire a filesystem lock on .zig-cache, |
| 24 | # formatting before an install is left unsupported. |
| 25 | if [ ! -f "$ZIG" ]; then |
| 26 | printf "Zig is not installed. Please run ./build once manually\n" |
| 27 | exit 1 |
| 28 | fi |
| 29 | shift |
| 30 | exec $ZIG fmt $@ |
| 31 | fi |
| 32 | |
| 19 | 33 | if [ ! -f "$ZIG" ]; then |
| 20 | 34 | OS=$(uname -s | tr '[:upper:]' '[:lower:]') |
| 21 | 35 | if [ "$OS" = "darwin" ]; then |
| ... | ... | @@ -28,16 +42,16 @@ if [ ! -f "$ZIG" ]; then |
| 28 | 42 | |
| 29 | 43 | URL="https://ziglang.org/builds/zig-$OS-$ARCH-$ZIG_VERSION.tar.xz" |
| 30 | 44 | |
| 31 | | echo "Installing Zig v$ZIG_VERSION via $URL" |
| 45 | printf "Installing Zig v$ZIG_VERSION via $URL\n" |
| 32 | 46 | |
| 33 | 47 | CURL=$(command -v curl 2>/dev/null) |
| 34 | 48 | TAR=$(command -v curl 2>/dev/null) |
| 35 | 49 | |
| 36 | 50 | if [ -z "$CURL" ]; then |
| 37 | | echo "This script requires 'curl' to be installed." |
| 51 | printf "This script requires 'curl' to be installed.\n" |
| 38 | 52 | fi |
| 39 | 53 | if [ -z "$TAR" ]; then |
| 40 | | echo "This script requires 'tar' to be installed." |
| 54 | printf "This script requires 'tar' to be installed.\n" |
| 41 | 55 | fi |
| 42 | 56 | |
| 43 | 57 | if [ -z "$CURL" ] || [ -z "$TAR" ]; then |
| ... | ... | @@ -48,10 +62,15 @@ if [ ! -f "$ZIG" ]; then |
| 48 | 62 | curl -fsSL --retry 3 --retry-delay 3 $URL \ |
| 49 | 63 | | tar -xJ --strip-components=1 -C "$ZIG_LOCAL_CACHE_DIR/zig/$ZIG_VERSION" |
| 50 | 64 | if [ "$($ZIG version)" != "$ZIG_VERSION" ]; then |
| 51 | | echo "Zig failed to install." |
| 65 | printf "Zig failed to install.\n" |
| 52 | 66 | rm -rf "$ZIG_LOCAL_CACHE_DIR/zig/$ZIG_VERSION" |
| 53 | 67 | exit 1 |
| 54 | 68 | fi |
| 55 | 69 | fi |
| 56 | 70 | |
| 71 | if [ "$1" == "--version" ]; then |
| 72 | printf "Zig version: " |
| 73 | exec $ZIG version |
| 74 | fi |
| 75 | |
| 57 | 76 | exec $ZIG build $@ |