tigerbeetle-node 0.11.11 → 0.11.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/.client.node.sha256 +1 -1
  2. package/package.json +4 -7
  3. package/scripts/build_lib.sh +22 -2
  4. package/src/tigerbeetle/scripts/benchmark.bat +0 -3
  5. package/src/tigerbeetle/scripts/benchmark.sh +0 -3
  6. package/src/tigerbeetle/scripts/scripts/benchmark.bat +48 -0
  7. package/src/tigerbeetle/scripts/scripts/benchmark.sh +66 -0
  8. package/src/tigerbeetle/scripts/scripts/confirm_image.sh +44 -0
  9. package/src/tigerbeetle/scripts/scripts/fuzz_loop.sh +15 -0
  10. package/src/tigerbeetle/scripts/scripts/fuzz_unique_errors.sh +7 -0
  11. package/src/tigerbeetle/scripts/scripts/install.bat +7 -0
  12. package/src/tigerbeetle/scripts/scripts/install.sh +21 -0
  13. package/src/tigerbeetle/scripts/scripts/install_zig.bat +113 -0
  14. package/src/tigerbeetle/scripts/scripts/install_zig.sh +90 -0
  15. package/src/tigerbeetle/scripts/scripts/lint.zig +199 -0
  16. package/src/tigerbeetle/scripts/scripts/pre-commit.sh +9 -0
  17. package/src/tigerbeetle/scripts/scripts/shellcheck.sh +5 -0
  18. package/src/tigerbeetle/scripts/scripts/tests_on_alpine.sh +10 -0
  19. package/src/tigerbeetle/scripts/scripts/tests_on_ubuntu.sh +14 -0
  20. package/src/tigerbeetle/scripts/scripts/upgrade_ubuntu_kernel.sh +48 -0
  21. package/src/tigerbeetle/scripts/scripts/validate_docs.sh +23 -0
  22. package/src/tigerbeetle/scripts/scripts/vr_state_enumerate +46 -0
  23. package/src/tigerbeetle/src/message_bus.zig +1 -1
  24. package/src/tigerbeetle/src/stdx.zig +23 -0
  25. package/src/tigerbeetle/src/testing/cluster/network.zig +6 -7
  26. package/src/tigerbeetle/src/testing/cluster.zig +5 -5
  27. package/src/tigerbeetle/src/testing/packet_simulator.zig +0 -1
  28. package/src/tigerbeetle/src/vsr/README.md +209 -0
  29. package/src/tigerbeetle/src/vsr/replica.zig +195 -362
  30. package/src/tigerbeetle/src/vsr/superblock.zig +14 -17
  31. package/src/tigerbeetle/src/vsr/superblock_fuzz.zig +5 -5
  32. package/src/tigerbeetle/src/vsr.zig +274 -14
@@ -1 +1 @@
1
- 21c6105d76e0efc68fe5cbe799d363a083a9b44359e16d7dbfbb172e381ea0c3 dist/client.node
1
+ 5d30352e917b04b1b6453bc9ba0d1c8f48673d155bee91caa8240e48130211ec dist/client.node
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tigerbeetle-node",
3
- "version": "0.11.11",
3
+ "version": "0.11.12",
4
4
  "description": "TigerBeetle Node.js client",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -24,9 +24,7 @@
24
24
  "src/index.ts",
25
25
  "src/node.zig",
26
26
  "src/test.ts",
27
- "src/tigerbeetle/src/*.zig",
28
- "src/tigerbeetle/src/{c,io,lsm,testing,vsr,state_machine}",
29
- "src/tigerbeetle/scripts",
27
+ "src/tigerbeetle",
30
28
  "src/translate.zig",
31
29
  "tsconfig.json"
32
30
  ],
@@ -36,13 +34,12 @@
36
34
  "scripts": {
37
35
  "benchmark": "./scripts/benchmark.sh",
38
36
  "test": "node dist/test",
39
- "postinstall": "npm run install_zig && npm run download_node_headers && npm run build_lib",
40
- "install_zig": "sh ./src/tigerbeetle/scripts/install_zig.sh",
37
+ "postinstall": "npm run download_node_headers && npm run build_lib",
41
38
  "download_node_headers": "sh ./scripts/download_node_headers.sh",
42
39
  "build": "npm run build_tsc && npm run build_lib",
43
40
  "build_tsc": "./node_modules/typescript/bin/tsc",
44
41
  "build_lib": "sh ./scripts/build_lib.sh",
45
- "prepack": "npm run build_tsc",
42
+ "prepack": "npm run build",
46
43
  "clean": "rm -rf build dist node_modules src/zig-cache zig"
47
44
  },
48
45
  "author": "TigerBeetle, Inc",
@@ -2,11 +2,30 @@
2
2
 
3
3
  set -e
4
4
 
5
+ # This is a bit hacky. If the script is run inside tigerbeetle's repository,
6
+ # copy sources over, so that we can package them into an npm package.
7
+ #
8
+ # If the script is run inside user's node_modules, do nothing, as we assume
9
+ # the sources are already there.
10
+ if [ -f "../../tigerbeetle.zig" ] && [ -d "../../clients/node" ]; then
11
+ rm -rf ./src/tigerbeetle/src
12
+ mkdir -p ./src/tigerbeetle/src
13
+ cp -r ../../../scripts/ ./src/tigerbeetle/scripts/
14
+ cp ../../*.zig ./src/tigerbeetle/src/
15
+ for dir in io lsm testing vsr state_machine; do
16
+ cp -r ../../$dir ./src/tigerbeetle/src/$dir
17
+ done
18
+ fi
19
+
20
+ if ! [ -f "./zig/zig" ]; then
21
+ ./src/tigerbeetle/scripts/install_zig.sh
22
+ fi
23
+
5
24
  # macOS 13 Ventura is not supported on Zig 0.9.x.
6
25
  # Overriding -target is one workaround Andrew suggests.
7
26
  # https://github.com/ziglang/zig/issues/10478#issuecomment-1294313967
8
27
  target=""
9
- if [ "$(./zig/zig targets | grep triple |cut -d '"' -f 4 | cut -d '.' -f 1,2)" = "aarch64-macos.13" ]; then
28
+ if [ "$(./zig/zig targets | grep triple |cut -d '"' -f 4 | cut -d '.' -f 1,2 | cut -d '-' -f 2)" = "macos.13" ]; then
10
29
  target="-target native-macos.11"
11
30
  fi
12
31
 
@@ -24,11 +43,12 @@ else
24
43
  echo "Building for '$target'"
25
44
  fi
26
45
 
27
- mkdir -p dist
46
+ mkdir -p ./dist
28
47
 
29
48
  # Need to do string eval-ing because of shellcheck's strict string
30
49
  # interpolation rules.
31
50
  cmd="./zig/zig build-lib \
51
+ --global-cache-dir ./zig/global-cache \
32
52
  -mcpu=baseline \
33
53
  -OReleaseSafe \
34
54
  -dynamic \
@@ -42,9 +42,6 @@ for /l %%i in (0, 1, 0) do (
42
42
  start /B "tigerbeetle_%%i" .\tigerbeetle.exe start --addresses=3001 !ZIG_FILE! > benchmark.log 2>&1
43
43
  )
44
44
 
45
- rem Wait for replicas to start, listen and connect:
46
- timeout /t 2
47
-
48
45
  echo.
49
46
  echo Benchmarking...
50
47
  zig\zig.exe build benchmark -Drelease-safe
@@ -52,9 +52,6 @@ do
52
52
  ./tigerbeetle start --addresses=3001 "$FILE" >> benchmark.log 2>&1 &
53
53
  done
54
54
 
55
- # Wait for replicas to start, listen and connect:
56
- sleep 1
57
-
58
55
  echo ""
59
56
  echo "Benchmarking..."
60
57
  zig/zig build benchmark -Drelease-safe
@@ -0,0 +1,48 @@
1
+ @echo off
2
+ setlocal enabledelayedexpansion
3
+
4
+ REM Install Zig if it does not already exist:
5
+ if not exist "zig" (
6
+ call .\scripts\install_zig.bat
7
+ )
8
+
9
+ if "%~1" equ ":main" (
10
+ shift /1
11
+ goto main
12
+ )
13
+
14
+ cmd /d /c "%~f0" :main %*
15
+ set ZIG_RESULT=%ERRORLEVEL%
16
+ taskkill /F /IM tigerbeetle.exe >nul
17
+
18
+ if !ZIG_RESULT! equ 0 (
19
+ del /f benchmark.log
20
+ ) else (
21
+ echo.
22
+ echo Error running benchmark, here are more details
23
+ type benchmark.log
24
+ )
25
+
26
+ echo.
27
+ exit /b
28
+
29
+ :main
30
+ zig\zig.exe build install -Drelease-safe
31
+
32
+ for /l %%i in (0, 1, 0) do (
33
+ echo Initializing replica %%i
34
+ set ZIG_FILE=.\0_%%i.tigerbeetle.benchmark
35
+ if exist "!ZIG_FILE!" DEL /F "!ZIG_FILE!"
36
+ .\tigerbeetle.exe format --cluster=0 --replica=%%i !ZIG_FILE! > benchmark.log 2>&1
37
+ )
38
+
39
+ for /l %%i in (0, 1, 0) do (
40
+ echo Starting replica %%i
41
+ set ZIG_FILE=.\0_%%i.tigerbeetle.benchmark
42
+ start /B "tigerbeetle_%%i" .\tigerbeetle.exe start --addresses=3001 !ZIG_FILE! > benchmark.log 2>&1
43
+ )
44
+
45
+ echo.
46
+ echo Benchmarking...
47
+ zig\zig.exe build benchmark -Drelease-safe
48
+ exit /b %errorlevel%
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env bash
2
+ set -eEuo pipefail
3
+
4
+ # Number of replicas to benchmark
5
+ REPLICAS=${REPLICAS:-0}
6
+
7
+ # Install Zig if it does not already exist:
8
+ if [ ! -d "zig" ]; then
9
+ scripts/install_zig.sh
10
+ fi
11
+
12
+ COLOR_RED='\033[1;31m'
13
+ COLOR_END='\033[0m'
14
+
15
+ zig/zig build install -Drelease-safe
16
+
17
+ function onerror {
18
+ if [ "$?" == "0" ]; then
19
+ rm benchmark.log
20
+ else
21
+ echo -e "${COLOR_RED}"
22
+ echo "Error running benchmark, here are more details (from benchmark.log):"
23
+ echo -e "${COLOR_END}"
24
+ cat benchmark.log
25
+ fi
26
+
27
+ for I in $REPLICAS
28
+ do
29
+ echo "Stopping replica $I..."
30
+ done
31
+ kill %1
32
+ }
33
+ trap onerror EXIT
34
+
35
+ for I in $REPLICAS
36
+ do
37
+ echo "Formatting replica $I..."
38
+
39
+ # Be careful to use a benchmark-specific filename so that we don't erase a real data file:
40
+ FILE="./0_${I}.tigerbeetle.benchmark"
41
+ if [ -f "$FILE" ]; then
42
+ rm "$FILE"
43
+ fi
44
+
45
+ ./tigerbeetle format --cluster=0 --replica="$I" "$FILE" > benchmark.log 2>&1
46
+ done
47
+
48
+ for I in $REPLICAS
49
+ do
50
+ echo "Starting replica $I..."
51
+ FILE="./0_${I}.tigerbeetle.benchmark"
52
+ ./tigerbeetle start --addresses=3001 "$FILE" >> benchmark.log 2>&1 &
53
+ done
54
+
55
+ echo ""
56
+ echo "Benchmarking..."
57
+ zig/zig build benchmark -Drelease-safe
58
+ echo ""
59
+
60
+ for I in $REPLICAS
61
+ do
62
+ FILE="./0_${I}.tigerbeetle.benchmark"
63
+ if [ -f "$FILE" ]; then
64
+ rm "$FILE"
65
+ fi
66
+ done
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ if [[ -z "$1" ]]; then
6
+ echo "Expected a first argument with a Docker image name or id"
7
+ exit 2
8
+ fi
9
+
10
+ if [[ "$2" != "--want-production" ]] && [[ "$2" != "--want-debug" ]]; then
11
+ echo "Expected a second argument: --want-production or --want-debug".
12
+ exit 2
13
+ fi
14
+
15
+ check="
16
+ set -eu
17
+
18
+ apt-get update -y
19
+ apt-get install -y binutils
20
+
21
+ is_production=false
22
+ # This getSymbolFromDwarf symbol only appears to be in the debug
23
+ # build, not the release build. So that's the test!
24
+ if ! [[ \$(nm -an /opt/beta-beetle/tigerbeetle | grep getSymbolFromDwarf) ]]; then
25
+ is_production=true
26
+ fi
27
+ "
28
+
29
+ if [[ "$2" == '--want-production' ]]; then
30
+ cmd+="
31
+ if [[ \$is_production == false ]]; then
32
+ echo 'Does not seem to be a production build'
33
+ exit 1
34
+ fi"
35
+ else
36
+ cmd+="
37
+ if [[ \$is_production == true ]]; then
38
+ echo 'Does not seem to be a debug build'
39
+ exit 1
40
+ fi"
41
+ fi
42
+
43
+ # We accept a passed-in arg
44
+ docker run --entrypoint bash "$1" -c "$check"
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env sh
2
+ set -eu
3
+
4
+ # Repeatedly runs some zig build command with different seeds and stores the output in the current directory.
5
+ # Eg `fuzz_repeatedly.sh fuzz_lsm_forest` will run `zig build fuzz_lsm_forest -- seed $SEED > fuzz_lsm_forest_fuzz_${SEED}`
6
+ # Use ./fuzz_unique_errors.sh to analyze the results.
7
+
8
+ FUZZ_COMMAND=$1
9
+
10
+ while true; do
11
+ SEED=$(od -A n -t u8 -N 8 /dev/urandom | xargs)
12
+ (zig build "$FUZZ_COMMAND" -Drelease-safe=true -- --seed "$SEED") || \
13
+ (zig build "$FUZZ_COMMAND" -- --seed "$SEED" 2> "fuzz_${FUZZ_COMMAND}_${SEED}") || \
14
+ true
15
+ done
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env sh
2
+ set -eu
3
+
4
+ # After running ./fuzz_loop.sh use this script to produce a list of unique crashes.
5
+ # As a heuristic, we look for the first line of the stacktrace that occurs inside tigerbeetle code.
6
+
7
+ grep -m 1 'tigerbeetle/src' fuzz_* | sort -u -t':' -k2,2
@@ -0,0 +1,7 @@
1
+ @echo off
2
+ setlocal enabledelayedexpansion
3
+
4
+ call .\scripts\install_zig.bat
5
+
6
+ echo "Building TigerBeetle..."
7
+ .\zig\zig.exe build install -Dcpu=baseline -Drelease-safe
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env sh
2
+
3
+ if [ -z "$DEBUG" ]; then
4
+ debug="$DEBUG"
5
+ fi
6
+
7
+ debug="$DEBUG"
8
+ if [ "$1" = "--debug" ]; then
9
+ debug="true"
10
+ fi
11
+
12
+ set -eu
13
+
14
+ scripts/install_zig.sh
15
+ if [ "$debug" = "true" ]; then
16
+ echo "Building Tigerbeetle debug..."
17
+ zig/zig build install -Dcpu=baseline
18
+ else
19
+ echo "Building TigerBeetle..."
20
+ zig/zig build install -Dcpu=baseline -Drelease-safe
21
+ fi
@@ -0,0 +1,113 @@
1
+ @echo off
2
+
3
+ set ZIG_RELEASE_DEFAULT=0.9.1
4
+
5
+ :: Determine the Zig build:
6
+ if "%~1"=="" (
7
+ set ZIG_RELEASE=%ZIG_RELEASE_DEFAULT%
8
+ ) else if "%~1"=="latest" (
9
+ set ZIG_RELEASE=builds
10
+ ) else (
11
+ set ZIG_RELEASE=%~1
12
+ )
13
+
14
+ :: Checks format of release version.
15
+ echo.%ZIG_RELEASE% | findstr /b /r /c:"builds" /c:"^[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*">nul || (echo.Unexpected release format. && exit 1)
16
+
17
+ set ZIG_OS=windows
18
+ set ZIG_ARCH=x86_64
19
+
20
+ set ZIG_TARGET=zig-%ZIG_OS%-%ZIG_ARCH%
21
+
22
+ :: Determine the build, split the JSON line on whitespace and extract the 2nd field:
23
+ for /f "tokens=2" %%a in ('curl --silent https://ziglang.org/download/index.json ^| findstr %ZIG_TARGET% ^| findstr %ZIG_RELEASE%' ) do (
24
+ set ZIG_URL=%%a
25
+ )
26
+
27
+ :: Then remove quotes and commas:
28
+ for /f %%b in ("%ZIG_URL:,=%") do (
29
+ set ZIG_URL=%%~b
30
+ )
31
+
32
+ :: Checks the ZIG_URL variable follows the expected format.
33
+ echo.%ZIG_URL% | findstr /b /r /c:"https://ziglang.org/builds/" /c:"https://ziglang.org/download/%ZIG_RELEASE%">nul || (echo.Unexpected release URL format. && exit 1)
34
+
35
+ if "%ZIG_RELEASE%"=="builds" (
36
+ echo Installing Zig latest build...
37
+ ) else (
38
+ echo Installing Zig %ZIG_RELEASE% release build...
39
+ )
40
+
41
+ :: Using variable modifiers to determine the directory and filename from the URL:
42
+ :: %%~ni Expands %%i to a file name only and %%~xi Expands %%i to a file name extension only.
43
+ for /f %%i in ("%ZIG_URL%") do (
44
+ set ZIG_DIRECTORY=%%~ni
45
+ set ZIG_TARBALL=%%~nxi
46
+ )
47
+
48
+ :: Checks the ZIG_DIRECTORY variable follows the expected format.
49
+ echo.%ZIG_DIRECTORY% | findstr /b /r /c:"zig-win64-" /c:"zig-windows-x86_64-">nul || (echo.Unexpected zip directory name format. && exit 1)
50
+
51
+ :: Making sure we download to the same output document, without wget adding "-1" etc. if the file was previously partially downloaded:
52
+ if exist %ZIG_TARBALL% (
53
+ del /q %ZIG_TARBALL%
54
+ if exist %ZIG_TARBALL% (
55
+ echo Failed to delete %ZIG_TARBALL%.
56
+ exit 1
57
+ )
58
+ )
59
+
60
+ echo Downloading %ZIG_URL%...
61
+ curl --silent --progress-bar --output %ZIG_TARBALL% %ZIG_URL%
62
+ if not exist %ZIG_TARBALL% (
63
+ echo Failed to download Zig zip file.
64
+ exit 1
65
+ )
66
+
67
+ :: Replace any existing Zig installation so that we can install or upgrade:
68
+ echo Removing any existing 'zig' and %ZIG_DIRECTORY% folders before extracting.
69
+ if exist zig\ (
70
+ rd /s /q zig\
71
+ :: Ensure the directory has been deleted.
72
+ if exist zig\ (
73
+ echo The ‘zig’ directory could not be deleted.
74
+ exit 1
75
+ )
76
+ )
77
+
78
+ if exist %ZIG_DIRECTORY%\ (
79
+ rd /s /q %ZIG_DIRECTORY%
80
+ :: Ensure the directory has been deleted.
81
+ if exist %ZIG_DIRECTORY% (
82
+ echo The %ZIG_DIRECTORY% directory could not be deleted.
83
+ exit 1
84
+ )
85
+ )
86
+
87
+ :: Extract and then remove the downloaded tarball:
88
+ echo Extracting %ZIG_TARBALL%...
89
+
90
+ :: Hiding Powershell's progress bar during the extraction
91
+ SET PS_DISABLE_PROGRESS="$ProgressPreference=[System.Management.Automation.ActionPreference]::SilentlyContinue"
92
+ powershell -Command "%PS_DISABLE_PROGRESS%;Expand-Archive %ZIG_TARBALL% -DestinationPath ."
93
+
94
+ if not exist %ZIG_TARBALL% (
95
+ echo Failed to extract zip file.
96
+ exit 1
97
+ )
98
+
99
+ echo Installing %ZIG_DIRECTORY% to 'zig' in current working directory...
100
+ ren %ZIG_DIRECTORY% zig
101
+ if exist %ZIG_DIRECTORY% (
102
+ echo Failed to rename %ZIG_DIRECTORY% to zig.
103
+ exit 1
104
+ )
105
+
106
+ :: Removes the zip file
107
+ del /q %ZIG_TARBALL%
108
+ if exist %ZIG_TARBALL% (
109
+ echo Failed to delete %ZIG_TARBALL% file.
110
+ exit 1
111
+ )
112
+
113
+ echo "Congratulations, you have successfully installed Zig version %ZIG_RELEASE%. Enjoy!"
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env sh
2
+ set -eu
3
+
4
+ ZIG_RELEASE_DEFAULT="0.9.1"
5
+ # Default to the release build, or allow the latest dev build, or an explicit release version:
6
+ ZIG_RELEASE=${1:-$ZIG_RELEASE_DEFAULT}
7
+ if [ "$ZIG_RELEASE" = "latest" ]; then
8
+ ZIG_RELEASE="builds"
9
+ fi
10
+
11
+ # Validate the release version explicitly:
12
+ if echo "$ZIG_RELEASE" | grep -q '^builds$'; then
13
+ echo "Installing Zig latest build..."
14
+ elif echo "$ZIG_RELEASE" | grep -q '^[0-9]\+.[0-9]\+.[0-9]\+$'; then
15
+ echo "Installing Zig $ZIG_RELEASE release build..."
16
+ else
17
+ echo "Release version invalid"
18
+ exit 1
19
+ fi
20
+
21
+ # Determine the architecture:
22
+ if [ "$(uname -m)" = 'arm64' ] || [ "$(uname -m)" = 'aarch64' ]; then
23
+ ZIG_ARCH="aarch64"
24
+ else
25
+ ZIG_ARCH="x86_64"
26
+ fi
27
+
28
+ # Determine the operating system:
29
+ if [ "$(uname)" = "Linux" ]; then
30
+ ZIG_OS="linux"
31
+ else
32
+ ZIG_OS="macos"
33
+ fi
34
+
35
+ ZIG_TARGET="zig-$ZIG_OS-$ZIG_ARCH"
36
+
37
+ # Determine the build, split the JSON line on whitespace and extract the 2nd field, then remove quotes and commas:
38
+ if command -v wget; then
39
+ # -4 forces `wget` to connect to ipv4 addresses, as ipv6 fails to resolve on certain distros.
40
+ # Only A records (for ipv4) are used in DNS:
41
+ ipv4="-4"
42
+ # But Alpine doesn't support this argument
43
+ if [ -f /etc/alpine-release ]; then
44
+ ipv4=""
45
+ fi
46
+ ZIG_URL=$(wget $ipv4 --quiet -O - https://ziglang.org/download/index.json | grep -F "$ZIG_TARGET" | grep -F "$ZIG_RELEASE" | awk '{print $2}' | sed 's/[",]//g')
47
+ else
48
+ ZIG_URL=$(curl --silent https://ziglang.org/download/index.json | grep -F "$ZIG_TARGET" | grep -F "$ZIG_RELEASE" | awk '{print $2}' | sed 's/[",]//g')
49
+ fi
50
+
51
+ # Ensure that the release is actually hosted on the ziglang.org website:
52
+ if [ -z "$ZIG_URL" ]; then
53
+ echo "Release not found on ziglang.org"
54
+ exit 1
55
+ fi
56
+
57
+ # Work out the filename from the URL, as well as the directory without the ".tar.xz" file extension:
58
+ ZIG_TARBALL=$(basename "$ZIG_URL")
59
+ ZIG_DIRECTORY=$(basename "$ZIG_TARBALL" .tar.xz)
60
+
61
+ # Download, making sure we download to the same output document, without wget adding "-1" etc. if the file was previously partially downloaded:
62
+ echo "Downloading $ZIG_URL..."
63
+ if command -v wget; then
64
+ # -4 forces `wget` to connect to ipv4 addresses, as ipv6 fails to resolve on certain distros.
65
+ # Only A records (for ipv4) are used in DNS:
66
+ ipv4="-4"
67
+ # But Alpine doesn't support this argument
68
+ if [ -f /etc/alpine-release ]; then
69
+ ipv4=""
70
+ fi
71
+ wget $ipv4 --quiet --output-document="$ZIG_TARBALL" "$ZIG_URL"
72
+ else
73
+ curl --silent --output "$ZIG_TARBALL" "$ZIG_URL"
74
+ fi
75
+
76
+ # Extract and then remove the downloaded tarball:
77
+ echo "Extracting $ZIG_TARBALL..."
78
+ tar -xf "$ZIG_TARBALL"
79
+ rm "$ZIG_TARBALL"
80
+
81
+ # Replace any existing Zig installation so that we can install or upgrade:
82
+ echo "Installing $ZIG_DIRECTORY to 'zig' in current working directory..."
83
+ rm -rf zig
84
+ mv "$ZIG_DIRECTORY" zig
85
+
86
+ # It's up to the user to add this to their path if they want to:
87
+ ZIG_BIN="$(pwd)/zig/zig"
88
+
89
+ ZIG_VERSION=$($ZIG_BIN version)
90
+ echo "Congratulations, you have successfully installed Zig $ZIG_VERSION to $ZIG_BIN. Enjoy!"