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 19, 2024
1 parent 5b3f13d commit b0877e5
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 27 deletions.
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

47 changes: 43 additions & 4 deletions PACKAGING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ despite the drawbacks of depending on a relatively immature language/toolchain.

## Source tarballs

Source tarballs with stable checksums and git submodule sources included may
be found on the [codeberg releases](https://codeberg.org/ifreund/waylock/releases)
page. These tarballs are signed with the PGP key available on my website at
Source tarballs with stable checksums may be found on the [codeberg
releases](https://codeberg.org/ifreund/waylock/releases) page. These
tarballs are signed with the PGP key available on my website at
<https://isaacfreund.com/public_key.txt>.

For the 0.4.0 release for example, the tarball and signature URLs are:
Expand All @@ -26,6 +26,45 @@ and is only compatible with that release and any patch releases. At the time
of writing for example waylock is compatible with Zig 0.9.0 and 0.9.1 but
not Zig 0.8.0 or 0.10.0.

## Zig Package Manager

Waylock uses the built-in Zig package manager for its (few) Zig dependencies.
By default, running `zig build` will fetch waylock's Zig dependencies from the
internet and store them in the global zig cache before building waylock. 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 waylock:

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

Waylock is built using the Zig build system. To see all available build
Expand Down Expand Up @@ -75,7 +114,7 @@ in the first place. For greatest effect, both may be used.
- `-Doptimize=ReleaseSmall`: Optimize for binary size,
disable all assertions and runtime safety checks.

Please use `-Doptimize=ReleaseSafe` when building waylock for general
Please use `-Doptimize=ReleaseSafe` when building waylock for general use. This
software is not at all demanding when it comes to CPU execution speed and the
increased safety is more than worth the binary size trade-off in my opinion.

Expand Down
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ more robust than previous client-side Wayland screen locking approaches.
Importantly, the screenlocker crashing does not cause the session to be
unlocked.

Install from your [package manager](https://repology.org/project/waylock/versions)

The main repository is on [codeberg](https://codeberg.org/ifreund/waylock),
which is where the issue tracker may be found and where contributions are accepted.

Expand All @@ -14,16 +16,7 @@ and [github](https://github.com/ifreund/waylock).

## Building

<a href="https://repology.org/project/waylock/versions">
<img src="https://repology.org/badge/vertical-allrepos/waylock.svg" alt="Packaging status" align="right">
</a>

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 waylock for distribution, see [PACKAGING.md](PACKAGING.md).

To compile waylock first ensure that you have the following dependencies
installed:
Expand All @@ -47,9 +40,6 @@ likely `/etc/pam.d` by default. Therefore care must be taken if
installing to a prefix other than `/usr` to ensure the configuration file
[pam.d/waylock](pam.d/waylock) is found by PAM.

If you are packaging waylock for distribution, see also
[PACKAGING.md](PACKAGING.md).

## Usage

See the `waylock(1)` man page or the output of `waylock -h` for an overview
Expand Down
4 changes: 2 additions & 2 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 waylock release is in development, this string should contain the version in
/// development with the "-dev" suffix.
Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn build(b: *Build) !void {
scanner.generate("wp_single_pixel_buffer_manager_v1", 1);

const wayland = b.createModule(.{ .root_source_file = scanner.result });
const xkbcommon = b.createModule(.{ .root_source_file = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" } });
const xkbcommon = b.dependency("zig-xkbcommon", .{}).module("xkbcommon");

const waylock = b.addExecutable(.{
.name = "waylock",
Expand Down
15 changes: 15 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.{
.name = "waylock",
.version = "1.1.0-dev",
.paths = .{""},
.dependencies = .{
.@"zig-wayland" = .{
.url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.1.0.tar.gz",
.hash = "1220b0f8f822c1625af7aae4cb3ab2c4ec1a4c0e99ef32867b2a8d88bb070b3e7f6d",
},
.@"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-wayland
Submodule zig-wayland deleted from fe0463
1 change: 0 additions & 1 deletion deps/zig-xkbcommon
Submodule zig-xkbcommon deleted from 85a796

0 comments on commit b0877e5

Please sign in to comment.