refactor(build.zig): no need to pass around b.graph.io next to b

This commit is contained in:
bfredl
2026-06-02 21:55:12 +02:00
parent b9913e78cc
commit 2a78df3a5a
3 changed files with 9 additions and 12 deletions

View File

@@ -197,7 +197,6 @@ pub fn build(b: *std.Build) !void {
const nlua0 = try build_lua.build_nlua0(
b,
io,
target_host,
optimize_host,
host_use_luajit,
@@ -458,7 +457,6 @@ pub fn build(b: *std.Build) !void {
const gen_headers, const funcs_data = try gen.nvim_gen_sources(
b,
io,
nlua0,
&nvim_sources,
&nvim_headers,
@@ -468,7 +466,7 @@ pub fn build(b: *std.Build) !void {
);
const test_config_step = b.addWriteFiles();
_ = test_config_step.add("test/cmakeconfig/paths.lua", try test_config(b, io));
_ = test_config_step.add("test/cmakeconfig/paths.lua", try test_config(b));
const test_gen_step = b.step("gen_headers", "debug: output generated headers");
const config_install = b.addInstallDirectory(.{
@@ -535,7 +533,7 @@ pub fn build(b: *std.Build) !void {
nvim_mod.addIncludePath(b.path("src"));
nvim_mod.addIncludePath(gen_config.getDirectory());
nvim_mod.addIncludePath(gen_headers.getDirectory());
try build_lua.add_lua_modules(b, io, t, nvim_mod, lpeg, use_luajit, false, sys_opts);
try build_lua.add_lua_modules(b, t, nvim_mod, lpeg, use_luajit, false, sys_opts);
var unit_test_sources = try std.ArrayList([]u8).initCapacity(b.allocator, 10);
if (support_unittests) {
@@ -829,9 +827,9 @@ fn replace_backslashes(b: *std.Build, input: []const u8) ![]const u8 {
input;
}
pub fn test_config(b: *std.Build, io: std.Io) ![]u8 {
pub fn test_config(b: *std.Build) ![]u8 {
var buf: [std.fs.max_path_bytes]u8 = std.mem.zeroes([std.fs.max_path_bytes]u8);
_ = try b.build_root.handle.realPath(io, &buf);
_ = try b.build_root.handle.realPath(b.graph.io, &buf);
const src_path = std.mem.span(@as([*:0]u8, @ptrCast(&buf)));
// we don't use test/cmakeconfig/paths.lua.in because it contains cmake specific logic

View File

@@ -4,7 +4,6 @@ const LazyPath = std.Build.LazyPath;
pub fn build_nlua0(
b: *std.Build,
io: std.Io,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
use_luajit: bool,
@@ -60,7 +59,7 @@ pub fn build_nlua0(
mod.addIncludePath(b.path("src"));
mod.addIncludePath(b.path("src/includes_fixmelater"));
try add_lua_modules(b, io, target.result, mod, lpeg, use_luajit, true, system_integration_options);
try add_lua_modules(b, target.result, mod, lpeg, use_luajit, true, system_integration_options);
}
// for debugging the nlua0 environment
@@ -84,7 +83,6 @@ pub fn build_nlua0(
pub fn add_lua_modules(
b: *std.Build,
io: std.Io,
target: std.Target,
mod: *std.Build.Module,
lpeg_dep: ?*std.Build.Dependency,
@@ -112,7 +110,7 @@ pub fn add_lua_modules(
.flags = &flags,
});
if (system_integration_options.lpeg) {
if (try findLpeg(b, io, target)) |lpeg_lib| {
if (try findLpeg(b, target)) |lpeg_lib| {
mod.addLibraryPath(.{ .cwd_relative = std.fs.path.dirname(lpeg_lib).? });
mod.addObjectFile(.{ .cwd_relative = lpeg_lib });
}
@@ -186,7 +184,7 @@ pub fn build_libluv(
return lib;
}
fn findLpeg(b: *std.Build, io: std.Io, target: std.Target) !?[]const u8 {
fn findLpeg(b: *std.Build, target: std.Target) !?[]const u8 {
const filenames = [_][]const u8{
"lpeg_a",
"lpeg",
@@ -207,6 +205,7 @@ fn findLpeg(b: *std.Build, io: std.Io, target: std.Target) !?[]const u8 {
try paths.append(b.allocator, dir);
try paths.append(b.allocator, b.fmt("{s}/lua/5.1", .{dir}));
}
const io = b.graph.io;
for (paths.items) |path| {
var dir = std.Io.Dir.openDirAbsolute(io, path, .{}) catch continue;
defer dir.close(io);

View File

@@ -5,7 +5,6 @@ pub const SourceItem = struct { name: []u8, api_export: bool };
pub fn nvim_gen_sources(
b: *std.Build,
io: std.Io,
nlua0: *std.Build.Step.Compile,
nvim_sources: *std.ArrayList(SourceItem),
nvim_headers: *std.ArrayList([]u8),
@@ -86,6 +85,7 @@ pub fn nvim_gen_sources(
}
// Dynamically add all Lua _core/ modules (like CMakeLists.txt does)
const io = b.graph.io;
if (b.build_root.handle.openDir(io, "runtime/lua/vim/_core", .{ .iterate = true })) |core_dir_handle| {
var core_dir = core_dir_handle;
defer core_dir.close(io);