mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-04-22 01:18:36 +03:00

Lazy dependencies are only fetched if the build script would actually reach a usage of that dependency at runtime (when the `lazyDependency` function is called). This can save a lot of network traffic, disk uage, and time because we don't have to fetch and build dependencies that we don't actually need. Prior to this commit, Ghostty fetched almost everything for all platforms and configurations all the time. This commit reverses that to fetching almost nothing until it's actually needed. There are very little downsides to doing this[1]. One downside is `zig build --fetch` doesn't fetch lazy dependencies, but we don't rely on this command for packaging and suggest using our custom shell script that downloads a cached list of URLs (`build.zig.zon.txt`). This commit doesn't cover 100% of dependencies, since some provide no benefit to make lazy while the complexity to make them lazy is higher (in code style typically). Conversely, some simple dependencies are marked lazy even if they're almost always needed if they don't introduce any real complexity to the code, because there is very little downside to do so. [1]: https://ziggit.dev/t/lazy-dependencies-best-dependencies/5509/5
55 lines
1.5 KiB
Zig
55 lines
1.5 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) !void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const lib = b.addStaticLibrary(.{
|
|
.name = "utfcpp",
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
lib.linkLibCpp();
|
|
|
|
if (target.result.os.tag.isDarwin()) {
|
|
const apple_sdk = @import("apple_sdk");
|
|
try apple_sdk.addPaths(b, lib.root_module);
|
|
}
|
|
|
|
var flags = std.ArrayList([]const u8).init(b.allocator);
|
|
defer flags.deinit();
|
|
try flags.appendSlice(&.{});
|
|
|
|
lib.addCSourceFiles(.{
|
|
.flags = flags.items,
|
|
.files = &.{"empty.cc"},
|
|
});
|
|
|
|
if (b.lazyDependency("utfcpp", .{})) |upstream| {
|
|
lib.addIncludePath(upstream.path(""));
|
|
lib.installHeadersDirectory(
|
|
upstream.path("source"),
|
|
"",
|
|
.{ .include_extensions = &.{".h"} },
|
|
);
|
|
}
|
|
|
|
b.installArtifact(lib);
|
|
|
|
// {
|
|
// const test_exe = b.addTest(.{
|
|
// .name = "test",
|
|
// .root_source_file = .{ .path = "main.zig" },
|
|
// .target = target,
|
|
// .optimize = optimize,
|
|
// });
|
|
// test_exe.linkLibrary(lib);
|
|
//
|
|
// var it = module.import_table.iterator();
|
|
// while (it.next()) |entry| test_exe.root_module.addImport(entry.key_ptr.*, entry.value_ptr.*);
|
|
// const tests_run = b.addRunArtifact(test_exe);
|
|
// const test_step = b.step("test", "Run tests");
|
|
// test_step.dependOn(&tests_run.step);
|
|
// }
|
|
}
|