| ... | @@ -16,6 +16,20 @@ if [ -z "$ZIG_LOCAL_CACHE_DIR" ]; then | ... | @@ -16,6 +16,20 @@ if [ -z "$ZIG_LOCAL_CACHE_DIR" ]; then |
| 16 | fi | 16 | fi |
| 17 | | 17 | |
| 18 | ZIG="$ZIG_LOCAL_CACHE_DIR/zig/$ZIG_VERSION/zig" | 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 | if [ ! -f "$ZIG" ]; then | 33 | if [ ! -f "$ZIG" ]; then |
| 20 | OS=$(uname -s | tr '[:upper:]' '[:lower:]') | 34 | OS=$(uname -s | tr '[:upper:]' '[:lower:]') |
| 21 | if [ "$OS" = "darwin" ]; then | 35 | if [ "$OS" = "darwin" ]; then |
| ... | @@ -28,16 +42,16 @@ if [ ! -f "$ZIG" ]; then | ... | @@ -28,16 +42,16 @@ if [ ! -f "$ZIG" ]; then |
| 28 | | 42 | |
| 29 | URL="https://ziglang.org/builds/zig-$OS-$ARCH-$ZIG_VERSION.tar.xz" | 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 | CURL=$(command -v curl 2>/dev/null) | 47 | CURL=$(command -v curl 2>/dev/null) |
| 34 | TAR=$(command -v curl 2>/dev/null) | 48 | TAR=$(command -v curl 2>/dev/null) |
| 35 | | 49 | |
| 36 | if [ -z "$CURL" ]; then | 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 | fi | 52 | fi |
| 39 | if [ -z "$TAR" ]; then | 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 | fi | 55 | fi |
| 42 | | 56 | |
| 43 | if [ -z "$CURL" ] || [ -z "$TAR" ]; then | 57 | if [ -z "$CURL" ] || [ -z "$TAR" ]; then |
| ... | @@ -48,10 +62,15 @@ if [ ! -f "$ZIG" ]; then | ... | @@ -48,10 +62,15 @@ if [ ! -f "$ZIG" ]; then |
| 48 | curl -fsSL --retry 3 --retry-delay 3 $URL \ | 62 | curl -fsSL --retry 3 --retry-delay 3 $URL \ |
| 49 | | tar -xJ --strip-components=1 -C "$ZIG_LOCAL_CACHE_DIR/zig/$ZIG_VERSION" | 63 | | tar -xJ --strip-components=1 -C "$ZIG_LOCAL_CACHE_DIR/zig/$ZIG_VERSION" |
| 50 | if [ "$($ZIG version)" != "$ZIG_VERSION" ]; then | 64 | if [ "$($ZIG version)" != "$ZIG_VERSION" ]; then |
| 51 | echo "Zig failed to install." | 65 | printf "Zig failed to install.\n" |
| 52 | rm -rf "$ZIG_LOCAL_CACHE_DIR/zig/$ZIG_VERSION" | 66 | rm -rf "$ZIG_LOCAL_CACHE_DIR/zig/$ZIG_VERSION" |
| 53 | exit 1 | 67 | exit 1 |
| 54 | fi | 68 | fi |
| 55 | fi | 69 | fi |
| 56 | | 70 | |
| | 71 | if [ "$1" == "--version" ]; then |
| | 72 | printf "Zig version: " |
| | 73 | exec $ZIG version |
| | 74 | fi |
| | 75 | |
| 57 | exec $ZIG build $@ | 76 | exec $ZIG build $@ |