Skip to content

Commit 359d9b1

Browse files
committed
feat: support 0.16.0-dev.1976+8e091047b
1 parent 26e0192 commit 359d9b1

4 files changed

Lines changed: 92 additions & 27 deletions

File tree

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fn getVersion(b: *Build) std.SemanticVersion {
345345
"git", "-C", b.pathFromRoot("."), "--git-dir", ".git", "describe", "--match", "*.*.*", "--tags",
346346
};
347347
var code: u8 = undefined;
348-
const git_describe_untrimmed = b.runAllowFail(argv, &code, .Ignore) catch |err| {
348+
const git_describe_untrimmed = b.runAllowFail(argv, &code, .ignore) catch |err| {
349349
const argv_joined = std.mem.join(b.allocator, " ", argv) catch @panic("OOM");
350350
std.log.warn(
351351
\\Failed to run git describe to resolve ZLS version: {}

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// nix flake update --commit-lock-file
1111
// ```
1212
// If you do not use Nix, a ZLS maintainer can take care of this.
13-
.minimum_zig_version = "0.16.0-dev.1912+0cbaaa5eb",
13+
.minimum_zig_version = "0.16.0-dev.1976+8e091047b",
1414
// If you do not use Nix, a ZLS maintainer can take care of this.
1515
// Whenever the dependencies are updated, run the following command:
1616
// ```bash

src/build_runner/build_runner.zig

Lines changed: 88 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ const ArrayList = if (@hasDecl(std, "array_list")) std.ArrayList else std.ArrayL
2626
const Step = std.Build.Step;
2727
const Allocator = std.mem.Allocator;
2828

29+
const has_process_env = @import("builtin").zig_version.order(.{
30+
.major = 0,
31+
.minor = 16,
32+
.patch = 0,
33+
.pre = "dev.1976",
34+
}) == .lt;
35+
const process_stdio_ignore: std.process.SpawnOptions.StdIo =
36+
if (@hasField(std.process.SpawnOptions.StdIo, "Ignore"))
37+
.Ignore
38+
else
39+
.ignore;
40+
2941
pub const dependencies = @import("@dependencies");
3042

3143
pub const std_options: std.Options = .{
@@ -34,9 +46,31 @@ pub const std_options: std.Options = .{
3446
.crypto_fork_safety = false,
3547
};
3648

37-
///! This is a modified build runner to extract information out of build.zig
38-
///! Modified version of lib/build_runner.zig
39-
pub fn main() !void {
49+
pub const main = if (has_process_env) @"main < dev.1976" else @"main >= dev.1976";
50+
51+
fn @"main >= dev.1976"(init: std.process.Init.Minimal) !void {
52+
// Here we use an ArenaAllocator backed by a DirectAllocator because a build is a short-lived,
53+
// one shot program. We don't need to waste time freeing memory and finding places to squish
54+
// bytes into. So we free everything all at once at the very end.
55+
var single_threaded_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
56+
defer single_threaded_arena.deinit();
57+
58+
var thread_safe_arena: std.heap.ThreadSafeAllocator = .{
59+
.child_allocator = single_threaded_arena.allocator(),
60+
};
61+
const arena = thread_safe_arena.allocator();
62+
63+
const args = try init.args.toSlice(arena);
64+
65+
var threaded: std.Io.Threaded = .init(arena, .{
66+
.environ = init.environ,
67+
});
68+
defer threaded.deinit();
69+
70+
try doMain(arena, &threaded, args);
71+
}
72+
73+
fn @"main < dev.1976"() !void {
4074
// Here we use an ArenaAllocator backed by a DirectAllocator because a build is a short-lived,
4175
// one shot program. We don't need to waste time freeing memory and finding places to squish
4276
// bytes into. So we free everything all at once at the very end.
@@ -52,6 +86,13 @@ pub fn main() !void {
5286

5387
var threaded: std.Io.Threaded = .init(arena, .{});
5488
defer threaded.deinit();
89+
90+
try doMain(arena, &threaded, args);
91+
}
92+
93+
///! This is a modified build runner to extract information out of build.zig
94+
///! Modified version of lib/build_runner.zig
95+
fn doMain(arena: std.mem.Allocator, threaded: *std.Io.Threaded, args: []const [:0]const u8) !void {
5596
const io = threaded.ioBasic();
5697

5798
// skip my own exe name
@@ -64,6 +105,7 @@ pub fn main() !void {
64105
const global_cache_root = nextArg(args, &arg_idx) orelse fatal("missing global cache root directory path", .{});
65106

66107
const cwd: std.Io.Dir = .cwd();
108+
const cwd_path = try std.process.getCwdAlloc(arena);
67109

68110
const zig_lib_directory: std.Build.Cache.Directory = .{
69111
.path = zig_lib_dir,
@@ -85,24 +127,33 @@ pub fn main() !void {
85127
.handle = try cwd.createDirPathOpen(io, global_cache_root, .{}),
86128
};
87129

88-
var graph: std.Build.Graph = .{
89-
.io = io,
90-
.arena = arena,
91-
.cache = .{
130+
var graph: std.Build.Graph = undefined;
131+
graph.io = io;
132+
graph.arena = arena;
133+
graph.zig_exe = zig_exe;
134+
graph.global_cache_root = global_cache_directory;
135+
graph.zig_lib_directory = zig_lib_directory;
136+
graph.host = .{
137+
.query = .{},
138+
.result = try std.zig.system.resolveTargetQuery(io, .{}),
139+
};
140+
graph.time_report = false;
141+
142+
if (has_process_env) {
143+
graph.env_map = try process.getEnvMap(arena);
144+
graph.cache = .{
92145
.io = io,
93146
.gpa = arena,
94147
.manifest_dir = try local_cache_directory.handle.createDirPathOpen(io, "h", .{}),
95-
},
96-
.zig_exe = zig_exe,
97-
.env_map = try process.getEnvMap(arena),
98-
.global_cache_root = global_cache_directory,
99-
.zig_lib_directory = zig_lib_directory,
100-
.host = .{
101-
.query = .{},
102-
.result = try std.zig.system.resolveTargetQuery(io, .{}),
103-
},
104-
.time_report = false,
105-
};
148+
};
149+
} else {
150+
graph.cache = .{
151+
.io = io,
152+
.gpa = arena,
153+
.manifest_dir = try local_cache_directory.handle.createDirPathOpen(io, "h", .{}),
154+
.cwd = cwd_path,
155+
};
156+
}
106157

107158
graph.cache.addPrefix(.{ .path = null, .handle = cwd });
108159
graph.cache.addPrefix(build_root_directory);
@@ -388,7 +439,7 @@ pub fn main() !void {
388439
return;
389440
}
390441

391-
var w = try Watch.init(io);
442+
var w = try Watch.init(io, cwd_path);
392443

393444
const message_thread = try std.Thread.spawn(.{}, struct {
394445
fn do(ww: *Watch) void {
@@ -475,10 +526,24 @@ const Watch = struct {
475526
manual_event: std.Io.Event,
476527
steps: []const *Step,
477528

478-
fn init(io: std.Io) !Watch {
529+
fn init(io: std.Io, cwd_path: []const u8) !Watch {
530+
const std_build_watch_status: enum {
531+
unimplemented,
532+
v1,
533+
v2,
534+
} = if (@TypeOf(std.Build.Watch) == void)
535+
.unimplemented
536+
else if (@typeInfo(@TypeOf(std.Build.Watch.init)).@"fn".params.len == 0)
537+
.v1
538+
else
539+
.v2;
479540
return .{
480541
.io = io,
481-
.fs_watch = if (@TypeOf(std.Build.Watch) != void) try std.Build.Watch.init() else {},
542+
.fs_watch = switch (std_build_watch_status) {
543+
.unimplemented => {},
544+
.v1 => try std.Build.Watch.init(),
545+
.v2 => try std.Build.Watch.init(cwd_path),
546+
},
482547
.supports_fs_watch = @TypeOf(std.Build.Watch) != void and shared.BuildOnSaveSupport.isSupportedRuntime(builtin.zig_version) == .supported,
483548
.manual_event = .unset,
484549
.steps = &.{},
@@ -1395,7 +1460,7 @@ const copied_from_zig = struct {
13951460
pkg_name,
13961461
"--cflags",
13971462
"--libs",
1398-
}, &code, .Ignore)) |stdout| stdout else |err| switch (err) {
1463+
}, &code, process_stdio_ignore)) |stdout| stdout else |err| switch (err) {
13991464
error.ProcessTerminated => return error.PkgConfigCrashed,
14001465
error.ExecNotSupported => return error.PkgConfigFailed,
14011466
error.ExitCodeFailure => return error.PkgConfigFailed,
@@ -1437,7 +1502,7 @@ const copied_from_zig = struct {
14371502
}
14381503

14391504
fn execPkgConfigList(self: *std.Build, out_code: *u8) (std.Build.PkgConfigError || std.Build.RunError)![]const std.Build.PkgConfigPkg {
1440-
const stdout = try self.runAllowFail(&.{ "pkg-config", "--list-all" }, out_code, .Ignore);
1505+
const stdout = try self.runAllowFail(&.{ "pkg-config", "--list-all" }, out_code, process_stdio_ignore);
14411506
var list = ArrayListManaged(std.Build.PkgConfigPkg).init(self.allocator);
14421507
errdefer list.deinit();
14431508
var line_it = mem.tokenizeAny(u8, stdout, "\r\n");

src/tools/config_gen.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,15 +1010,15 @@ fn generateVersionDataFile(
10101010
try file_writer.end();
10111011
}
10121012

1013-
pub fn main() !void {
1013+
pub fn main(init: std.process.Init.Minimal) !void {
10141014
var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
10151015
defer _ = debug_allocator.deinit();
10161016
const gpa = debug_allocator.allocator();
10171017

10181018
var threaded: std.Io.Threaded = .init_single_threaded;
10191019
const io = threaded.io();
10201020

1021-
var args_it = try std.process.argsWithAllocator(gpa);
1021+
var args_it = try init.args.iterateAllocator(gpa);
10221022
defer args_it.deinit();
10231023

10241024
_ = args_it.skip();

0 commit comments

Comments
 (0)