Skip to content

Commit

Permalink
build: switch to the Zig package manager
Browse files Browse the repository at this point in the history
No more git submodules!
  • Loading branch information
ifreund committed May 20, 2024
1 parent 045ee7b commit 958f879
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 54 deletions.
12 changes: 0 additions & 12 deletions .gitmodules

This file was deleted.

39 changes: 39 additions & 0 deletions PACKAGING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
46 changes: 18 additions & 28 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 xkbcommon = b.createModule(.{
.root_source_file = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" },
.target = target,
});
xkbcommon.linkSystemLibrary("xkbcommon", .{});

const pixman = b.createModule(.{
.root_source_file = .{ .path = "deps/zig-pixman/pixman.zig" },
.target = target,
});
pixman.linkSystemLibrary("pixman-1", .{});

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,
});
const wayland = b.createModule(.{ .root_source_file = scanner.result });

const xkbcommon = b.dependency("zig-xkbcommon", .{}).module("xkbcommon");
const pixman = b.dependency("zig-pixman", .{}).module("pixman");

const wlroots = b.dependency("zig-wlroots", .{}).module("wlroots");
wlroots.addImport("wayland", wayland);
wlroots.addImport("xkbcommon", xkbcommon);
wlroots.addImport("pixman", pixman);

// 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" } });
Expand All @@ -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);
Expand All @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -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 change: 0 additions & 1 deletion deps/zig-pixman
Submodule zig-pixman deleted from 70bff9
1 change: 0 additions & 1 deletion deps/zig-wayland
Submodule zig-wayland deleted from 6be3eb
1 change: 0 additions & 1 deletion deps/zig-wlroots
Submodule zig-wlroots deleted from 941859
1 change: 0 additions & 1 deletion deps/zig-xkbcommon
Submodule zig-xkbcommon deleted from 3a2eef

0 comments on commit 958f879

Please sign in to comment.