build: many more lazy dependencies, defer deps add unless needed
This makes more dependencies lazy. This has a practical effect of reducing the number of dependencies that need to be downloaded when running certain zig build steps. This is all limited because we're blocked on an upstream Zig issue: https://github.com/ziglang/zig/issues/21525 This prevents us from fully avoiding downloading many dependencies, but at least they're relatively small. One major improvement here is the usage of `lazyImport` for `zig-wayland` that prevents downloading `zig_wayland` unconditionally on all platforms. On macOS, we don't download this at all anymore. Another, weirder change is that all our transitive dependencies are now marked lazy (e.g. glslang's upstream source) even if the glslang build always requires it. This was necessary because without this, even if we simply referenced glslang in the root build.zig, it would force the source package to download unconditionally. This no longer happens.pull/8826/head
parent
fcd0f88024
commit
17498ce122
|
|
@ -45,6 +45,7 @@
|
|||
// codeberg ifreund/zig-wayland
|
||||
.url = "https://codeberg.org/ifreund/zig-wayland/archive/f3c5d503e540ada8cbcb056420de240af0c094f7.tar.gz",
|
||||
.hash = "wayland-0.4.0-dev-lQa1kjfIAQCmhhQu3xF0KH-94-TzeMXOqfnP0-Dg6Wyy",
|
||||
.lazy = true,
|
||||
},
|
||||
.zf = .{
|
||||
// natecraddock/zf
|
||||
|
|
@ -103,10 +104,12 @@
|
|||
.jetbrains_mono = .{
|
||||
.url = "https://deps.files.ghostty.org/JetBrainsMono-2.304.tar.gz",
|
||||
.hash = "N-V-__8AAIC5lwAVPJJzxnCAahSvZTIlG-HhtOvnM1uh-66x",
|
||||
.lazy = true,
|
||||
},
|
||||
.nerd_fonts_symbols_only = .{
|
||||
.url = "https://deps.files.ghostty.org/NerdFontsSymbolsOnly-3.4.0.tar.gz",
|
||||
.hash = "N-V-__8AAMVLTABmYkLqhZPLXnMl-KyN38R8UVYqGrxqO26s",
|
||||
.lazy = true,
|
||||
},
|
||||
|
||||
// Other
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub fn build(b: *std.Build) !void {
|
|||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const imgui = b.dependency("imgui", .{});
|
||||
const imgui_ = b.lazyDependency("imgui", .{});
|
||||
const lib = b.addLibrary(.{
|
||||
.name = "cimgui",
|
||||
.root_module = b.createModule(.{
|
||||
|
|
@ -52,7 +52,7 @@ pub fn build(b: *std.Build) !void {
|
|||
}
|
||||
}
|
||||
|
||||
lib.addIncludePath(imgui.path(""));
|
||||
if (imgui_) |imgui| lib.addIncludePath(imgui.path(""));
|
||||
module.addIncludePath(b.path("vendor"));
|
||||
|
||||
var flags = std.ArrayList([]const u8).init(b.allocator);
|
||||
|
|
@ -72,6 +72,7 @@ pub fn build(b: *std.Build) !void {
|
|||
});
|
||||
}
|
||||
|
||||
if (imgui_) |imgui| {
|
||||
lib.addCSourceFile(.{ .file = b.path("vendor/cimgui.cpp"), .flags = flags.items });
|
||||
lib.addCSourceFile(.{ .file = imgui.path("imgui.cpp"), .flags = flags.items });
|
||||
lib.addCSourceFile(.{ .file = imgui.path("imgui_draw.cpp"), .flags = flags.items });
|
||||
|
|
@ -79,7 +80,6 @@ pub fn build(b: *std.Build) !void {
|
|||
lib.addCSourceFile(.{ .file = imgui.path("imgui_widgets.cpp"), .flags = flags.items });
|
||||
lib.addCSourceFile(.{ .file = imgui.path("imgui_tables.cpp"), .flags = flags.items });
|
||||
lib.addCSourceFile(.{ .file = imgui.path("misc/freetype/imgui_freetype.cpp"), .flags = flags.items });
|
||||
|
||||
lib.addCSourceFile(.{
|
||||
.file = imgui.path("backends/imgui_impl_opengl3.cpp"),
|
||||
.flags = flags.items,
|
||||
|
|
@ -100,6 +100,7 @@ pub fn build(b: *std.Build) !void {
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lib.installHeadersDirectory(
|
||||
b.path("vendor"),
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
// ocornut/imgui
|
||||
.url = "https://deps.files.ghostty.org/imgui-1220bc6b9daceaf7c8c60f3c3998058045ba0c5c5f48ae255ff97776d9cd8bfc6402.tar.gz",
|
||||
.hash = "N-V-__8AAH0GaQC8a52s6vfIxg88OZgFgEW6DFxfSK4lX_l3",
|
||||
.lazy = true,
|
||||
},
|
||||
|
||||
.apple_sdk = .{ .path = "../apple-sdk" },
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ pub fn build(b: *std.Build) !void {
|
|||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const upstream = b.dependency("glslang", .{});
|
||||
const upstream = b.lazyDependency("glslang", .{});
|
||||
const lib = try buildGlslang(b, upstream, target, optimize);
|
||||
b.installArtifact(lib);
|
||||
|
||||
module.addIncludePath(upstream.path(""));
|
||||
if (upstream) |v| module.addIncludePath(v.path(""));
|
||||
module.addIncludePath(b.path("override"));
|
||||
|
||||
if (target.query.isNative()) {
|
||||
|
|
@ -38,7 +38,7 @@ pub fn build(b: *std.Build) !void {
|
|||
|
||||
fn buildGlslang(
|
||||
b: *std.Build,
|
||||
upstream: *std.Build.Dependency,
|
||||
upstream_: ?*std.Build.Dependency,
|
||||
target: std.Build.ResolvedTarget,
|
||||
optimize: std.builtin.OptimizeMode,
|
||||
) !*std.Build.Step.Compile {
|
||||
|
|
@ -52,7 +52,7 @@ fn buildGlslang(
|
|||
});
|
||||
lib.linkLibC();
|
||||
lib.linkLibCpp();
|
||||
lib.addIncludePath(upstream.path(""));
|
||||
if (upstream_) |upstream| lib.addIncludePath(upstream.path(""));
|
||||
lib.addIncludePath(b.path("override"));
|
||||
if (target.result.os.tag.isDarwin()) {
|
||||
const apple_sdk = @import("apple_sdk");
|
||||
|
|
@ -66,6 +66,7 @@ fn buildGlslang(
|
|||
"-fno-sanitize-trap=undefined",
|
||||
});
|
||||
|
||||
if (upstream_) |upstream| {
|
||||
lib.addCSourceFiles(.{
|
||||
.root = upstream.path(""),
|
||||
.flags = flags.items,
|
||||
|
|
@ -147,6 +148,7 @@ fn buildGlslang(
|
|||
"",
|
||||
.{ .include_extensions = &.{".h"} },
|
||||
);
|
||||
}
|
||||
|
||||
return lib;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
.glslang = .{
|
||||
.url = "https://deps.files.ghostty.org/glslang-12201278a1a05c0ce0b6eb6026c65cd3e9247aa041b1c260324bf29cee559dd23ba1.tar.gz",
|
||||
.hash = "N-V-__8AABzkUgISeKGgXAzgtutgJsZc0-kkeqBBscJgMkvy",
|
||||
.lazy = true,
|
||||
},
|
||||
|
||||
.apple_sdk = .{ .path = "../apple-sdk" },
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pub fn build(b: *std.Build) !void {
|
|||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const upstream = b.dependency("highway", .{});
|
||||
const upstream_ = b.lazyDependency("highway", .{});
|
||||
|
||||
const module = b.addModule("highway", .{
|
||||
.root_source_file = b.path("main.zig"),
|
||||
|
|
@ -21,8 +21,10 @@ pub fn build(b: *std.Build) !void {
|
|||
.linkage = .static,
|
||||
});
|
||||
lib.linkLibCpp();
|
||||
if (upstream_) |upstream| {
|
||||
lib.addIncludePath(upstream.path(""));
|
||||
module.addIncludePath(upstream.path(""));
|
||||
}
|
||||
|
||||
if (target.result.os.tag.isDarwin()) {
|
||||
const apple_sdk = @import("apple_sdk");
|
||||
|
|
@ -74,6 +76,7 @@ pub fn build(b: *std.Build) !void {
|
|||
}
|
||||
|
||||
lib.addCSourceFiles(.{ .flags = flags.items, .files = &.{"bridge.cpp"} });
|
||||
if (upstream_) |upstream| {
|
||||
lib.addCSourceFiles(.{
|
||||
.root = upstream.path(""),
|
||||
.flags = flags.items,
|
||||
|
|
@ -92,6 +95,7 @@ pub fn build(b: *std.Build) !void {
|
|||
"hwy",
|
||||
.{ .include_extensions = &.{".h"} },
|
||||
);
|
||||
}
|
||||
|
||||
b.installArtifact(lib);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
.highway = .{
|
||||
.url = "https://deps.files.ghostty.org/highway-66486a10623fa0d72fe91260f96c892e41aceb06.tar.gz",
|
||||
.hash = "N-V-__8AAGmZhABbsPJLfbqrh6JTHsXhY6qCaLAQyx25e0XE",
|
||||
.lazy = true,
|
||||
},
|
||||
|
||||
.apple_sdk = .{ .path = "../apple-sdk" },
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pub fn build(b: *std.Build) !void {
|
|||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const upstream = b.dependency("libxml2", .{});
|
||||
const upstream_ = b.lazyDependency("libxml2", .{});
|
||||
|
||||
const lib = b.addLibrary(.{
|
||||
.name = "xml2",
|
||||
|
|
@ -16,7 +16,7 @@ pub fn build(b: *std.Build) !void {
|
|||
});
|
||||
lib.linkLibC();
|
||||
|
||||
lib.addIncludePath(upstream.path("include"));
|
||||
if (upstream_) |upstream| lib.addIncludePath(upstream.path("include"));
|
||||
lib.addIncludePath(b.path("override/include"));
|
||||
if (target.result.os.tag == .windows) {
|
||||
lib.addIncludePath(b.path("override/config/win32"));
|
||||
|
|
@ -97,6 +97,7 @@ pub fn build(b: *std.Build) !void {
|
|||
}
|
||||
}
|
||||
|
||||
if (upstream_) |upstream| {
|
||||
lib.addCSourceFiles(.{
|
||||
.root = upstream.path(""),
|
||||
.files = srcs,
|
||||
|
|
@ -112,6 +113,7 @@ pub fn build(b: *std.Build) !void {
|
|||
"",
|
||||
.{ .include_extensions = &.{".h"} },
|
||||
);
|
||||
}
|
||||
|
||||
b.installArtifact(lib);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
.libxml2 = .{
|
||||
.url = "https://deps.files.ghostty.org/libxml2-2.11.5.tar.gz",
|
||||
.hash = "N-V-__8AAG3RoQEyRC2Vw7Qoro5SYBf62IHn3HjqtNVY6aWK",
|
||||
.lazy = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ pub fn build(b: *std.Build) !void {
|
|||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const upstream = b.dependency("spirv_cross", .{});
|
||||
const upstream = b.lazyDependency("spirv_cross", .{});
|
||||
|
||||
const module = b.addModule("spirv_cross", .{ .root_source_file = b.path("main.zig") });
|
||||
module.addIncludePath(upstream.path(""));
|
||||
if (upstream) |v| module.addIncludePath(v.path(""));
|
||||
|
||||
const lib = try buildSpirvCross(b, upstream, target, optimize);
|
||||
b.installArtifact(lib);
|
||||
|
|
@ -33,7 +33,7 @@ pub fn build(b: *std.Build) !void {
|
|||
|
||||
fn buildSpirvCross(
|
||||
b: *std.Build,
|
||||
upstream: *std.Build.Dependency,
|
||||
upstream_: ?*std.Build.Dependency,
|
||||
target: std.Build.ResolvedTarget,
|
||||
optimize: std.builtin.OptimizeMode,
|
||||
) !*std.Build.Step.Compile {
|
||||
|
|
@ -62,6 +62,7 @@ fn buildSpirvCross(
|
|||
"-fno-sanitize-trap=undefined",
|
||||
});
|
||||
|
||||
const upstream = upstream_ orelse return lib;
|
||||
lib.addCSourceFiles(.{
|
||||
.root = upstream.path(""),
|
||||
.flags = flags.items,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
.spirv_cross = .{
|
||||
.url = "https://deps.files.ghostty.org/spirv_cross-1220fb3b5586e8be67bc3feb34cbe749cf42a60d628d2953632c2f8141302748c8da.tar.gz",
|
||||
.hash = "N-V-__8AANb6pwD7O1WG6L5nvD_rNMvnSc9Cpg1ijSlTYywv",
|
||||
.lazy = true,
|
||||
},
|
||||
|
||||
.apple_sdk = .{ .path = "../apple-sdk" },
|
||||
|
|
|
|||
|
|
@ -502,7 +502,7 @@ pub fn add(
|
|||
// Fonts
|
||||
{
|
||||
// JetBrains Mono
|
||||
const jb_mono = b.dependency("jetbrains_mono", .{});
|
||||
if (b.lazyDependency("jetbrains_mono", .{})) |jb_mono| {
|
||||
step.root_module.addAnonymousImport(
|
||||
"jetbrains_mono_regular",
|
||||
.{ .root_source_file = jb_mono.path("fonts/ttf/JetBrainsMono-Regular.ttf") },
|
||||
|
|
@ -527,14 +527,16 @@ pub fn add(
|
|||
"jetbrains_mono_variable_italic",
|
||||
.{ .root_source_file = jb_mono.path("fonts/variable/JetBrainsMono-Italic[wght].ttf") },
|
||||
);
|
||||
}
|
||||
|
||||
// Symbols-only nerd font
|
||||
const nf_symbols = b.dependency("nerd_fonts_symbols_only", .{});
|
||||
if (b.lazyDependency("nerd_fonts_symbols_only", .{})) |nf_symbols| {
|
||||
step.root_module.addAnonymousImport(
|
||||
"nerd_fonts_symbols_only",
|
||||
.{ .root_source_file = nf_symbols.path("SymbolsNerdFont-Regular.ttf") },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// If we're building an exe then we have additional dependencies.
|
||||
if (step.kind != .lib) {
|
||||
|
|
@ -615,17 +617,20 @@ fn addGtkNg(
|
|||
"plasma_wayland_protocols",
|
||||
.{},
|
||||
);
|
||||
const zig_wayland_import_ = b.lazyImport(
|
||||
@import("../../build.zig"),
|
||||
"zig_wayland",
|
||||
);
|
||||
const zig_wayland_dep_ = b.lazyDependency("zig_wayland", .{});
|
||||
|
||||
// Unwrap or return, there are no more dependencies below.
|
||||
const wayland_dep = wayland_dep_ orelse break :wayland;
|
||||
const wayland_protocols_dep = wayland_protocols_dep_ orelse break :wayland;
|
||||
const plasma_wayland_protocols_dep = plasma_wayland_protocols_dep_ orelse break :wayland;
|
||||
const zig_wayland_import = zig_wayland_import_ orelse break :wayland;
|
||||
const zig_wayland_dep = zig_wayland_dep_ orelse break :wayland;
|
||||
|
||||
// Note that zig_wayland cannot be lazy because lazy dependencies
|
||||
// can't be imported since they don't exist and imports are
|
||||
// resolved at compile time of the build.
|
||||
const zig_wayland_dep = b.dependency("zig_wayland", .{});
|
||||
const Scanner = @import("zig_wayland").Scanner;
|
||||
const Scanner = zig_wayland_import.Scanner;
|
||||
const scanner = Scanner.create(zig_wayland_dep.builder, .{
|
||||
.wayland_xml = wayland_dep.path("protocol/wayland.xml"),
|
||||
.wayland_protocols = wayland_protocols_dep.path(""),
|
||||
|
|
|
|||
Loading…
Reference in New Issue