From 958f8798b6fdfab40aa29e1538827fa74e833a1c Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 20 May 2024 11:33:04 +0200 Subject: [PATCH] build: switch to the Zig package manager No more git submodules! --- .gitmodules | 12 ------------ PACKAGING.md | 39 +++++++++++++++++++++++++++++++++++++++ README.md | 12 ++---------- build.zig | 40 +++++++++++++++------------------------- build.zig.zon | 23 +++++++++++++++++++++++ deps/zig-pixman | 1 - deps/zig-wayland | 1 - deps/zig-wlroots | 1 - deps/zig-xkbcommon | 1 - 9 files changed, 79 insertions(+), 51 deletions(-) delete mode 100644 .gitmodules create mode 100644 build.zig.zon delete mode 160000 deps/zig-pixman delete mode 160000 deps/zig-wayland delete mode 160000 deps/zig-wlroots delete mode 160000 deps/zig-xkbcommon diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 0729afd..0000000 --- a/.gitmodules +++ /dev/null @@ -1,12 +0,0 @@ -[submodule "deps/zig-wayland"] - path = deps/zig-wayland - url = https://codeberg.org/ifreund/zig-wayland -[submodule "deps/zig-pixman"] - path = deps/zig-pixman - url = https://codeberg.org/ifreund/zig-pixman -[submodule "deps/zig-xkbcommon"] - path = deps/zig-xkbcommon - url = https://codeberg.org/ifreund/zig-xkbcommon -[submodule "deps/zig-wlroots"] - path = deps/zig-wlroots - url = https://codeberg.org/ifreund/zig-wlroots diff --git a/PACKAGING.md b/PACKAGING.md index 0e465bd..315fe14 100644 --- a/PACKAGING.md +++ b/PACKAGING.md @@ -26,6 +26,45 @@ and is only compatible with that release and any patch releases. At the time of writing for example river is compatible with Zig 0.9.0 and 0.9.1 but not Zig 0.8.0 or 0.10.0. +## Zig Package Manager + +River uses the built-in Zig package manager for its (few) Zig dependencies. +By default, running `zig build` will fetch river's Zig dependencies from the +internet and store them in the global zig cache before building river. Since +accessing the internet is forbidden or at least frowned upon by most distro +packaging infrastructure, there are ways to fetch the Zig dependencies in a +separate step before building river: + +1. Fetch step with internet access: + + For each package in the `build.zig.zon` manifest file run the following command + with the tarball URL in the `build.zig.zon`: + + ``` + zig fetch --global-cache-dir /tmp/foobar $URL + ``` + + This command will download and unpack the tarball, hash the contents of the + tarball, and store the contents in the `/tmp/foobar/p/$HASH` directory. This + hash should match the corresponding hash field in the `build.zig.zon`. + +2. Build step with no internet access: + + The `--system` flag for `zig build` takes a path to an arbitrary directory in + which zig packages stored in subdirectories matching their hash can be found. + + ``` + zig build --system /tmp/foobar/p/ ... + ``` + + This flag will disable all internet access and error if a package is not found + in the provided directory. + +It is also possible for distros to distribute Zig package manager packages as +distro packages, although there are still some rough edges as the support for +this is not yet mature. See this patchset for Chimera Linux for an example of +how this can work: https://github.com/chimera-linux/cports/pull/1395 + ## Build options River is built using the Zig build system. To see all available build diff --git a/README.md b/README.md index 8b8c5b9..e3cd756 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,7 @@ commands to set up the user's configuration. ## Building -On cloning the repository, you must init and update the submodules as well -with e.g. - -``` -git submodule update --init -``` +Note: If you are packaging river for distribution, see [PACKAGING.md](PACKAGING.md). To compile river first ensure that you have the following dependencies installed. The "development" versions are required if applicable to your @@ -76,10 +71,7 @@ Then run, for example: ``` zig build -Doptimize=ReleaseSafe --prefix ~/.local install ``` -To enable experimental Xwayland support pass the `-Dxwayland` option as well. - -If you are packaging river for distribution, see also -[PACKAGING.md](PACKAGING.md). +To enable Xwayland support pass the `-Dxwayland` option as well. ## Usage diff --git a/build.zig b/build.zig index 286145e..b4eacc1 100644 --- a/build.zig +++ b/build.zig @@ -4,7 +4,7 @@ const Build = std.Build; const fs = std.fs; const mem = std.mem; -const Scanner = @import("deps/zig-wayland/build.zig").Scanner; +const Scanner = @import("zig-wayland").Scanner; /// While a river release is in development, this string should contain the version in development /// with the "-dev" suffix. @@ -132,32 +132,20 @@ pub fn build(b: *Build) !void { scanner.generate("zwlr_layer_shell_v1", 4); scanner.generate("zwlr_output_power_manager_v1", 1); - const wayland = b.createModule(.{ - .root_source_file = scanner.result, - .target = target, - }); + const wayland = b.createModule(.{ .root_source_file = scanner.result }); - const xkbcommon = b.createModule(.{ - .root_source_file = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" }, - .target = target, - }); - xkbcommon.linkSystemLibrary("xkbcommon", .{}); + const xkbcommon = b.dependency("zig-xkbcommon", .{}).module("xkbcommon"); + const pixman = b.dependency("zig-pixman", .{}).module("pixman"); - const pixman = b.createModule(.{ - .root_source_file = .{ .path = "deps/zig-pixman/pixman.zig" }, - .target = target, - }); - pixman.linkSystemLibrary("pixman-1", .{}); + const wlroots = b.dependency("zig-wlroots", .{}).module("wlroots"); + wlroots.addImport("wayland", wayland); + wlroots.addImport("xkbcommon", xkbcommon); + wlroots.addImport("pixman", pixman); - const wlroots = b.createModule(.{ - .root_source_file = .{ .path = "deps/zig-wlroots/src/wlroots.zig" }, - .imports = &.{ - .{ .name = "wayland", .module = wayland }, - .{ .name = "xkbcommon", .module = xkbcommon }, - .{ .name = "pixman", .module = pixman }, - }, - .target = target, - }); + // We need to ensure the wlroots include path obtained from pkg-config is + // exposed to the wlroots module for @cImport() to work. This seems to be + // the best way to do so with the current std.Build API. + wlroots.resolved_target = target; wlroots.linkSystemLibrary("wlroots", .{}); const flags = b.createModule(.{ .root_source_file = .{ .path = "common/flags.zig" } }); @@ -179,6 +167,9 @@ pub fn build(b: *Build) !void { river.linkSystemLibrary("libevdev"); river.linkSystemLibrary("libinput"); river.linkSystemLibrary("wayland-server"); + river.linkSystemLibrary("wlroots"); + river.linkSystemLibrary("xkbcommon"); + river.linkSystemLibrary("pixman-1"); river.root_module.addImport("wayland", wayland); river.root_module.addImport("xkbcommon", xkbcommon); @@ -191,7 +182,6 @@ pub fn build(b: *Build) !void { .file = .{ .path = "river/wlroots_log_wrapper.c" }, .flags = &.{ "-std=c99", "-O2" }, }); - river.linkSystemLibrary("wlroots"); // TODO: remove when zig issue #131 is implemented scanner.addCSource(river); diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..057490a --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,23 @@ +.{ + .name = "river", + .version = "0.4.0-dev", + .paths = .{""}, + .dependencies = .{ + .@"zig-pixman" = .{ + .url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.1.0.tar.gz", + .hash = "122014eeb4600a059bdcfe1c864862f17e6d5e4237e3bb7d6818f2a5583f6f4eb843", + }, + .@"zig-wayland" = .{ + .url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.1.0.tar.gz", + .hash = "1220b0f8f822c1625af7aae4cb3ab2c4ec1a4c0e99ef32867b2a8d88bb070b3e7f6d", + }, + .@"zig-wlroots" = .{ + .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.17.0.tar.gz", + .hash = "1220714d1cc39c3abb1d9c22a0b838d847ead099cb7d9931821490483f30c022e827", + }, + .@"zig-xkbcommon" = .{ + .url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.1.0.tar.gz", + .hash = "1220840390382c88caf9b0887f6cebbba3a7d05960b8b2ee6d80567b2950b71e5017", + }, + }, +} diff --git a/deps/zig-pixman b/deps/zig-pixman deleted file mode 160000 index 70bff91..0000000 --- a/deps/zig-pixman +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 70bff91beec4ad4c026dfc4465613e360dc85527 diff --git a/deps/zig-wayland b/deps/zig-wayland deleted file mode 160000 index 6be3eb9..0000000 --- a/deps/zig-wayland +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6be3eb9bff878bbf3f83a7c6862f1e14233606f5 diff --git a/deps/zig-wlroots b/deps/zig-wlroots deleted file mode 160000 index 941859c..0000000 --- a/deps/zig-wlroots +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 941859cd842b68cc5d20757e8708eb70295e9344 diff --git a/deps/zig-xkbcommon b/deps/zig-xkbcommon deleted file mode 160000 index 3a2eefd..0000000 --- a/deps/zig-xkbcommon +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3a2eefdad6b4d48757274061dd2b5df3b89a2bfd