From 72eae696f0605057057211846a213f78d101d707 Mon Sep 17 00:00:00 2001 From: nat3 <121395237+nat3Github@users.noreply.github.com> Date: Thu, 1 Oct 2026 13:41:54 +0200 Subject: [PATCH] Make platform dependencies lazy and drop unused GL registries Every dependency except sdl is now lazy, so only what the target needs is fetched. Passing -fsys= skips the fetch and uses the system/sysroot headers instead. The egl and opengl registries are removed: SDL already ships the EGL/KHR/GLES and GL headers it needs. zig-pkg footprint: macOS/Windows 26 pkgs/379M -> 1 pkg/52M. --- build.zig | 13 ++++++++++++ build.zig.zon | 30 +++++++++++++++++++-------- src/linux.zig | 54 ++++++++++++++++++++----------------------------- src/macos.zig | 4 ---- src/windows.zig | 4 ---- 5 files changed, 57 insertions(+), 48 deletions(-) diff --git a/build.zig b/build.zig index 2834e0a02..8df295add 100644 --- a/build.zig +++ b/build.zig @@ -172,3 +172,16 @@ pub fn build(b: *std.Build) !void { const run_step = b.step("run-example", "Run the example app"); run_step.dependOn(&run_example.step); } + +/// Platform dependencies are lazy so only the ones the target needs get fetched. Passing +/// `-fsys=` skips the fetch and uses the headers from the system/sysroot instead. Returns +/// null in either case, or while the dependency is still being fetched. +pub fn lazyDep(b: *std.Build, name: []const u8) ?*std.Build.Dependency { + if (b.systemIntegrationOption(name, .{})) return null; + return b.lazyDependency(name, .{}); +} + +pub fn addDepInclude(lib: *std.Build.Step.Compile, name: []const u8, sub_path: []const u8) void { + const b = lib.step.owner; + if (lazyDep(b, name)) |dep| lib.root_module.addIncludePath(dep.path(sub_path)); +} diff --git a/build.zig.zon b/build.zig.zon index 2debcd727..b75810fd7 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -13,84 +13,93 @@ .version = "1.16.2", .url = "https://gitlab.freedesktop.org/dbus/dbus/-/archive/dbus-1.16.2/dbus-dbus-1.16.2.tar.gz", .hash = "N-V-__8AALxqaQCXLK7KmtlbRHzj5quTSajWtJZ86Qy7aBxj", + .lazy = true, }, .x11 = .{ .url = "https://gitlab.freedesktop.org/xorg/lib/libx11/-/archive/libX11-1.8.13/libx11-libX11-1.8.13.tar.gz", .hash = "N-V-__8AANL5xACqderCBKpnIFKe282dZAikvyc--kNSKWgd", - }, - .egl = .{ - .url = "https://github.com/KhronosGroup/EGL-Registry/archive/3d7796b3721d93976b6bfe536aa97bbc4bce8667.tar.gz", - .hash = "N-V-__8AAItrbQBen6_Wl2eZ2ax6B0G6qtKys7_uVz224o99", + .lazy = true, }, .wayland = .{ .version = "1.26.0", .url = "git+https://gitlab.freedesktop.org/wayland/wayland?ref=1.26.0#87cc8a8728a923fc57938faa81ba0e74f34ecdc7", .hash = "N-V-__8AAA46JQABKU7sa-6xGUAN44uFsYSUS_w79UVuu7qo", + .lazy = true, }, .xkbcommon = .{ .version = "1.13.2", .url = "https://github.com/xkbcommon/libxkbcommon/archive/refs/tags/xkbcommon-1.13.2.tar.gz", .hash = "N-V-__8AAGh7bAAD9LH6Hh6HB6br9SDZmRBbRu-_1NNpQ4GL", + .lazy = true, }, .xorgproto = .{ .url = "https://gitlab.freedesktop.org/xorg/proto/xorgproto/-/archive/xorgproto-2025.1/xorgproto-xorgproto-2025.1.tar.gz", .hash = "N-V-__8AAG86ZgA2-SHGTO4n81-Sj8LNvSASCKZ91wOWZ7Sg", + .lazy = true, }, .xext = .{ .url = "https://gitlab.freedesktop.org/xorg/lib/libxext/-/archive/libXext-1.3.7/libxext-libXext-1.3.7.tar.gz", .hash = "N-V-__8AAHTdBwAEWsgYzKEVP-WmGT0wYKIJjBtqH1No6y73", + .lazy = true, }, .xcb = .{ .url = "https://gitlab.freedesktop.org/xorg/lib/libxcb/-/archive/libxcb-1.17.0/libxcb-libxcb-1.17.0.tar.gz", .hash = "N-V-__8AAPZxCQD7JyQLx0_D9J9dnkSoP7iziBVxreTgUqlj", + .lazy = true, }, .ibus = .{ .url = "https://github.com/ibus/ibus/releases/download/1.5.34/ibus-1.5.34.tar.gz", .hash = "N-V-__8AANTkvAHAAXsApyhePM0ufoLcIQxEGXVB6Q7n7grW", + .lazy = true, }, .usb = .{ .url = "https://github.com/libusb/libusb/archive/refs/tags/v1.0.30.zip", .hash = "N-V-__8AAP6YHABRm4muBuwd_qlKgvsenaOLg962zfsjQr8B", + .lazy = true, }, .xcursor = .{ .version = "1.2.3", .url = "https://gitlab.freedesktop.org/xorg/lib/libxcursor/-/archive/libXcursor-1.2.3/libxcursor-libXcursor-1.2.3.tar.gz", .hash = "N-V-__8AAKtlAgAAqwksheZkCSajEEPpi2XivNet-_3hZyz2", + .lazy = true, }, .xi = .{ .url = "https://gitlab.freedesktop.org/xorg/lib/libxi/-/archive/libXi-1.8.3/libxi-libXi-1.8.3.tar.gz", .hash = "N-V-__8AAPR0DQAuD3_ZopKbezyogf0SLNe6GiYF3RlaaNrh", + .lazy = true, }, .xfixes = .{ .url = "https://gitlab.freedesktop.org/xorg/lib/libxfixes/-/archive/libXfixes-6.0.2/libxfixes-libXfixes-6.0.2.tar.gz", .hash = "N-V-__8AAFIgAQCJSug37AGy4zypGtiDtUR9wtQa8U74Nm0a", + .lazy = true, }, .xrandr = .{ .url = "https://gitlab.freedesktop.org/xorg/lib/libxrandr/-/archive/libXrandr-1.5.5/libxrandr-libXrandr-1.5.5.tar.gz", .hash = "N-V-__8AAGlRAgBdkf1F-Y410qIz6cV4C62ZAUk_SGeUVriw", + .lazy = true, }, .xrender = .{ .url = "https://gitlab.freedesktop.org/xorg/lib/libxrender/-/archive/libXrender-0.9.12/libxrender-libXrender-0.9.12.tar.gz", .hash = "N-V-__8AANorBADbt-RlITZJofNvQWTiaQlv7r7lWYtxAqGx", + .lazy = true, }, .decor = .{ .url = "https://gitlab.freedesktop.org/libdecor/libdecor/-/archive/0.2.5/libdecor-0.2.5.tar.gz", .hash = "N-V-__8AADG6BADZ6vLbOD3OrWhDYa5jrubmgY-ljspuv-4R", + .lazy = true, .version = "0.2.5", }, - .opengl = .{ - .url = "https://github.com/KhronosGroup/OpenGL-Registry/archive/e8f7cd0e35ac8d6f5667a021ff83d04b1fec41ef.tar.gz", - .hash = "N-V-__8AADsI5wqNqQMgAmqSba8PUrQcWdd3Svxc8GoX8SgY", - }, .pipewire = .{ .url = "https://gitlab.freedesktop.org/pipewire/pipewire/-/archive/1.6.8/pipewire-1.6.8.tar.gz", .hash = "N-V-__8AAEBm3gCliUlb1HgAJA-3XvTWKC2YfRa5hJMiaEld", + .lazy = true, .version = "1.6.8", .api_version = "0.3", // From `meson.build`, does not directly track `version`! }, .jack = .{ .url = "https://github.com/jackaudio/jack2/archive/refs/tags/jack2-control-api-relicense-nedko.tar.gz", .hash = "N-V-__8AANOERwAn9QBxYJf43h9P3jq2HYTPvXlZRCHPEmrj", + .lazy = true, }, .pulseaudio = .{ // This dependency must be kept in sync with `pulseaudio_windows`. @@ -117,14 +126,17 @@ // This dependency must be kept in sync with `xscrnsaver_windows` for similar reasons explained in the `pulseaudio` dependency. .url = "https://gitlab.freedesktop.org/xorg/lib/libxscrnsaver/-/archive/libXScrnSaver-1.2.5/libxscrnsaver-libXScrnSaver-1.2.5.tar.gz", .hash = "N-V-__8AAMXRAADYeHz48Y1IuZUzOOqRvOO7f0wrdeNkWcBF", + .lazy = true, }, .alsa = .{ .url = "https://github.com/alsa-project/alsa-lib/archive/refs/tags/v1.2.16.1.tar.gz", .hash = "N-V-__8AACQ2RADoahGXBHOr7fJYspVVN8sMHwQn2C-kzECe", + .lazy = true, }, .sndio = .{ .url = "https://sndio.org/sndio-1.10.0.tar.gz", .hash = "N-V-__8AAKA0CgB5SuKmufbOKBnZsjDFZuUTNO70MHQEf1p8", + .lazy = true, }, .fribidi = .{ .version = "1.0.16", @@ -132,10 +144,12 @@ .unicode_version = "16.0.0", .url = "https://github.com/fribidi/fribidi/archive/refs/tags/v1.0.16.tar.gz", .hash = "N-V-__8AABbxDAFJr4_dchs33gEqLRpBMP2oUBTuIueW9u_h", + .lazy = true, }, .thai = .{ .url = "https://github.com/tlwg/libthai/archive/refs/tags/v0.1.30.tar.gz", .hash = "N-V-__8AAAqMIgArahV5mT0LGKWmDhZC9QtlMIZlaT9yp_lP", + .lazy = true, }, }, .paths = .{ diff --git a/src/linux.zig b/src/linux.zig index 1c73739eb..c25967e22 100644 --- a/src/linux.zig +++ b/src/linux.zig @@ -20,8 +20,7 @@ pub fn build( lib.root_module.addIncludePath(generated.getDirectory()); // Provide the D-Bus headers - { - const dbus = b.dependency("dbus", .{}); + if (root.lazyDep(b, "dbus")) |dbus| { lib.root_module.addIncludePath(dbus.path(".")); const version_string = build_zon.dependencies.dbus.version; @@ -106,7 +105,7 @@ pub fn build( // Provide the IBus headers { // The headers are here - lib.root_module.addIncludePath(b.dependency("ibus", .{}).path("src")); + root.addDepInclude(lib, "ibus", "src"); // They depend on the GLib headers, which require some configuration lib.root_module.addIncludePath(b.path("deps/glib/upstream/include")); @@ -289,9 +288,7 @@ pub fn build( // Provide the X11 headers { - { - const x11 = b.dependency("x11", .{}); - + if (root.lazyDep(b, "x11")) |x11| { lib.root_module.addIncludePath(x11.path("include")); const config = b.addConfigHeader(.{ @@ -305,8 +302,7 @@ pub fn build( } // Provide the Xcursor headers - { - const xcursor = b.dependency("xcursor", .{}); + if (root.lazyDep(b, "xcursor")) |xcursor| { const version_string = build_zon.dependencies.xcursor.version; const version = comptime std.SemanticVersion.parse(version_string) catch unreachable; const config = b.addConfigHeader(.{ @@ -352,8 +348,7 @@ pub fn build( } // Provide the pipewire headers - { - const pipewire = b.dependency("pipewire", .{}); + if (root.lazyDep(b, "pipewire")) |pipewire| { lib.root_module.addIncludePath(pipewire.path("spa/include")); lib.root_module.addIncludePath(pipewire.path("src")); const version_string = build_zon.dependencies.pipewire.version; @@ -379,7 +374,7 @@ pub fn build( .windows => "pulseaudio_windows", else => "pulseaudio", }; - if (b.lazyDependency(pulseaudio_name, .{})) |pulseaudio| { + if (root.lazyDep(b, pulseaudio_name)) |pulseaudio| { lib.root_module.addIncludePath(pulseaudio.path("src")); const version_string = build_zon.dependencies.pulseaudio.version; const version = comptime std.SemanticVersion.parse(version_string) catch unreachable; @@ -401,8 +396,7 @@ pub fn build( } // Provide the Wayland headers - { - const wayland = b.dependency("wayland", .{}); + if (root.lazyDep(b, "wayland")) |wayland| { lib.root_module.addIncludePath(wayland.path("src")); lib.root_module.addIncludePath(wayland.path("cursor")); lib.root_module.addIncludePath(wayland.path("egl")); @@ -430,8 +424,7 @@ pub fn build( } // Provide the Alsa headers - { - const alsa = b.dependency("alsa", .{}); + if (root.lazyDep(b, "alsa")) |alsa| { _ = generated.addCopyDirectory(alsa.path("include"), "alsa", .{ .include_extensions = &.{".h"}, }); @@ -440,8 +433,7 @@ pub fn build( } // Provide the Fribidi headers - { - const fribidi = b.dependency("fribidi", .{}); + if (root.lazyDep(b, "fribidi")) |fribidi| { const interface_version = build_zon.dependencies.fribidi.interface_version; const version_string = build_zon.dependencies.fribidi.version; const version = comptime std.SemanticVersion.parse(version_string) catch unreachable; @@ -487,23 +479,21 @@ pub fn build( } // Provide upstream headers that don't require any special handling - lib.root_module.addIncludePath(b.dependency("egl", .{}).path("api")); - lib.root_module.addIncludePath(b.dependency("opengl", .{}).path("api")); - lib.root_module.addIncludePath(b.dependency("xkbcommon", .{}).path("include")); - lib.root_module.addIncludePath(b.dependency("xorgproto", .{}).path("include")); - lib.root_module.addIncludePath(b.dependency("xext", .{}).path("include")); - lib.root_module.addIncludePath(b.dependency("usb", .{}).path("libusb")); - lib.root_module.addIncludePath(b.dependency("xi", .{}).path("include")); - lib.root_module.addIncludePath(b.dependency("xfixes", .{}).path("include")); - lib.root_module.addIncludePath(b.dependency("xrandr", .{}).path("include")); - lib.root_module.addIncludePath(b.dependency("xrender", .{}).path("include")); - lib.root_module.addIncludePath(b.dependency("xscrnsaver", .{}).path("include")); - lib.root_module.addIncludePath(b.dependency("jack", .{}).path("common")); - lib.root_module.addIncludePath(b.dependency("sndio", .{}).path("libsndio")); + root.addDepInclude(lib, "xkbcommon", "include"); + root.addDepInclude(lib, "xorgproto", "include"); + root.addDepInclude(lib, "xext", "include"); + root.addDepInclude(lib, "usb", "libusb"); + root.addDepInclude(lib, "xi", "include"); + root.addDepInclude(lib, "xfixes", "include"); + root.addDepInclude(lib, "xrandr", "include"); + root.addDepInclude(lib, "xrender", "include"); + root.addDepInclude(lib, "xscrnsaver", "include"); + root.addDepInclude(lib, "jack", "common"); + root.addDepInclude(lib, "sndio", "libsndio"); lib.root_module.addIncludePath(b.path("deps/wayland/protocols")); - lib.root_module.addIncludePath(b.dependency("decor", .{}).path("src")); + root.addDepInclude(lib, "decor", "src"); lib.root_module.addIncludePath(b.path("deps/mesa/include")); - lib.root_module.addIncludePath(b.dependency("thai", .{}).path("include")); + root.addDepInclude(lib, "thai", "include"); // Provide vendored headers that don't require any special handling lib.root_module.addIncludePath(b.path("deps/xcb/include")); diff --git a/src/macos.zig b/src/macos.zig index 49bae4194..7f60724b1 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -15,10 +15,6 @@ pub fn build( const upstream = b.dependency("sdl", .{}); - // Add the platform specific dependency include paths - lib.root_module.addIncludePath(b.dependency("egl", .{}).path("api")); - lib.root_module.addIncludePath(b.dependency("opengl", .{}).path("api")); - // Link with the platform specific system frameworks lib.root_module.linkFramework("Cocoa", .{}); lib.root_module.linkFramework("IOKit", .{}); diff --git a/src/windows.zig b/src/windows.zig index f30e430ab..62aa7768a 100644 --- a/src/windows.zig +++ b/src/windows.zig @@ -15,10 +15,6 @@ pub fn build( const upstream = b.dependency("sdl", .{}); - // Add the platform specific dependency include paths - lib.root_module.addIncludePath(b.dependency("egl", .{}).path("api")); - lib.root_module.addIncludePath(b.dependency("opengl", .{}).path("api")); - // Link with the platform specific system libraries lib.root_module.linkSystemLibrary("advapi32", .{}); lib.root_module.linkSystemLibrary("gdi32", .{});