build: switch to the Zig package manager

No more git submodules!
This commit is contained in:
Isaac Freund 2024-05-20 11:33:04 +02:00
parent 045ee7bd25
commit 958f8798b6
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
9 changed files with 79 additions and 51 deletions

12
.gitmodules vendored
View File

@ -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

View File

@ -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 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. 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 ## Build options
River is built using the Zig build system. To see all available build River is built using the Zig build system. To see all available build

View File

@ -51,12 +51,7 @@ commands to set up the user's configuration.
## Building ## Building
On cloning the repository, you must init and update the submodules as well Note: If you are packaging river for distribution, see [PACKAGING.md](PACKAGING.md).
with e.g.
```
git submodule update --init
```
To compile river first ensure that you have the following dependencies To compile river first ensure that you have the following dependencies
installed. The "development" versions are required if applicable to your 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 zig build -Doptimize=ReleaseSafe --prefix ~/.local install
``` ```
To enable experimental Xwayland support pass the `-Dxwayland` option as well. To enable Xwayland support pass the `-Dxwayland` option as well.
If you are packaging river for distribution, see also
[PACKAGING.md](PACKAGING.md).
## Usage ## Usage

View File

@ -4,7 +4,7 @@ const Build = std.Build;
const fs = std.fs; const fs = std.fs;
const mem = std.mem; 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 /// While a river release is in development, this string should contain the version in development
/// with the "-dev" suffix. /// with the "-dev" suffix.
@ -132,32 +132,20 @@ pub fn build(b: *Build) !void {
scanner.generate("zwlr_layer_shell_v1", 4); scanner.generate("zwlr_layer_shell_v1", 4);
scanner.generate("zwlr_output_power_manager_v1", 1); scanner.generate("zwlr_output_power_manager_v1", 1);
const wayland = b.createModule(.{ const wayland = b.createModule(.{ .root_source_file = scanner.result });
.root_source_file = scanner.result,
.target = target,
});
const xkbcommon = b.createModule(.{ const xkbcommon = b.dependency("zig-xkbcommon", .{}).module("xkbcommon");
.root_source_file = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" }, const pixman = b.dependency("zig-pixman", .{}).module("pixman");
.target = target,
});
xkbcommon.linkSystemLibrary("xkbcommon", .{});
const pixman = b.createModule(.{ const wlroots = b.dependency("zig-wlroots", .{}).module("wlroots");
.root_source_file = .{ .path = "deps/zig-pixman/pixman.zig" }, wlroots.addImport("wayland", wayland);
.target = target, wlroots.addImport("xkbcommon", xkbcommon);
}); wlroots.addImport("pixman", pixman);
pixman.linkSystemLibrary("pixman-1", .{});
const wlroots = b.createModule(.{ // We need to ensure the wlroots include path obtained from pkg-config is
.root_source_file = .{ .path = "deps/zig-wlroots/src/wlroots.zig" }, // exposed to the wlroots module for @cImport() to work. This seems to be
.imports = &.{ // the best way to do so with the current std.Build API.
.{ .name = "wayland", .module = wayland }, wlroots.resolved_target = target;
.{ .name = "xkbcommon", .module = xkbcommon },
.{ .name = "pixman", .module = pixman },
},
.target = target,
});
wlroots.linkSystemLibrary("wlroots", .{}); wlroots.linkSystemLibrary("wlroots", .{});
const flags = b.createModule(.{ .root_source_file = .{ .path = "common/flags.zig" } }); 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("libevdev");
river.linkSystemLibrary("libinput"); river.linkSystemLibrary("libinput");
river.linkSystemLibrary("wayland-server"); river.linkSystemLibrary("wayland-server");
river.linkSystemLibrary("wlroots");
river.linkSystemLibrary("xkbcommon");
river.linkSystemLibrary("pixman-1");
river.root_module.addImport("wayland", wayland); river.root_module.addImport("wayland", wayland);
river.root_module.addImport("xkbcommon", xkbcommon); river.root_module.addImport("xkbcommon", xkbcommon);
@ -191,7 +182,6 @@ pub fn build(b: *Build) !void {
.file = .{ .path = "river/wlroots_log_wrapper.c" }, .file = .{ .path = "river/wlroots_log_wrapper.c" },
.flags = &.{ "-std=c99", "-O2" }, .flags = &.{ "-std=c99", "-O2" },
}); });
river.linkSystemLibrary("wlroots");
// TODO: remove when zig issue #131 is implemented // TODO: remove when zig issue #131 is implemented
scanner.addCSource(river); scanner.addCSource(river);

23
build.zig.zon Normal file
View File

@ -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",
},
},
}

1
deps/zig-pixman vendored

@ -1 +0,0 @@
Subproject commit 70bff91beec4ad4c026dfc4465613e360dc85527

1
deps/zig-wayland vendored

@ -1 +0,0 @@
Subproject commit 6be3eb9bff878bbf3f83a7c6862f1e14233606f5

1
deps/zig-wlroots vendored

@ -1 +0,0 @@
Subproject commit 941859cd842b68cc5d20757e8708eb70295e9344

1
deps/zig-xkbcommon vendored

@ -1 +0,0 @@
Subproject commit 3a2eefdad6b4d48757274061dd2b5df3b89a2bfd