Skip to content

Commit bb80b0e

Browse files
authored
Merge pull request #26 from zigtools/auguste/fuzzer-with-reducer
fuzzer with reducer + web frontend
2 parents e3ff6ff + 7b47bb0 commit bb80b0e

18 files changed

+2413
-735
lines changed

.gitattributes

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.zig text=auto eol=lf
1+
* text=auto eol=lf

.github/workflows/main.yml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ name: CI
22

33
on:
44
push:
5-
paths:
6-
- "**.zig"
5+
branches:
6+
- main
77
pull_request:
8-
paths:
9-
- "**.zig"
10-
schedule:
11-
- cron: "0 0 * * *"
8+
branches:
9+
- main
1210
workflow_dispatch:
1311

1412
jobs:
@@ -18,16 +16,11 @@ jobs:
1816
os: [ubuntu-latest]
1917
runs-on: ${{ matrix.os }}
2018
steps:
21-
- uses: actions/checkout@v3
22-
with:
23-
fetch-depth: 0
24-
submodules: recursive
25-
- uses: goto-bus-stop/setup-zig@v2
26-
with:
27-
version: master
19+
- name: Checkout
20+
uses: actions/checkout@v4
2821

29-
- run: zig version
30-
- run: zig env
22+
- name: Setup Zig
23+
uses: mlugg/setup-zig@v2
3124

3225
- name: Build
3326
run: zig build

.gitignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
/zig-out
2-
/zig-cache
3-
/saved_logs
4-
/repos
1+
zig-out
2+
zig-cache
3+
.zig-cache
4+
saved_logs
5+
repos
56
node_modules
6-
/.env
7+
.env
78
d_*.log

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ For a listing of build options, use 'zig build --help'.
3030
```
3131

3232
# .env
33-
if a .env file is present at project root or next to the exe, the following keys will be used as default values.
33+
34+
If a `.env` file is present in the current working directory, the following keys will be used as default values.
35+
3436
```console
35-
zls_path=~/repos/zls/zig-out/bin/zls
37+
zls_path=/path/to/repos/zls/zig-out/bin/zls
3638
mode=markov
37-
markov_training_dir=~/repos/zig/src
39+
markov_training_dir=/path/to/repos/zig/src
3840
```
3941

4042
this allows the project to be run with no args:
43+
4144
```console
4245
zig build run
4346
```

build.zig

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,46 @@
11
const std = @import("std");
22

33
pub fn build(b: *std.Build) void {
4-
const zig_lsp = b.dependency("zig-lsp", .{}).module("zig-lsp");
5-
64
const target = b.standardTargetOptions(.{});
75
const optimize = b.standardOptimizeOption(.{});
86

9-
const exe = b.addExecutable(.{
10-
.name = "sus",
11-
.root_source_file = .{ .path = "src/main.zig" },
7+
const block_len = b.option(
8+
u8,
9+
"block-len",
10+
"how many bytes to consider when predicting the next character. " ++
11+
"defaults to 8. " ++
12+
"note: this may affect performance.",
13+
) orelse 8;
14+
15+
const options = b.addOptions();
16+
options.addOption(u8, "block_len", block_len);
17+
18+
const lsp_module = b.dependency("lsp_kit", .{}).module("lsp");
19+
20+
const root_module = b.createModule(.{
21+
.root_source_file = b.path("src/main.zig"),
1222
.target = target,
1323
.optimize = optimize,
24+
.imports = &.{
25+
.{ .name = "lsp", .module = lsp_module },
26+
.{ .name = "build_options", .module = options.createModule() },
27+
},
28+
});
29+
30+
const exe = b.addExecutable(.{
31+
.name = "sus",
32+
.root_module = root_module,
1433
});
15-
exe.root_module.addImport("zig-lsp", zig_lsp);
1634
b.installArtifact(exe);
1735

36+
const exe_check = b.addExecutable(.{
37+
.name = "zls",
38+
.root_module = root_module,
39+
});
40+
41+
const check = b.step("check", "Check if sus compiles");
42+
check.dependOn(&exe_check.step);
43+
1844
const run_cmd = b.addRunArtifact(exe);
1945
run_cmd.step.dependOn(b.getInstallStep());
2046
if (b.args) |args| {
@@ -23,25 +49,4 @@ pub fn build(b: *std.Build) void {
2349

2450
const run_step = b.step("run", "Run the app");
2551
run_step.dependOn(&run_cmd.step);
26-
27-
const build_exe_tests = b.addTest(.{
28-
.root_source_file = .{ .path = "src/main.zig" },
29-
.target = target,
30-
.optimize = .Debug,
31-
});
32-
const run_exe_tests = b.addRunArtifact(build_exe_tests);
33-
34-
const test_step = b.step("test", "Run unit tests");
35-
test_step.dependOn(&run_exe_tests.step);
36-
37-
const block_len = b.option(
38-
u8,
39-
"block-len",
40-
"how many bytes to consider when predicting the next character. " ++
41-
"defaults to 8. " ++
42-
"note: this may affect performance.",
43-
) orelse 8;
44-
const options = b.addOptions();
45-
options.addOption(u8, "block_len", block_len);
46-
exe.root_module.addOptions("build_options", options);
4752
}

build.zig.zon

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
.{
2-
.name = "sus",
2+
.name = .sus,
33
.version = "0.1.0",
4+
.minimum_zig_version = "0.15.0-dev.1593+399bace2f",
45
.dependencies = .{
5-
.@"zig-lsp" = .{
6-
.url = "https://github.com/ziglibs/zig-lsp/archive/1c18c0c64b076e79385e525214a7acc4fdf7d398.tar.gz",
7-
.hash = "12208c1385f4c1adca29fd17cc93397a60e54d5987bb27b9f961cb1945a96fc4a7e1",
6+
.lsp_kit = .{
7+
.url = "git+https://github.com/zigtools/lsp-kit#6031c563c1e1f30e7e2857fcd81a5d06e4a0c099",
8+
.hash = "lsp_kit-0.1.0-bi_PL5YyCgA2QFEza6llr2Uy08QUQsWBu2wKvtr8tbLx",
89
},
910
},
1011
.paths = .{
@@ -14,4 +15,5 @@
1415
"LICENSE",
1516
"README.md",
1617
},
18+
.fingerprint = 0x32b2a22ef62d2b4b, // Changing this has security and trust implications.
1719
}

server/index.ejs

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>sus</title>
7+
8+
<style>
9+
:root {
10+
--bg: hsl(0, 0%, 10%);
11+
--fg: hsl(0, 0%, 90%);
12+
}
13+
14+
html, body {
15+
margin: 0;
16+
padding: 0;
17+
18+
color: var(--fg);
19+
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
20+
background-color: var(--bg);
21+
}
22+
23+
main {
24+
padding: 2rem;
25+
}
26+
27+
h1 {
28+
margin: 0;
29+
}
30+
31+
table, th, td {
32+
border: 1px solid var(--fg);
33+
border-collapse: collapse;
34+
}
35+
36+
th, td {
37+
padding: 0.45rem 0.3rem;
38+
}
39+
40+
#entries {
41+
list-style: none;
42+
margin: 0;
43+
padding: 0;
44+
}
45+
46+
#entries>li {
47+
margin-top: 1rem;
48+
49+
border: 1.5px solid var(--fg);
50+
border-radius: 5px;
51+
}
52+
53+
header {
54+
display: flex;
55+
align-items: center;
56+
justify-content: space-between;
57+
padding: 1rem;
58+
font-size: 14pt;
59+
cursor: pointer;
60+
}
61+
</style>
62+
</head>
63+
<body>
64+
<main>
65+
<h1>Zig Language Server Fuzzer</h1>
66+
67+
<p>Note that results are not expected to be long-lasting. When documenting a result, copy the reproduction steps.</p>
68+
69+
<ul id="entries">
70+
<% for (const entry of entries) { %>
71+
<li>
72+
<article>
73+
<header>
74+
<code><%= entry.stderr.slice(0, entry.stderr.indexOf("\n")) %></code>
75+
<time datetime="<%= new Date(entry.created_at).toISOString() %>"></time>
76+
</header>
77+
</article>
78+
</li>
79+
<% } %>
80+
</ul>
81+
</main>
82+
83+
<script>
84+
const units = [
85+
{unit: "year", ms: 31536000000},
86+
{unit: "month", ms: 2628000000},
87+
{unit: "day", ms: 86400000},
88+
{unit: "hour", ms: 3600000},
89+
{unit: "minute", ms: 60000},
90+
{unit: "second", ms: 1000},
91+
];
92+
const rtf = new Intl.RelativeTimeFormat("en", {numeric: "auto"});
93+
94+
function relativeTimeFromDates(relative, pivot = new Date()) {
95+
if (!relative) return "";
96+
const elapsed = relative.getTime() - pivot.getTime();
97+
return relativeTimeFromElapsed(elapsed);
98+
}
99+
100+
function relativeTimeFromElapsed(elapsed) {
101+
for (const {unit, ms} of units) {
102+
if (Math.abs(elapsed) >= ms || unit === "second") {
103+
return rtf.format(Math.round(elapsed / ms), unit);
104+
}
105+
}
106+
return "";
107+
}
108+
109+
110+
[...document.querySelectorAll("time")].map(_ => _.innerText = relativeTimeFromDates(new Date(_.dateTime)));
111+
</script>
112+
</body>
113+
</html>

0 commit comments

Comments
 (0)