Skip to content

Commit ca0a438

Browse files
committed
Make dependencies lazy
1 parent 7e57394 commit ca0a438

File tree

2 files changed

+50
-44
lines changed

2 files changed

+50
-44
lines changed

build.zig

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -39,53 +39,53 @@ pub fn build(b: *Build) void {
3939
zlua.addCMacro("LUA_VECTOR_SIZE", b.fmt("{}", .{vector_size}));
4040
}
4141

42-
const upstream = b.dependency(@tagName(lang), .{});
43-
44-
const lib = switch (lang) {
45-
.luajit => luajit_setup.configure(b, target, optimize, upstream, shared),
46-
.luau => luau_setup.configure(b, target, optimize, upstream, luau_use_4_vector),
47-
else => lua_setup.configure(b, target, optimize, upstream, lang, shared),
48-
};
42+
if (b.lazyDependency(@tagName(lang), .{})) |upstream| {
43+
const lib = switch (lang) {
44+
.luajit => luajit_setup.configure(b, target, optimize, upstream, shared),
45+
.luau => luau_setup.configure(b, target, optimize, upstream, luau_use_4_vector),
46+
else => lua_setup.configure(b, target, optimize, upstream, lang, shared),
47+
};
48+
49+
// Expose the Lua artifact, and get an install step that header translation can refer to
50+
const install_lib = b.addInstallArtifact(lib, .{});
51+
b.getInstallStep().dependOn(&install_lib.step);
52+
53+
switch (lang) {
54+
.luau => {
55+
zlua.addIncludePath(upstream.path("Common/include"));
56+
zlua.addIncludePath(upstream.path("Compiler/include"));
57+
zlua.addIncludePath(upstream.path("Ast/include"));
58+
zlua.addIncludePath(upstream.path("VM/include"));
59+
},
60+
else => zlua.addIncludePath(upstream.path("src")),
61+
}
62+
63+
zlua.linkLibrary(lib);
64+
65+
// lib must expose all headers included by these root headers
66+
const c_header_path = switch (lang) {
67+
.luajit => b.path("include/luajit_all.h"),
68+
.luau => b.path("include/luau_all.h"),
69+
else => b.path("include/lua_all.h"),
70+
};
71+
const c_headers = b.addTranslateC(.{
72+
.root_source_file = c_header_path,
73+
.target = target,
74+
.optimize = optimize,
75+
});
76+
c_headers.addIncludePath(lib.getEmittedIncludeTree());
77+
c_headers.step.dependOn(&install_lib.step);
78+
79+
const ziglua_c = b.addModule("ziglua-c", .{
80+
.root_source_file = c_headers.getOutput(),
81+
.target = c_headers.target,
82+
.optimize = c_headers.optimize,
83+
.link_libc = c_headers.link_libc,
84+
});
4985

50-
// Expose the Lua artifact, and get an install step that header translation can refer to
51-
const install_lib = b.addInstallArtifact(lib, .{});
52-
b.getInstallStep().dependOn(&install_lib.step);
53-
54-
switch (lang) {
55-
.luau => {
56-
zlua.addIncludePath(upstream.path("Common/include"));
57-
zlua.addIncludePath(upstream.path("Compiler/include"));
58-
zlua.addIncludePath(upstream.path("Ast/include"));
59-
zlua.addIncludePath(upstream.path("VM/include"));
60-
},
61-
else => zlua.addIncludePath(upstream.path("src")),
86+
zlua.addImport("c", ziglua_c);
6287
}
6388

64-
zlua.linkLibrary(lib);
65-
66-
// lib must expose all headers included by these root headers
67-
const c_header_path = switch (lang) {
68-
.luajit => b.path("include/luajit_all.h"),
69-
.luau => b.path("include/luau_all.h"),
70-
else => b.path("include/lua_all.h"),
71-
};
72-
const c_headers = b.addTranslateC(.{
73-
.root_source_file = c_header_path,
74-
.target = target,
75-
.optimize = optimize,
76-
});
77-
c_headers.addIncludePath(lib.getEmittedIncludeTree());
78-
c_headers.step.dependOn(&install_lib.step);
79-
80-
const ziglua_c = b.addModule("ziglua-c", .{
81-
.root_source_file = c_headers.getOutput(),
82-
.target = c_headers.target,
83-
.optimize = c_headers.optimize,
84-
.link_libc = c_headers.link_libc,
85-
});
86-
87-
zlua.addImport("c", ziglua_c);
88-
8989
// Tests
9090
const tests = b.addTest(.{
9191
.root_source_file = b.path("src/tests.zig"),

build.zig.zon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,37 @@
1212
.lua51 = .{
1313
.url = "https://github.com/natecraddock/lua/archive/refs/tags/5.1.5-1.tar.gz",
1414
.hash = "N-V-__8AABYiDAA_4f7ruBY1-N9aWnJCcz5EH-PzBDmJyOa0",
15+
.lazy = true,
1516
},
1617

1718
.lua52 = .{
1819
.url = "https://www.lua.org/ftp/lua-5.2.4.tar.gz",
1920
.hash = "N-V-__8AALg2DgDVsrOXOPBkTZ7Vt0MZc_Gha5N--G1M-FiH",
21+
.lazy = true,
2022
},
2123

2224
.lua53 = .{
2325
.url = "https://www.lua.org/ftp/lua-5.3.6.tar.gz",
2426
.hash = "N-V-__8AALihEACTeiI1Me9rP-qPZT3BNTELDoSAXn76FIhw",
27+
.lazy = true,
2528
},
2629

2730
.lua54 = .{
2831
.url = "https://www.lua.org/ftp/lua-5.4.7.tar.gz",
2932
.hash = "N-V-__8AAIMvFABt-Qcpk24RD10ldEN743D8Q2e19Er8x3dJ",
33+
.lazy = true,
3034
},
3135

3236
.luajit = .{
3337
.url = "https://github.com/LuaJIT/LuaJIT/archive/c525bcb9024510cad9e170e12b6209aedb330f83.tar.gz",
3438
.hash = "N-V-__8AACcgQgCuLYTPzCp6pnBmFJHyG77RAtM13hjOfTaG",
39+
.lazy = true,
3540
},
3641

3742
.luau = .{
3843
.url = "https://github.com/luau-lang/luau/archive/refs/tags/0.653.tar.gz",
3944
.hash = "N-V-__8AAFB1kwDHb7dLmDsOv91rOkqorfDB_2nJtqnp4F-b",
45+
.lazy = true,
4046
},
4147
},
4248
}

0 commit comments

Comments
 (0)