tigerbeetle-node 0.8.1 → 0.9.143

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 (83) hide show
  1. package/README.md +584 -184
  2. package/dist/benchmark.js +59 -51
  3. package/dist/benchmark.js.map +1 -1
  4. package/dist/bin/aarch64-linux-gnu/client.node +0 -0
  5. package/dist/bin/aarch64-linux-musl/client.node +0 -0
  6. package/dist/bin/aarch64-macos/client.node +0 -0
  7. package/dist/bin/x86_64-linux-gnu/client.node +0 -0
  8. package/dist/bin/x86_64-linux-musl/client.node +0 -0
  9. package/dist/bin/x86_64-macos/client.node +0 -0
  10. package/dist/bin/x86_64-windows/client.node +0 -0
  11. package/dist/bindings.d.ts +141 -0
  12. package/dist/bindings.js +112 -0
  13. package/dist/bindings.js.map +1 -0
  14. package/dist/index.d.ts +2 -125
  15. package/dist/index.js +51 -101
  16. package/dist/index.js.map +1 -1
  17. package/dist/test.js +69 -55
  18. package/dist/test.js.map +1 -1
  19. package/package-lock.json +26 -0
  20. package/package.json +17 -28
  21. package/src/benchmark.ts +58 -49
  22. package/src/bindings.ts +631 -0
  23. package/src/index.ts +71 -163
  24. package/src/node.zig +169 -148
  25. package/src/test.ts +71 -57
  26. package/src/translate.zig +19 -36
  27. package/.yarn/releases/yarn-berry.cjs +0 -55
  28. package/.yarnrc.yml +0 -1
  29. package/scripts/download_node_headers.sh +0 -25
  30. package/scripts/postinstall.sh +0 -6
  31. package/src/tigerbeetle/scripts/benchmark.bat +0 -46
  32. package/src/tigerbeetle/scripts/benchmark.sh +0 -55
  33. package/src/tigerbeetle/scripts/install.sh +0 -6
  34. package/src/tigerbeetle/scripts/install_zig.bat +0 -109
  35. package/src/tigerbeetle/scripts/install_zig.sh +0 -84
  36. package/src/tigerbeetle/scripts/lint.zig +0 -199
  37. package/src/tigerbeetle/scripts/upgrade_ubuntu_kernel.sh +0 -39
  38. package/src/tigerbeetle/scripts/vopr.bat +0 -48
  39. package/src/tigerbeetle/scripts/vopr.sh +0 -33
  40. package/src/tigerbeetle/scripts/vr_state_enumerate +0 -46
  41. package/src/tigerbeetle/src/benchmark.zig +0 -290
  42. package/src/tigerbeetle/src/cli.zig +0 -244
  43. package/src/tigerbeetle/src/config.zig +0 -239
  44. package/src/tigerbeetle/src/demo.zig +0 -125
  45. package/src/tigerbeetle/src/demo_01_create_accounts.zig +0 -35
  46. package/src/tigerbeetle/src/demo_02_lookup_accounts.zig +0 -7
  47. package/src/tigerbeetle/src/demo_03_create_transfers.zig +0 -24
  48. package/src/tigerbeetle/src/demo_04_create_pending_transfers.zig +0 -61
  49. package/src/tigerbeetle/src/demo_05_post_pending_transfers.zig +0 -37
  50. package/src/tigerbeetle/src/demo_06_void_pending_transfers.zig +0 -24
  51. package/src/tigerbeetle/src/demo_07_lookup_transfers.zig +0 -7
  52. package/src/tigerbeetle/src/fifo.zig +0 -104
  53. package/src/tigerbeetle/src/io/benchmark.zig +0 -213
  54. package/src/tigerbeetle/src/io/darwin.zig +0 -793
  55. package/src/tigerbeetle/src/io/linux.zig +0 -1038
  56. package/src/tigerbeetle/src/io/test.zig +0 -643
  57. package/src/tigerbeetle/src/io/windows.zig +0 -1161
  58. package/src/tigerbeetle/src/io.zig +0 -34
  59. package/src/tigerbeetle/src/main.zig +0 -144
  60. package/src/tigerbeetle/src/message_bus.zig +0 -1000
  61. package/src/tigerbeetle/src/message_pool.zig +0 -142
  62. package/src/tigerbeetle/src/ring_buffer.zig +0 -289
  63. package/src/tigerbeetle/src/simulator.zig +0 -417
  64. package/src/tigerbeetle/src/state_machine.zig +0 -2470
  65. package/src/tigerbeetle/src/storage.zig +0 -308
  66. package/src/tigerbeetle/src/test/cluster.zig +0 -351
  67. package/src/tigerbeetle/src/test/message_bus.zig +0 -93
  68. package/src/tigerbeetle/src/test/network.zig +0 -179
  69. package/src/tigerbeetle/src/test/packet_simulator.zig +0 -387
  70. package/src/tigerbeetle/src/test/state_checker.zig +0 -145
  71. package/src/tigerbeetle/src/test/state_machine.zig +0 -76
  72. package/src/tigerbeetle/src/test/storage.zig +0 -438
  73. package/src/tigerbeetle/src/test/time.zig +0 -84
  74. package/src/tigerbeetle/src/tigerbeetle.zig +0 -222
  75. package/src/tigerbeetle/src/time.zig +0 -113
  76. package/src/tigerbeetle/src/unit_tests.zig +0 -14
  77. package/src/tigerbeetle/src/vsr/client.zig +0 -505
  78. package/src/tigerbeetle/src/vsr/clock.zig +0 -812
  79. package/src/tigerbeetle/src/vsr/journal.zig +0 -2293
  80. package/src/tigerbeetle/src/vsr/marzullo.zig +0 -309
  81. package/src/tigerbeetle/src/vsr/replica.zig +0 -5015
  82. package/src/tigerbeetle/src/vsr.zig +0 -1017
  83. package/yarn.lock +0 -42
package/.yarnrc.yml DELETED
@@ -1 +0,0 @@
1
- yarnPath: ".yarn/releases/yarn-berry.cjs"
@@ -1,25 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- # Ask node for headers
5
- HEADERS_URL=$(node -p 'process.release.headersUrl')
6
-
7
- # Work out the filename from the URL, as well as the directory without the ".tar.gz" file extension:
8
- rm -rf ./build
9
- mkdir build
10
- HEADERS_TARBALL=./build/`basename "$HEADERS_URL"`
11
-
12
- # Download, making sure we download to the same output document, without wget adding "-1" etc. if the file was previously partially downloaded:
13
- echo "Downloading $HEADERS_URL..."
14
- if command -v wget &> /dev/null; then
15
- # -4 forces `wget` to connect to ipv4 addresses, as ipv6 fails to resolve on certain distros.
16
- # Only A records (for ipv4) are used in DNS:
17
- wget -4 --quiet --show-progress --output-document=$HEADERS_TARBALL $HEADERS_URL
18
- else
19
- curl --silent --progress-bar --output $HEADERS_TARBALL $HEADERS_URL
20
- fi
21
-
22
- # Extract and then remove the downloaded tarball:
23
- echo "Extracting $HEADERS_TARBALL..."
24
- tar -xf $HEADERS_TARBALL -C ./build
25
- rm $HEADERS_TARBALL
@@ -1,6 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- ./src/tigerbeetle/scripts/install_zig.sh
5
- ./scripts/download_node_headers.sh
6
- mkdir -p dist && zig/zig build-lib -mcpu=baseline -OReleaseSafe -dynamic -lc -isystem build/node-$(node --version)/include/node src/node.zig -fallow-shlib-undefined -femit-bin=dist/client.node
@@ -1,46 +0,0 @@
1
- @echo off
2
- setlocal enabledelayedexpansion
3
-
4
- if "%~1" equ ":main" (
5
- shift /1
6
- goto main
7
- )
8
-
9
- cmd /d /c "%~f0" :main %*
10
- set ZIG_RESULT=%ERRORLEVEL%
11
- taskkill /F /IM tigerbeetle.exe >nul
12
-
13
- if !ZIG_RESULT! equ 0 (
14
- del /f benchmark.log
15
- ) else (
16
- echo.
17
- echo Error running benchmark, here are more details
18
- type benchmark.log
19
- )
20
-
21
- echo.
22
- exit /b
23
-
24
- :main
25
- zig\zig.exe build -Drelease-safe
26
- move zig-out\bin\tigerbeetle.exe . >nul
27
-
28
- for /l %%i in (0, 1, 0) do (
29
- echo Initializing replica %%i
30
- set ZIG_FILE=.\cluster_0000000000_replica_00%%i.tigerbeetle
31
- if exist "!ZIG_FILE!" DEL /F "!ZIG_FILE!"
32
- .\tigerbeetle.exe init --directory=. --cluster=0 --replica=%%i > benchmark.log 2>&1
33
- )
34
-
35
- for /l %%i in (0, 1, 0) do (
36
- echo Starting replica %%i
37
- start /B "tigerbeetle_%%i" .\tigerbeetle.exe start --directory=. --cluster=0 --addresses=3001 --replica=%%i > benchmark.log 2>&1
38
- )
39
-
40
- rem Wait for replicas to start, listen and connect:
41
- timeout /t 2
42
-
43
- echo.
44
- echo Benchmarking...
45
- zig\zig.exe run -OReleaseSafe src\benchmark.zig
46
- exit /b %errorlevel%
@@ -1,55 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -e
3
-
4
- # Install Zig if it does not already exist:
5
- if [ ! -d "zig" ]; then
6
- scripts/install_zig.sh
7
- fi
8
-
9
- COLOR_RED='\033[1;31m'
10
- COLOR_END='\033[0m'
11
-
12
- zig/zig build -Drelease-safe
13
- mv zig-out/bin/tigerbeetle .
14
-
15
- function onerror {
16
- if [ "$?" == "0" ]; then
17
- rm benchmark.log
18
- else
19
- echo -e "${COLOR_RED}"
20
- echo "Error running benchmark, here are more details (from benchmark.log):"
21
- echo -e "${COLOR_END}"
22
- cat benchmark.log
23
- fi
24
-
25
- for I in 0
26
- do
27
- echo "Stopping replica $I..."
28
- done
29
- kill %1
30
- }
31
- trap onerror EXIT
32
-
33
- for I in 0
34
- do
35
- echo "Initializing replica $I..."
36
- FILE="./cluster_0000000000_replica_00${I}.tigerbeetle"
37
- if [ -f $FILE ]; then
38
- rm $FILE
39
- fi
40
- ./tigerbeetle init --directory=. --cluster=0 --replica=$I > benchmark.log 2>&1
41
- done
42
-
43
- for I in 0
44
- do
45
- echo "Starting replica $I..."
46
- ./tigerbeetle start --directory=. --cluster=0 --addresses=3001 --replica=$I > benchmark.log 2>&1 &
47
- done
48
-
49
- # Wait for replicas to start, listen and connect:
50
- sleep 1
51
-
52
- echo ""
53
- echo "Benchmarking..."
54
- zig/zig run -OReleaseSafe src/benchmark.zig
55
- echo ""
@@ -1,6 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
- scripts/install_zig.sh
4
- echo "Building TigerBeetle..."
5
- zig/zig build -Dcpu=baseline -Drelease-safe
6
- mv zig-out/bin/tigerbeetle .
@@ -1,109 +0,0 @@
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
- powershell -Command "Expand-Archive %ZIG_TARBALL% -DestinationPath ."
90
- if not exist %ZIG_TARBALL% (
91
- echo Failed to extract zip file.
92
- exit 1
93
- )
94
-
95
- echo Installing %ZIG_DIRECTORY% to 'zig' in current working directory...
96
- ren %ZIG_DIRECTORY% zig
97
- if exist %ZIG_DIRECTORY% (
98
- echo Failed to rename %ZIG_DIRECTORY% to zig.
99
- exit 1
100
- )
101
-
102
- :: Removes the zip file
103
- del /q %ZIG_TARBALL%
104
- if exist %ZIG_TARBALL% (
105
- echo Failed to delete %ZIG_TARBALL% file.
106
- exit 1
107
- )
108
-
109
- echo "Congratulations, you have successfully installed Zig version %ZIG_RELEASE%. Enjoy!"
@@ -1,84 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- ZIG_RELEASE_DEFAULT="0.9.1"
5
-
6
- # Default to the release build, or allow the latest dev build, or an explicit release version:
7
- if [ -z "$1" ]; then
8
- ZIG_RELEASE=$ZIG_RELEASE_DEFAULT
9
- elif [ "$1" == "latest" ]; then
10
- ZIG_RELEASE="builds"
11
- else
12
- ZIG_RELEASE=$1
13
- fi
14
-
15
- # Validate the release version explicitly:
16
- if [[ $ZIG_RELEASE =~ ^builds$ ]]; then
17
- echo "Installing Zig latest build..."
18
- elif [[ $ZIG_RELEASE =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
19
- echo "Installing Zig $ZIG_RELEASE release build..."
20
- else
21
- echo "Release version invalid"
22
- exit 1
23
- fi
24
-
25
- # Determine the architecture:
26
- if [ `uname -m` == 'arm64' ] || [ `uname -m` == 'aarch64' ]; then
27
- ZIG_ARCH="aarch64"
28
- else
29
- ZIG_ARCH="x86_64"
30
- fi
31
-
32
- # Determine the operating system:
33
- if [[ "$OSTYPE" == "darwin"* ]]; then
34
- ZIG_OS="macos"
35
- else
36
- ZIG_OS="linux"
37
- fi
38
-
39
- ZIG_TARGET="zig-$ZIG_OS-$ZIG_ARCH"
40
-
41
- # Determine the build, split the JSON line on whitespace and extract the 2nd field, then remove quotes and commas:
42
- if command -v wget &> /dev/null; then
43
- # -4 forces `wget` to connect to ipv4 addresses, as ipv6 fails to resolve on certain distros.
44
- # Only A records (for ipv4) are used in DNS:
45
- ZIG_URL=`wget -4 --quiet -O - https://ziglang.org/download/index.json | grep -F "$ZIG_TARGET" | grep -F "$ZIG_RELEASE" | awk '{print $2}' | sed 's/[",]//g'`
46
- else
47
- ZIG_URL=`curl --silent https://ziglang.org/download/index.json | grep -F "$ZIG_TARGET" | grep -F "$ZIG_RELEASE" | awk '{print $2}' | sed 's/[",]//g'`
48
- fi
49
-
50
- # Ensure that the release is actually hosted on the ziglang.org website:
51
- if [ -z "$ZIG_URL" ]; then
52
- echo "Release not found on ziglang.org"
53
- exit 1
54
- fi
55
-
56
- # Work out the filename from the URL, as well as the directory without the ".tar.xz" file extension:
57
- ZIG_TARBALL=`basename "$ZIG_URL"`
58
- ZIG_DIRECTORY=`basename "$ZIG_TARBALL" .tar.xz`
59
-
60
- # Download, making sure we download to the same output document, without wget adding "-1" etc. if the file was previously partially downloaded:
61
- echo "Downloading $ZIG_URL..."
62
- if command -v wget &> /dev/null; then
63
- # -4 forces `wget` to connect to ipv4 addresses, as ipv6 fails to resolve on certain distros.
64
- # Only A records (for ipv4) are used in DNS:
65
- wget -4 --quiet --show-progress --output-document=$ZIG_TARBALL $ZIG_URL
66
- else
67
- curl --silent --progress-bar --output $ZIG_TARBALL $ZIG_URL
68
- fi
69
-
70
- # Extract and then remove the downloaded tarball:
71
- echo "Extracting $ZIG_TARBALL..."
72
- tar -xf $ZIG_TARBALL
73
- rm $ZIG_TARBALL
74
-
75
- # Replace any existing Zig installation so that we can install or upgrade:
76
- echo "Installing $ZIG_DIRECTORY to 'zig' in current working directory..."
77
- rm -rf zig
78
- mv $ZIG_DIRECTORY zig
79
-
80
- # It's up to the user to add this to their path if they want to:
81
- ZIG_BIN="$(pwd)/zig/zig"
82
-
83
- ZIG_VERSION=`$ZIG_BIN version`
84
- echo "Congratulations, you have successfully installed Zig $ZIG_VERSION to $ZIG_BIN. Enjoy!"
@@ -1,199 +0,0 @@
1
- const std = @import("std");
2
- const fs = std.fs;
3
- const math = std.math;
4
- const mem = std.mem;
5
-
6
- const whitelist = std.ComptimeStringMap([]const u32, .{
7
- .{ "src/cli.zig", &.{ 35, 39 } },
8
- });
9
-
10
- fn whitelisted(path: []const u8, line: u32) bool {
11
- const lines = whitelist.get(path) orelse return false;
12
- return mem.indexOfScalar(u32, lines, line) != null;
13
- }
14
-
15
- const Stats = struct {
16
- path: []const u8,
17
- assert_count: u32,
18
- function_count: u32,
19
- ratio: f64,
20
- };
21
-
22
- var file_stats = std.ArrayListUnmanaged(Stats){};
23
- var seen = std.AutoArrayHashMapUnmanaged(fs.File.INode, void){};
24
-
25
- var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
26
- const gpa = general_purpose_allocator.allocator();
27
-
28
- pub fn main() !void {
29
- const argv = std.os.argv;
30
- for (argv[1..]) |raw_path| {
31
- const path = mem.span(raw_path);
32
- lint_file(path, fs.cwd(), path) catch |err| switch (err) {
33
- error.IsDir, error.AccessDenied => try lint_dir(path, fs.cwd(), path),
34
- else => return err,
35
- };
36
- }
37
-
38
- var max_path_len: usize = "total:".len;
39
- var total_assert_count: usize = 0;
40
- var total_function_count: usize = 0;
41
- for (file_stats.items) |stats| {
42
- max_path_len = math.max(max_path_len, stats.path.len);
43
- total_assert_count += stats.assert_count;
44
- total_function_count += stats.function_count;
45
- }
46
-
47
- std.sort.sort(Stats, file_stats.items, {}, struct {
48
- fn less_than(_: void, a: Stats, b: Stats) bool {
49
- return a.ratio > b.ratio;
50
- }
51
- }.less_than);
52
-
53
- var buffered_writer = std.io.bufferedWriter(std.io.getStdOut().writer());
54
- const stdout = buffered_writer.writer();
55
-
56
- try stdout.writeAll("\npath");
57
- try stdout.writeByteNTimes(' ', max_path_len - "path".len);
58
- try stdout.writeAll(" asserts functions ratio\n");
59
-
60
- for (file_stats.items) |stats| {
61
- try stdout.writeAll(stats.path);
62
- try stdout.writeByteNTimes(' ', max_path_len - stats.path.len);
63
- try stdout.print(" {d: >7} {d: >9} {d: >5.2}\n", .{
64
- stats.assert_count,
65
- stats.function_count,
66
- stats.ratio,
67
- });
68
- }
69
-
70
- try stdout.writeByteNTimes(' ', max_path_len - "total:".len);
71
- try stdout.print("total: {d: >7} {d: >9} {d: >5.2}\n", .{
72
- total_assert_count,
73
- total_function_count,
74
- @intToFloat(f64, total_assert_count) / @intToFloat(f64, total_function_count),
75
- });
76
- try buffered_writer.flush();
77
- }
78
-
79
- const LintError = error{
80
- OutOfMemory,
81
- ParseError,
82
- NotUtf8,
83
- } || fs.File.OpenError || fs.File.ReadError || fs.File.WriteError;
84
-
85
- fn lint_dir(file_path: []const u8, parent_dir: fs.Dir, parent_sub_path: []const u8) LintError!void {
86
- var dir = try parent_dir.openDir(parent_sub_path, .{ .iterate = true });
87
- defer dir.close();
88
-
89
- const stat = try dir.stat();
90
- if (try seen.fetchPut(gpa, stat.inode, {})) |_| return;
91
-
92
- var dir_it = dir.iterate();
93
- while (try dir_it.next()) |entry| {
94
- const is_dir = entry.kind == .Directory;
95
-
96
- if (is_dir and std.mem.eql(u8, entry.name, "zig-cache")) continue;
97
-
98
- if (is_dir or mem.endsWith(u8, entry.name, ".zig")) {
99
- const full_path = try fs.path.join(gpa, &[_][]const u8{ file_path, entry.name });
100
- defer gpa.free(full_path);
101
-
102
- if (is_dir) {
103
- try lint_dir(full_path, dir, entry.name);
104
- } else {
105
- try lint_file(full_path, dir, entry.name);
106
- }
107
- }
108
- }
109
- }
110
-
111
- fn lint_file(file_path: []const u8, dir: fs.Dir, sub_path: []const u8) LintError!void {
112
- const source_file = try dir.openFile(sub_path, .{});
113
- defer source_file.close();
114
-
115
- const stat = try source_file.stat();
116
-
117
- if (stat.kind == .Directory) return error.IsDir;
118
-
119
- // Add to set after no longer possible to get error.IsDir.
120
- if (try seen.fetchPut(gpa, stat.inode, {})) |_| return;
121
-
122
- const source = try source_file.readToEndAllocOptions(
123
- gpa,
124
- math.maxInt(usize),
125
- null,
126
- @alignOf(u8),
127
- 0,
128
- );
129
- try check_line_length(source, file_path);
130
-
131
- var tree = try std.zig.parse(gpa, source);
132
- defer tree.deinit(gpa);
133
-
134
- if (tree.errors.len != 0) return error.ParseError;
135
-
136
- const node_tags = tree.nodes.items(.tag);
137
- const main_tokens = tree.nodes.items(.main_token);
138
- const node_datas = tree.nodes.items(.data);
139
-
140
- var function_count: u32 = 0;
141
- var assert_count: u32 = 0;
142
- for (node_tags) |tag, node| {
143
- switch (tag) {
144
- .fn_decl => {
145
- function_count += 1;
146
- const body = node_datas[node].rhs;
147
- const body_start = tree.tokenLocation(0, tree.firstToken(body));
148
- const body_end = tree.tokenLocation(0, tree.lastToken(body));
149
- // Add 1 as the count returned by tokenLocation() is
150
- // 0-indexed while most editors start at 1.
151
- const line = @intCast(u32, body_start.line + 1);
152
- const body_lines = body_end.line - body_start.line;
153
- if (body_lines > 70 and !whitelisted(file_path, line)) {
154
- const stderr = std.io.getStdErr().writer();
155
- try stderr.print("{s}:{d} function body exceeds 70 lines ({d} lines)\n", .{
156
- file_path,
157
- line,
158
- body_lines,
159
- });
160
- }
161
- },
162
-
163
- .call_one, .call_one_comma => {
164
- const lhs = node_datas[node].lhs;
165
- if (node_tags[lhs] == .identifier and
166
- mem.eql(u8, "assert", tree.tokenSlice(main_tokens[lhs])))
167
- {
168
- assert_count += 1;
169
- }
170
- },
171
-
172
- .unreachable_literal => assert_count += 1,
173
-
174
- else => {},
175
- }
176
- }
177
-
178
- try file_stats.append(gpa, .{
179
- .path = try gpa.dupe(u8, file_path),
180
- .assert_count = assert_count,
181
- .function_count = function_count,
182
- .ratio = @intToFloat(f64, assert_count) / @intToFloat(f64, function_count),
183
- });
184
- }
185
-
186
- fn check_line_length(source: []const u8, path: []const u8) !void {
187
- var i: usize = 0;
188
- var line: u32 = 1;
189
- while (mem.indexOfScalar(u8, source[i..], '\n')) |newline| : (line += 1) {
190
- const line_length = std.unicode.utf8CountCodepoints(
191
- source[i..][0..newline],
192
- ) catch return error.NotUtf8;
193
- if (line_length > 100 and !whitelisted(path, line)) {
194
- const stderr = std.io.getStdErr().writer();
195
- try stderr.print("{s}:{d} line exceeds 100 columns\n", .{ path, line });
196
- }
197
- i += newline + 1;
198
- }
199
- }
@@ -1,39 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- # Assert that we are only upgrading the kernel for Ubuntu, and not another distribution:
5
- DISTRIBUTION=`lsb_release -i | awk '{print $3}'`
6
- if [ $DISTRIBUTION != "Ubuntu" ]; then
7
- echo "This script must be run on Ubuntu."
8
- exit 1
9
- fi
10
-
11
- # Use a temporary download directory that we can cleanup afterwards:
12
- DIRECTORY_PREFIX="upgrade_ubuntu_kernel"
13
- rm -rf $DIRECTORY_PREFIX
14
- mkdir $DIRECTORY_PREFIX
15
-
16
- # Download the 5.7.15 amd64 generic kernel files (note the "_all.deb" or "generic" keywords):
17
- echo "Downloading the 5.7.15 amd64 generic kernel files..."
18
- wget --quiet --show-progress --directory-prefix=$DIRECTORY_PREFIX https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.7.15/amd64/linux-headers-5.7.15-050715_5.7.15-050715.202008111432_all.deb
19
- wget --quiet --show-progress --directory-prefix=$DIRECTORY_PREFIX https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.7.15/amd64/linux-headers-5.7.15-050715-generic_5.7.15-050715.202008111432_amd64.deb
20
- wget --quiet --show-progress --directory-prefix=$DIRECTORY_PREFIX https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.7.15/amd64/linux-image-unsigned-5.7.15-050715-generic_5.7.15-050715.202008111432_amd64.deb
21
- wget --quiet --show-progress --directory-prefix=$DIRECTORY_PREFIX https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.7.15/amd64/linux-modules-5.7.15-050715-generic_5.7.15-050715.202008111432_amd64.deb
22
-
23
- # Install and then remove the downloaded files:
24
- echo "Installing (requires root)..."
25
- sudo dpkg -i $DIRECTORY_PREFIX/*.deb
26
- rm -rf $DIRECTORY_PREFIX
27
- echo "Installed the 5.7.15 amd64 generic kernel files."
28
-
29
- # Reboot the system if the user wants to:
30
- read -p "Press Y to reboot your system (or any other key to reboot later)... " -n 1 -r
31
- echo
32
- if [[ $REPLY =~ ^[Yy]$ ]]
33
- then
34
- echo "Rebooting in 3 seconds..."
35
- sleep 3
36
- sudo reboot
37
- else
38
- echo "You must reboot your system for these changes to take effect."
39
- fi
@@ -1,48 +0,0 @@
1
- :: Installs Zig if needed and runs the VOPR
2
- @echo off
3
-
4
- :: Install Zig if a zig folder does not already exist:
5
- if not exist zig\ (
6
- :: Installs the latest version of Zig
7
- call scripts\install_zig.bat
8
- :: Checks that the Zig folder now exists
9
- if not exist zig\ (
10
- echo The Zig installation failed.
11
- exit 1
12
- )
13
- echo Running the TigerBeetle VOPR for the first time...
14
- echo Visit https://www.tigerbeetle.com
15
- )
16
-
17
- :: If a seed is provided as an argument then replay the seed, otherwise test 1,000 seeds:
18
- if not "%~1"=="" (
19
- :: Build in fast ReleaseSafe mode if required, useful where you don't need debug logging:
20
- if "%~2"=="-OReleaseSafe" (
21
- echo Replaying seed %~1 in ReleaseSafe mode...
22
- call zig\zig run src\simulator.zig -OReleaseSafe -- %~1
23
- if not %ERRORLEVEL%==0 (
24
- echo Cannot replay the %~1 seed using the VOPR.
25
- exit 1
26
- )
27
- ) else (
28
- echo Replaying seed %~1 in Debug mode with full debug logging enabled...
29
- call zig\zig run src\simulator.zig -ODebug -- %~1
30
- if not %ERRORLEVEL%==0 (
31
- echo Cannot run the VOPR.
32
- exit 1
33
- )
34
- )
35
- ) else (
36
- call zig\zig build-exe src\simulator.zig -OReleaseSafe
37
- if not %ERRORLEVEL%==0 (
38
- echo Cannot run the VOPR.
39
- exit 1
40
- )
41
- for %%i in (1,1,1000) do (
42
- call simulator
43
- if not %ERRORLEVEL%==0 (
44
- echo Cannot run a seed using the VOPR.
45
- exit 1
46
- )
47
- )
48
- )
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -e
3
-
4
- # Install Zig if it does not already exist:
5
- if [ ! -d "zig" ]; then
6
- scripts/install_zig.sh
7
- echo ""
8
- echo "Running the TigerBeetle VOPR for the first time..."
9
- echo "Visit https://www.tigerbeetle.com"
10
- sleep 2
11
- fi
12
-
13
- # If a seed is provided as an argument then replay the seed, otherwise test a 1,000 seeds:
14
- if [ "$1" ]; then
15
-
16
- # Build in fast ReleaseSafe mode if required, useful where you don't need debug logging:
17
- if [ "$2" == "-OReleaseSafe" ]; then
18
- echo "Replaying seed $1 in ReleaseSafe mode..."
19
- BUILD_MODE="-OReleaseSafe"
20
- else
21
- echo "Replaying seed $1 in Debug mode with full debug logging enabled..."
22
- BUILD_MODE="-ODebug"
23
- fi
24
- echo ""
25
-
26
- zig/zig run src/simulator.zig $BUILD_MODE -- $1
27
- else
28
- zig/zig build-exe src/simulator.zig -OReleaseSafe
29
- for I in {1..1000}
30
- do
31
- ./simulator
32
- done
33
- fi