Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Syndica/sig into 19/flush-c…
Browse files Browse the repository at this point in the history
…lean-db
  • Loading branch information
0xNineteen committed Jun 11, 2024
2 parents 77533d3 + 5ddea90 commit 5505a28
Show file tree
Hide file tree
Showing 70 changed files with 2,856 additions and 884 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: check

on:
push:
branches: [main, pre-release]
pull_request:
branches: [main, pre-release]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup-zig
uses: goto-bus-stop/setup-zig@v1
with:
version: 0.13.0

- name: lint
run: |
zig fmt --check src/
zig fmt --check build.zig
unused_imports:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: remove unused imports
run: python remove_unused.py src/

test:
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{matrix.os}}
steps:
- name: checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: setup-zig
uses: goto-bus-stop/setup-zig@v1
with:
version: 0.13.0

- name: test
run: zig build test

benchmarks:
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{matrix.os}}
steps:
- name: checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: setup-zig
uses: goto-bus-stop/setup-zig@v1
with:
version: 0.13.0

- name: benchmarks
run: zig build -Doptimize=ReleaseSafe benchmark

gossip:
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{matrix.os}}
steps:
- name: checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: setup-zig
uses: goto-bus-stop/setup-zig@v1
with:
version: 0.13.0

- name: build release
run: zig build -Doptimize=ReleaseSafe
- name: run gossip
run: bash scripts/gossip_test.sh 120 # in seconds
79 changes: 0 additions & 79 deletions .github/workflows/test.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
zig-cache/
.zig-cache/
zig-out/
data/

Expand All @@ -12,4 +12,4 @@ index_storage/

/gossip-dumps

**/.DS_Store
**/.DS_Store
6 changes: 1 addition & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ pub fn build(b: *Build) void {
const httpz_dep = b.dependency("httpz", dep_opts);
const httpz_mod = httpz_dep.module("httpz");

const zigdig_dep = b.dependency("zigdig", dep_opts);
const zigdig_mod = zigdig_dep.module("dns");

const zstd_dep = b.dependency("zstd", dep_opts);
const zstd_mod = zstd_dep.module("zstd");

Expand All @@ -45,7 +42,6 @@ pub fn build(b: *Build) void {
sig_mod.addImport("base58-zig", base58_module);
sig_mod.addImport("zig-cli", zig_cli_module);
sig_mod.addImport("httpz", httpz_mod);
sig_mod.addImport("zigdig", zigdig_mod);
sig_mod.addImport("zstd", zstd_mod);
sig_mod.addImport("curl", curl_mod);

Expand All @@ -62,7 +58,6 @@ pub fn build(b: *Build) void {
sig_exe.root_module.addImport("httpz", httpz_mod);
sig_exe.root_module.addImport("zig-cli", zig_cli_module);
sig_exe.root_module.addImport("zig-network", zig_network_module);
sig_exe.root_module.addImport("zigdig", zigdig_mod);
sig_exe.root_module.addImport("zstd", zstd_mod);

const main_exe_run = b.addRunArtifact(sig_exe);
Expand All @@ -79,6 +74,7 @@ pub fn build(b: *Build) void {
});
b.installArtifact(unit_tests);
unit_tests.root_module.addImport("base58-zig", base58_module);
unit_tests.root_module.addImport("curl", curl_mod);
unit_tests.root_module.addImport("httpz", httpz_mod);
unit_tests.root_module.addImport("zig-network", zig_network_module);
unit_tests.root_module.addImport("zstd", zstd_mod);
Expand Down
20 changes: 8 additions & 12 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,28 @@
},
.dependencies = .{
.@"base58-zig" = .{
.url = "https://github.com/ultd/base58-zig/archive/7cec0723c99d713149ad4e875f888918d2687ca6.tar.gz",
.hash = "1220995cd000a5d0f8595b119de29573769531c002fe3448a2c69fa6307bd1332620",
.url = "https://github.com/Syndica/base58-zig/archive/e1001fbe8b41eed36d81e37931ada66b784e51dc.tar.gz",
.hash = "12206e5050a03cd9dcb896781de0cf541081488006532675371653f61d00c1f27433",
},
.@"zig-network" = .{
.url = "https://github.com/MasterQ32/zig-network/archive/2caffd712f57f29abb5e41a453cd1c2129517b05.tar.gz",
.hash = "122095b1af33a2fbe87af9365516e6c2d21f9f5a6725b539e03bcc6ed8df3c012f39",
.url = "https://github.com/ikskuh/zig-network/archive/d4506cd1950de8a6e6d3f28aed68a0b4f64e0b44.tar.gz",
.hash = "122080b2675fa7fdd7410af5f62942dec99e0ea766827c8c6506e6672b575fb0a50e",
},
.@"zig-cli" = .{
.url = "https://github.com/sam701/zig-cli/archive/8c7a798c0f7fa0358d7ab41106fc872fca4cd995.tar.gz",
.hash = "1220c008492d9460c3be2b209600a948181e6efb3bf0d79a1633def499632e708f4b",
},
.httpz = .{
.url = "https://github.com/karlseguin/http.zig/archive/d05b9889382d240c826c7654a999e4da515bd20a.tar.gz",
.hash = "1220833d40f1767fa46b0efc4ae1af9bd5880a8e6fe7a66ee0215be916263f149e40",
},
.zigdig = .{
.url = "https://github.com/lun-4/zigdig/archive/6d872bb061a85e416304b379ce3f3b868d6e835c.tar.gz",
.hash = "1220fe113318a795d366cd63d2d3f1abacfaa6ff0739bc3240eaf7b68b06d21e4917",
.url = "https://github.com/karlseguin/http.zig/archive/79dad0f0cc652830cd8e49bf3e73aa77155ad4b2.tar.gz",
.hash = "1220b8a918dfcee4fc8326ec337776e2ffd3029511c35f6b96d10aa7be98ca2faf99",
},
.zstd = .{
.url = "https://github.com/Syndica/zstd.zig/archive/a052e839a3dfc44feb00c2eb425815baa3c76e0d.tar.gz",
.hash = "122001d56e43ef94e31243739ae83d7508abf0b8102795aff1ac91446e7ff450d875",
},
.curl = .{
.url = "https://github.com/jiacai2050/zig-curl/archive/7b1e1c6adb1daca48bbae6bd18fc1386dc6076ab.tar.gz",
.hash = "1220f2f863742c19fec9381537083da27519a7e638ce690973b34faf89f8f2b32729",
.url = "https://github.com/jiacai2050/zig-curl/archive/8a3f45798a80a5de4c11c6fa44dab8785c421d27.tar.gz",
.hash = "1220f70ac854b59315a8512861e039648d677feb4f9677bd873d6b9b7074a5906485",
},
},
}
121 changes: 53 additions & 68 deletions remove_unused.py
Original file line number Diff line number Diff line change
@@ -1,83 +1,68 @@
# parse arg of file name
# parse arg of file name
import sys
import os
import re

if len(sys.argv) != 2:
print("Usage: python remove_unused.py <dir name>")
sys.exit()

zig_files = []
dirs = [sys.argv[1]]
while 1:
while 1:
d = dirs.pop()
files = os.listdir(d)
for file in files:
for file in files:
full_path = os.path.join(d, file)
if os.path.isdir(full_path):
if os.path.isdir(full_path):
dirs.append(full_path)
else:
# if file ends in .zig
if file.endswith('.zig'):
else:
# if file ends in .zig
if file.endswith(".zig"):
zig_files.append(full_path)

if len(dirs) == 0:
break

total_removes = 0
n_remove_iter = 0
n_removes = 1
while n_removes > 0:
n_removes = 0
print(f"iteration: {n_remove_iter}, lines removed: {n_removes}")
n_remove_iter += 1

for filename in zig_files:
print(filename)

# open and read lines of file
with open(filename, 'r') as f:
full_lines = f.readlines()

# parse the value {VAR} name in 'const {VAR} = @import ...'
import_var_names = []
for (i, line) in enumerate(full_lines):
if not (line.startswith('const') or line.startswith('pub const')):
continue

if '@import' not in line:
continue

start_index = line.index("const ")
end_index = line.index(" = ")
var_name = line[start_index + 6:end_index]
import_var_names.append((var_name, i))

unused_vars = import_var_names.copy()
for i, line in enumerate(full_lines):

for var, line_num in import_var_names:
if (var in line) and (i != line_num):
if (var, line_num) in unused_vars:
unused_vars.remove((var, line_num))

new_lines = []
lines_to_remove = [i for (_, i) in unused_vars]
n_removes += len(lines_to_remove)
total_removes += len(lines_to_remove)

for (i, line) in enumerate(full_lines):
if i in lines_to_remove:
continue
new_lines.append(line)

if (len(lines_to_remove) > 0):
print(filename)
print(unused_vars)

# write
with open(filename, 'w') as f:
f.writelines(new_lines)

print("total iterations: ", n_remove_iter)
print("total lines removed: ", total_removes)

if len(dirs) == 0:
break

import_line_regex = re.compile(
r'const ([a-zA-Z0-9_]+) = (@import\("[a-zA-Z0-9_]+"\))?[a-zA-Z0-9_.]*;'
)

total_num_lines_removed = 0
lines_removed_this_time = 999 # get past 1st while check

while lines_removed_this_time > 0:
lines_removed_this_time = 0
for path in zig_files:
with open(path) as f:
orig_file = f.read()
orig_lines = orig_file.split("\n")
if orig_lines[-1] == "":
orig_lines = orig_lines[0:-1]
imported_names = []
for line_num, line in enumerate(orig_lines):
match = import_line_regex.match(line)
if match:
imported_names.append((match.groups()[0], line_num))
lines_to_drop = set()
num_lines_to_remove = 0
for name, line in imported_names:
match = re.findall(f"[^a-zA-Z0-9_.]{name}[^a-zA-Z0-9_]", orig_file)
assert len(match) > 0
if len(match) == 1:
lines_to_drop.add(line)
num_lines_to_remove += 1
with open(path, "w") as f:
f.writelines(
f"{line}\n"
for i, line in enumerate(orig_lines)
if i not in lines_to_drop
)
lines_to_drop
print(path, num_lines_to_remove)
total_num_lines_removed += num_lines_to_remove
lines_removed_this_time += num_lines_to_remove
print("removed this iteration:", lines_removed_this_time)
print()

print("total lines removed:", total_num_lines_removed)
Loading

0 comments on commit 5505a28

Please sign in to comment.