Skip to content

Commit af8f778

Browse files
committed
Properly handle lazy dependencies
It is incorrect to return early from the script from a lazyDependency call. That meant the module was never built and the build would fail.
1 parent ac577d6 commit af8f778

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

build.zig

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ pub fn build(b: *Build) void {
2323
const shared = b.option(bool, "shared", "Build shared library instead of static") orelse false;
2424
const luau_use_4_vector = b.option(bool, "luau_use_4_vector", "Build Luau to use 4-vectors instead of the default 3-vector.") orelse false;
2525

26-
const upstream = b.lazyDependency(@tagName(lang), .{}) orelse return;
27-
2826
if (lang == .luau and shared) {
2927
std.debug.panic("Luau does not support compiling or loading shared modules", .{});
3028
}
@@ -45,27 +43,31 @@ pub fn build(b: *Build) void {
4543
ziglua.addCMacro("LUA_VECTOR_SIZE", b.fmt("{}", .{vector_size}));
4644
}
4745

48-
const lib = switch (lang) {
49-
.luajit => buildLuaJIT(b, target, optimize, upstream, shared),
50-
.luau => buildLuau(b, target, optimize, upstream, luau_use_4_vector),
51-
else => buildLua(b, target, optimize, upstream, lang, shared),
52-
};
53-
54-
// Expose the Lua artifact
55-
b.installArtifact(lib);
56-
57-
switch (lang) {
58-
.luau => {
59-
ziglua.addIncludePath(upstream.path("Common/include"));
60-
ziglua.addIncludePath(upstream.path("Compiler/include"));
61-
ziglua.addIncludePath(upstream.path("Ast/include"));
62-
ziglua.addIncludePath(upstream.path("VM/include"));
63-
},
64-
else => ziglua.addIncludePath(upstream.path("src")),
46+
luadep: {
47+
const upstream = b.lazyDependency(@tagName(lang), .{}) orelse break :luadep;
48+
49+
const lib = switch (lang) {
50+
.luajit => buildLuaJIT(b, target, optimize, upstream, shared),
51+
.luau => buildLuau(b, target, optimize, upstream, luau_use_4_vector),
52+
else => buildLua(b, target, optimize, upstream, lang, shared),
53+
};
54+
55+
// Expose the Lua artifact
56+
b.installArtifact(lib);
57+
58+
switch (lang) {
59+
.luau => {
60+
ziglua.addIncludePath(upstream.path("Common/include"));
61+
ziglua.addIncludePath(upstream.path("Compiler/include"));
62+
ziglua.addIncludePath(upstream.path("Ast/include"));
63+
ziglua.addIncludePath(upstream.path("VM/include"));
64+
},
65+
else => ziglua.addIncludePath(upstream.path("src")),
66+
}
67+
68+
ziglua.linkLibrary(lib);
6569
}
6670

67-
ziglua.linkLibrary(lib);
68-
6971
// Tests
7072
const tests = b.addTest(.{
7173
.root_source_file = .{ .path = "src/tests.zig" },

0 commit comments

Comments
 (0)