From 3043d5c175c5b1811f518be2ebfbf97826c63286 Mon Sep 17 00:00:00 2001 From: geemili Date: Wed, 21 Feb 2024 12:22:59 -0700 Subject: [PATCH] replace libxkbcommon system library with build.zig.zon dependency --- build.zig | 16 ++++++--- build.zig.zon | 36 +++++++++++++++++++ ...{02_text_editor.zig => 10_text_editor.zig} | 2 +- src/main.zig | 3 ++ 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 build.zig.zon rename examples/{02_text_editor.zig => 10_text_editor.zig} (99%) diff --git a/build.zig b/build.zig index 452e355..675271d 100644 --- a/build.zig +++ b/build.zig @@ -4,12 +4,21 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); + const libxkbcommon = b.dependency("libxkbcommon", .{ + .target = target, + .optimize = optimize, + }); + const xkbcommon_module = b.createModule(.{ .root_source_file = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" }, }); + xkbcommon_module.linkLibrary(libxkbcommon.artifact("xkbcommon")); const module = b.addModule("wayland", .{ .root_source_file = .{ .path = "src/main.zig" }, + .imports = &.{ + .{ .name = "xkbcommon", .module = xkbcommon_module }, + }, }); const lib = b.addStaticLibrary(.{ @@ -48,16 +57,15 @@ pub fn build(b: *std.Build) void { client_connect_exe.root_module.addImport("wayland", module); b.installArtifact(client_connect_exe); + // Text Editor example const text_editor_exe = b.addExecutable(.{ - .name = "02_text_editor", - .root_source_file = .{ .path = "examples/02_text_editor.zig" }, + .name = "10_text_editor", + .root_source_file = .{ .path = "examples/10_text_editor.zig" }, .target = target, .optimize = optimize, }); text_editor_exe.root_module.addImport("wayland", module); - text_editor_exe.root_module.addImport("xkbcommon", xkbcommon_module); text_editor_exe.linkLibC(); - text_editor_exe.linkSystemLibrary("xkbcommon"); text_editor_exe.addIncludePath(.{ .path = "deps/font8x8/" }); b.installArtifact(text_editor_exe); } diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..de51d66 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,36 @@ +.{ + .name = "zig-wayland-wire", + // This is a [Semantic Version](https://semver.org/). + // In a future version of Zig it will be used for package deduplication. + .version = "0.0.0", + + // This field is optional. + // This is currently advisory only; Zig does not yet do anything + // with this value. + //.minimum_zig_version = "0.11.0", + + // This field is optional. + // Each dependency must either provide a `url` and `hash`, or a `path`. + // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. + // Once all dependencies are fetched, `zig build` no longer requires + // internet connectivity. + .dependencies = .{ + .libxkbcommon = .{ + .url = "https://git.samsehu.perli.casa/StreetLight/libxkbcommon/archive/d6a9539e0ca8676ae2e8e379a68671c79cc4fd47.tar.gz", + .hash = "1220c133a5f7de0ba8c7cb59258cbdc611f51097c43b9240a092ee078e3e3ea09f45", + }, + }, + .paths = .{ + // This makes *all* files, recursively, included in this package. It is generally + // better to explicitly list the files and directories instead, to insure that + // fetching from tarballs, file system paths, and version control all result + // in the same contents hash. + "", + // For example... + //"build.zig", + //"build.zig.zon", + //"src", + //"LICENSE", + //"README.md", + }, +} diff --git a/examples/02_text_editor.zig b/examples/10_text_editor.zig similarity index 99% rename from examples/02_text_editor.zig rename to examples/10_text_editor.zig index 84aabf5..616d542 100644 --- a/examples/02_text_editor.zig +++ b/examples/10_text_editor.zig @@ -1,6 +1,6 @@ const std = @import("std"); const wayland = @import("wayland"); -const xkbcommon = @import("xkbcommon"); +const xkbcommon = wayland.xkbcommon; const font8x8 = @cImport({ @cInclude("font8x8.h"); }); diff --git a/src/main.zig b/src/main.zig index 90126bc..dd84f29 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,8 @@ const std = @import("std"); const testing = std.testing; + +pub const xkbcommon = @import("xkbcommon"); + pub const core = @import("./core.zig"); pub const xdg = @import("./xdg.zig"); pub const zxdg = @import("./zxdg.zig");