Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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=<name>` 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));
}
30 changes: 22 additions & 8 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -117,25 +126,30 @@
// 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",
.interface_version = 4,
.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 = .{
Expand Down
54 changes: 22 additions & 32 deletions src/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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(.{
Expand All @@ -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(.{
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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"));
Expand Down Expand Up @@ -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"},
});
Expand All @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down
4 changes: 0 additions & 4 deletions src/macos.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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", .{});
Expand Down
4 changes: 0 additions & 4 deletions src/windows.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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", .{});
Expand Down
Loading