Skip to content

Commit 7b47bb0

Browse files
committed
update to zig 0.15.0-dev.1593+399bace2f
1 parent 121155c commit 7b47bb0

File tree

11 files changed

+217
-292
lines changed

11 files changed

+217
-292
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/checkout@v4
2121

2222
- name: Setup Zig
23-
uses: mlugg/setup-zig@v1
23+
uses: mlugg/setup-zig@v2
2424

2525
- name: Build
2626
run: zig build

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: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,31 @@ pub fn build(b: *std.Build) void {
1515
const options = b.addOptions();
1616
options.addOption(u8, "block_len", block_len);
1717

18-
const lsp_module = b.dependency("lsp_codegen", .{}).module("lsp");
18+
const lsp_module = b.dependency("lsp_kit", .{}).module("lsp");
1919

20-
const exe = b.addExecutable(.{
21-
.name = "sus",
20+
const root_module = b.createModule(.{
2221
.root_source_file = b.path("src/main.zig"),
2322
.target = target,
2423
.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,
2533
});
2634
b.installArtifact(exe);
27-
exe.root_module.addImport("lsp", lsp_module);
28-
exe.root_module.addOptions("build_options", options);
35+
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);
2943

3044
const run_cmd = b.addRunArtifact(exe);
3145
run_cmd.step.dependOn(b.getInstallStep());

build.zig.zon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
.{
22
.name = .sus,
33
.version = "0.1.0",
4-
.minimum_zig_version = "0.14.0",
4+
.minimum_zig_version = "0.15.0-dev.1593+399bace2f",
55
.dependencies = .{
6-
.lsp_codegen = .{
7-
.url = "git+https://github.com/zigtools/zig-lsp-codegen.git#30ccbd10fec9c4eaad5196f2d560b80d6cc2c078",
8-
.hash = "lsp_codegen-0.1.0-CMjjo9nOCQA7rKs_uLFYA6A2FQ7hRqwXeID0CRnql0AD",
6+
.lsp_kit = .{
7+
.url = "git+https://github.com/zigtools/lsp-kit#6031c563c1e1f30e7e2857fcd81a5d06e4a0c099",
8+
.hash = "lsp_kit-0.1.0-bi_PL5YyCgA2QFEza6llr2Uy08QUQsWBu2wKvtr8tbLx",
99
},
1010
},
1111
.paths = .{

src/Fuzzer.zig

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ pub const Config = struct {
1717
mode_name: ModeName,
1818
cycles_per_gen: u32,
1919

20-
zig_env: std.json.Parsed(ZigEnv),
20+
zig_env_arena: std.heap.ArenaAllocator.State,
21+
zig_env: ZigEnv,
2122
zls_version: []const u8,
2223

2324
pub const Defaults = struct {
@@ -35,7 +36,7 @@ pub const Config = struct {
3536
};
3637

3738
pub fn deinit(self: *Config, allocator: std.mem.Allocator) void {
38-
self.zig_env.deinit();
39+
self.zig_env_arena.promote(allocator).deinit();
3940
allocator.free(self.zls_path);
4041
allocator.free(self.zls_version);
4142
self.* = undefined;
@@ -58,11 +59,12 @@ cycle: usize = 0,
5859
zls_process: std.process.Child,
5960
id: i64 = 0,
6061

61-
transport: lsp.TransportOverStdio,
62+
transport_read_buffer: [256]u8 = undefined,
63+
stdio_transport: lsp.Transport.Stdio,
6264

63-
sent_data: std.ArrayListUnmanaged(u8) = .{},
64-
sent_messages: std.ArrayListUnmanaged(SentMessage) = .{},
65-
sent_ids: std.AutoArrayHashMapUnmanaged(i64, void) = .{},
65+
sent_data: std.ArrayList(u8) = .empty,
66+
sent_messages: std.ArrayList(SentMessage) = .empty,
67+
sent_ids: std.AutoArrayHashMapUnmanaged(i64, void) = .empty,
6668

6769
principal_file_source: []const u8 = "",
6870
principal_file_uri: []const u8,
@@ -92,7 +94,7 @@ pub fn create(
9294
else
9395
&.{ config.zls_path, "--log-file", if (builtin.target.os.tag == .windows) "nul" else "/dev/null", "--disable-lsp-logs" };
9496

95-
var zls_process = std.process.Child.init(argv, allocator);
97+
var zls_process: std.process.Child = .init(argv, allocator);
9698
zls_process.env_map = &env_map;
9799
zls_process.stdin_behavior = .Pipe;
98100
zls_process.stderr_behavior = .Ignore;
@@ -101,17 +103,17 @@ pub fn create(
101103
try zls_process.spawn();
102104
errdefer _ = zls_process.kill() catch @panic("failed to kill zls process");
103105

104-
var sent_ids = std.AutoArrayHashMapUnmanaged(i64, void){};
106+
var sent_ids: std.AutoArrayHashMapUnmanaged(i64, void) = .empty;
105107
try sent_ids.ensureTotalCapacity(allocator, config.cycles_per_gen);
106108

107109
fuzzer.* = .{
108110
.allocator = allocator,
109111
.progress_node = progress.start("fuzzer", 0),
110112
.mode = mode,
111113
.config = config,
112-
.rand = std.Random.DefaultPrng.init(seed),
114+
.rand = .init(seed),
113115
.zls_process = zls_process,
114-
.transport = lsp.TransportOverStdio.init(zls_process.stdout.?, zls_process.stdin.?),
116+
.stdio_transport = .init(&fuzzer.transport_read_buffer, zls_process.stdout.?, zls_process.stdin.?),
115117
.sent_ids = sent_ids,
116118
.principal_file_uri = principal_file_uri,
117119
};
@@ -148,10 +150,10 @@ pub fn initCycle(fuzzer: *Fuzzer) !void {
148150
});
149151
try fuzzer.sendNotification("initialized", .{});
150152

151-
var settings = std.json.ObjectMap.init(fuzzer.allocator);
153+
var settings: std.json.ObjectMap = .init(fuzzer.allocator);
152154
defer settings.deinit();
153155
try settings.putNoClobber("skip_std_references", .{ .bool = true }); // references collection into std is very slow
154-
try settings.putNoClobber("zig_exe_path", .{ .string = fuzzer.config.zig_env.value.zig_exe });
156+
try settings.putNoClobber("zig_exe_path", .{ .string = fuzzer.config.zig_env.zig_exe });
155157

156158
try fuzzer.sendNotification("workspace/didChangeConfiguration", lsp.types.DidChangeConfigurationParams{
157159
.settings = .{ .object = settings },
@@ -177,7 +179,7 @@ pub fn closeCycle(fuzzer: *Fuzzer) !void {
177179
}
178180

179181
pub fn reduce(fuzzer: *Fuzzer) !void {
180-
var reducer = Reducer.fromFuzzer(fuzzer);
182+
var reducer: Reducer = .fromFuzzer(fuzzer);
181183
defer reducer.deinit();
182184

183185
try reducer.reduce();
@@ -190,7 +192,7 @@ pub fn fuzz(fuzzer: *Fuzzer) !void {
190192
// detch from cycle count to prevent pipe fillage on windows
191193
try utils.waitForResponseToRequests(
192194
fuzzer.allocator,
193-
&fuzzer.transport,
195+
&fuzzer.stdio_transport.transport,
194196
&fuzzer.sent_ids,
195197
);
196198

@@ -239,7 +241,7 @@ pub fn fuzzFeatureRandom(
239241
fuzzer: *Fuzzer,
240242
file_uri: []const u8,
241243
file_data: []const u8,
242-
) (lsp.AnyTransport.WriteError || error{OutOfMemory})!void {
244+
) (lsp.Transport.WriteError || error{OutOfMemory})!void {
243245
const rand = fuzzer.random();
244246
const wtf = rand.enumValue(WhatToFuzz);
245247

@@ -289,7 +291,7 @@ pub fn fuzzFeatureRandom(
289291
}
290292
}
291293

292-
fn sendRequest(fuzzer: *Fuzzer, comptime method: []const u8, params: lsp.ParamsType(method)) (lsp.AnyTransport.WriteError || error{OutOfMemory})!void {
294+
fn sendRequest(fuzzer: *Fuzzer, comptime method: []const u8, params: lsp.ParamsType(method)) (lsp.Transport.WriteError || error{OutOfMemory})!void {
293295
defer fuzzer.id += 1;
294296

295297
const request: lsp.TypedJsonRPCRequest(lsp.ParamsType(method)) = .{
@@ -299,8 +301,12 @@ fn sendRequest(fuzzer: *Fuzzer, comptime method: []const u8, params: lsp.ParamsT
299301
};
300302

301303
const start = fuzzer.sent_data.items.len;
302-
try std.json.stringify(request, .{ .emit_null_optional_fields = false }, fuzzer.sent_data.writer(fuzzer.allocator));
303-
try fuzzer.transport.writeJsonMessage(fuzzer.sent_data.items[start..]);
304+
{
305+
var aw: std.Io.Writer.Allocating = .fromArrayList(fuzzer.allocator, &fuzzer.sent_data);
306+
defer fuzzer.sent_data = aw.toArrayList();
307+
std.json.Stringify.value(request, .{ .emit_null_optional_fields = false }, &aw.writer) catch return error.OutOfMemory;
308+
}
309+
try fuzzer.stdio_transport.transport.writeJsonMessage(fuzzer.sent_data.items[start..]);
304310

305311
try fuzzer.sent_messages.append(fuzzer.allocator, .{
306312
.id = fuzzer.id,
@@ -311,13 +317,17 @@ fn sendRequest(fuzzer: *Fuzzer, comptime method: []const u8, params: lsp.ParamsT
311317
fuzzer.sent_ids.putAssumeCapacityNoClobber(fuzzer.id, {});
312318
}
313319

314-
fn sendNotification(fuzzer: *Fuzzer, comptime method: []const u8, params: lsp.ParamsType(method)) (lsp.AnyTransport.WriteError || error{OutOfMemory})!void {
320+
fn sendNotification(fuzzer: *Fuzzer, comptime method: []const u8, params: lsp.ParamsType(method)) (lsp.Transport.WriteError || error{OutOfMemory})!void {
315321
const notification: lsp.TypedJsonRPCNotification(lsp.ParamsType(method)) = .{
316322
.method = method,
317323
.params = params,
318324
};
319325

320326
const start = fuzzer.sent_data.items.len;
321-
try std.json.stringify(notification, .{ .emit_null_optional_fields = false }, fuzzer.sent_data.writer(fuzzer.allocator));
322-
try fuzzer.transport.writeJsonMessage(fuzzer.sent_data.items[start..]);
327+
{
328+
var aw: std.Io.Writer.Allocating = .fromArrayList(fuzzer.allocator, &fuzzer.sent_data);
329+
defer fuzzer.sent_data = aw.toArrayList();
330+
std.json.Stringify.value(notification, .{ .emit_null_optional_fields = false }, &aw.writer) catch return error.OutOfMemory;
331+
}
332+
try fuzzer.stdio_transport.transport.writeJsonMessage(fuzzer.sent_data.items[start..]);
323333
}

0 commit comments

Comments
 (0)