Skip to content

Commit bd5d2c0

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

4 files changed

Lines changed: 92 additions & 13 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 & 9 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, try init.environ.createMap(arena));
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,18 @@ 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(
96+
arena: std.mem.Allocator,
97+
threaded: *std.Io.Threaded,
98+
args: []const [:0]const u8,
99+
environ_map: if (@hasDecl(std.process, "Environ")) std.process.Environ.Map else void,
100+
) !void {
55101
const io = threaded.ioBasic();
56102

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

66112
const cwd: std.Io.Dir = .cwd();
113+
const cwd_path = try std.process.getCwdAlloc(arena);
67114

68115
const zig_lib_directory: std.Build.Cache.Directory = .{
69116
.path = zig_lib_dir,
@@ -85,7 +132,7 @@ pub fn main() !void {
85132
.handle = try cwd.createDirPathOpen(io, global_cache_root, .{}),
86133
};
87134

88-
var graph: std.Build.Graph = .{
135+
var graph: std.Build.Graph = if (has_process_env) .{
89136
.io = io,
90137
.arena = arena,
91138
.cache = .{
@@ -102,6 +149,24 @@ pub fn main() !void {
102149
.result = try std.zig.system.resolveTargetQuery(io, .{}),
103150
},
104151
.time_report = false,
152+
} else .{
153+
.io = io,
154+
.arena = arena,
155+
.cache = .{
156+
.io = io,
157+
.gpa = arena,
158+
.manifest_dir = try local_cache_directory.handle.createDirPathOpen(io, "h", .{}),
159+
.cwd = cwd_path,
160+
},
161+
.zig_exe = zig_exe,
162+
.environ_map = environ_map,
163+
.global_cache_root = global_cache_directory,
164+
.zig_lib_directory = zig_lib_directory,
165+
.host = .{
166+
.query = .{},
167+
.result = try std.zig.system.resolveTargetQuery(io, .{}),
168+
},
169+
.time_report = false,
105170
};
106171

107172
graph.cache.addPrefix(.{ .path = null, .handle = cwd });
@@ -388,7 +453,7 @@ pub fn main() !void {
388453
return;
389454
}
390455

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

393458
const message_thread = try std.Thread.spawn(.{}, struct {
394459
fn do(ww: *Watch) void {
@@ -475,10 +540,24 @@ const Watch = struct {
475540
manual_event: std.Io.Event,
476541
steps: []const *Step,
477542

478-
fn init(io: std.Io) !Watch {
543+
fn init(io: std.Io, cwd_path: []const u8) !Watch {
544+
const std_build_watch_status: enum {
545+
unimplemented,
546+
v1,
547+
v2,
548+
} = if (@TypeOf(std.Build.Watch) == void)
549+
.unimplemented
550+
else if (@typeInfo(@TypeOf(std.Build.Watch.init)).@"fn".params.len == 0)
551+
.v1
552+
else
553+
.v2;
479554
return .{
480555
.io = io,
481-
.fs_watch = if (@TypeOf(std.Build.Watch) != void) try std.Build.Watch.init() else {},
556+
.fs_watch = switch (std_build_watch_status) {
557+
.unimplemented => {},
558+
.v1 => try std.Build.Watch.init(),
559+
.v2 => try std.Build.Watch.init(cwd_path),
560+
},
482561
.supports_fs_watch = @TypeOf(std.Build.Watch) != void and shared.BuildOnSaveSupport.isSupportedRuntime(builtin.zig_version) == .supported,
483562
.manual_event = .unset,
484563
.steps = &.{},
@@ -1395,7 +1474,7 @@ const copied_from_zig = struct {
13951474
pkg_name,
13961475
"--cflags",
13971476
"--libs",
1398-
}, &code, .Ignore)) |stdout| stdout else |err| switch (err) {
1477+
}, &code, process_stdio_ignore)) |stdout| stdout else |err| switch (err) {
13991478
error.ProcessTerminated => return error.PkgConfigCrashed,
14001479
error.ExecNotSupported => return error.PkgConfigFailed,
14011480
error.ExitCodeFailure => return error.PkgConfigFailed,
@@ -1437,7 +1516,7 @@ const copied_from_zig = struct {
14371516
}
14381517

14391518
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);
1519+
const stdout = try self.runAllowFail(&.{ "pkg-config", "--list-all" }, out_code, process_stdio_ignore);
14411520
var list = ArrayListManaged(std.Build.PkgConfigPkg).init(self.allocator);
14421521
errdefer list.deinit();
14431522
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)