Skip to content

Commit

Permalink
build: update to Zig 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
ifreund committed May 20, 2024
1 parent 680cb8e commit 033cad4
Show file tree
Hide file tree
Showing 51 changed files with 281 additions and 267 deletions.
8 changes: 4 additions & 4 deletions .builds/alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ tasks:
sudo ninja -C build/ install
cd ..
wget -nv https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz
wget -nv https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz
# Remove a lot of useless lines from tar output.
tar -xvf zig-linux-x86_64-0.11.0.tar.xz 1>/dev/null
sudo mv zig-linux-x86_64-0.11.0/zig /usr/bin/
sudo mv zig-linux-x86_64-0.11.0/lib /usr/lib/zig
tar -xvf zig-linux-x86_64-0.12.0.tar.xz 1>/dev/null
sudo mv zig-linux-x86_64-0.12.0/zig /usr/bin/
sudo mv zig-linux-x86_64-0.12.0/lib /usr/lib/zig
- build: |
cd river
zig build
Expand Down
8 changes: 4 additions & 4 deletions .builds/archlinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ tasks:
sudo ninja -C build/ install
cd ..
wget -nv https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz
wget -nv https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz
# Remove a lot of useless lines from tar output.
tar -xvf zig-linux-x86_64-0.11.0.tar.xz 1>/dev/null
sudo mv zig-linux-x86_64-0.11.0/zig /usr/bin/
sudo mv zig-linux-x86_64-0.11.0/lib /usr/lib/zig
tar -xvf zig-linux-x86_64-0.12.0.tar.xz 1>/dev/null
sudo mv zig-linux-x86_64-0.12.0/zig /usr/bin/
sudo mv zig-linux-x86_64-0.12.0/lib /usr/lib/zig
- build: |
cd river
zig build
Expand Down
8 changes: 4 additions & 4 deletions .builds/freebsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ tasks:
sudo ninja -C build/ install
cd ..
wget -nv https://ziglang.org/download/0.11.0/zig-freebsd-x86_64-0.11.0.tar.xz
wget -nv https://ziglang.org/download/0.12.0/zig-freebsd-x86_64-0.12.0.tar.xz
# Remove a lot of useless lines from tar output.
tar -xvf zig-freebsd-x86_64-0.11.0.tar.xz 1>/dev/null
sudo mv zig-freebsd-x86_64-0.11.0/zig /usr/bin/
sudo mv zig-freebsd-x86_64-0.11.0/lib /usr/lib/zig
tar -xvf zig-freebsd-x86_64-0.12.0.tar.xz 1>/dev/null
sudo mv zig-freebsd-x86_64-0.12.0/zig /usr/bin/
sudo mv zig-freebsd-x86_64-0.12.0/lib /usr/lib/zig
- build: |
cd river
zig build
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ To compile river first ensure that you have the following dependencies
installed. The "development" versions are required if applicable to your
distribution.

- [zig](https://ziglang.org/download/) 0.11
- [zig](https://ziglang.org/download/) 0.12
- wayland
- wayland-protocols
- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.17.2
Expand Down
79 changes: 43 additions & 36 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn build(b: *Build) !void {
if (mem.endsWith(u8, version, "-dev")) {
var ret: u8 = undefined;

const git_describe_long = b.execAllowFail(
const git_describe_long = b.runAllowFail(
&.{ "git", "-C", b.build_root.path orelse ".", "describe", "--long" },
&ret,
.Inherit,
Expand All @@ -91,12 +91,12 @@ pub fn build(b: *Build) !void {
const scanner = Scanner.create(b, .{});

scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
scanner.addSystemProtocol("staging/cursor-shape/cursor-shape-v1.xml");
scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml");
scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");
scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml");
scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml");
scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");
scanner.addSystemProtocol("unstable/tablet/tablet-unstable-v2.xml");
scanner.addSystemProtocol("staging/cursor-shape/cursor-shape-v1.xml");
scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml");

scanner.addCustomProtocol("protocol/river-control-unstable-v1.xml");
scanner.addCustomProtocol("protocol/river-status-unstable-v1.xml");
Expand Down Expand Up @@ -131,63 +131,70 @@ 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(.{ .source_file = scanner.result });
const wayland = b.createModule(.{
.root_source_file = scanner.result,
.target = target,
});

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

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

const wlroots = b.createModule(.{
.source_file = .{ .path = "deps/zig-wlroots/src/wlroots.zig" },
.dependencies = &.{
.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,
});
wlroots.linkSystemLibrary("wlroots", .{});

const flags = b.createModule(.{ .source_file = .{ .path = "common/flags.zig" } });
const globber = b.createModule(.{ .source_file = .{ .path = "common/globber.zig" } });
const flags = b.createModule(.{ .root_source_file = .{ .path = "common/flags.zig" } });
const globber = b.createModule(.{ .root_source_file = .{ .path = "common/globber.zig" } });

{
const river = b.addExecutable(.{
.name = "river",
.root_source_file = .{ .path = "river/main.zig" },
.target = target,
.optimize = optimize,
.strip = strip,
});
river.addOptions("build_options", options);
river.root_module.addOptions("build_options", options);

river.linkLibC();
river.linkSystemLibrary("libevdev");
river.linkSystemLibrary("libinput");

river.addModule("wayland", wayland);
river.linkSystemLibrary("wayland-server");

river.addModule("xkbcommon", xkbcommon);
river.linkSystemLibrary("xkbcommon");

river.addModule("pixman", pixman);
river.linkSystemLibrary("pixman-1");
river.root_module.addImport("wayland", wayland);
river.root_module.addImport("xkbcommon", xkbcommon);
river.root_module.addImport("pixman", pixman);
river.root_module.addImport("wlroots", wlroots);
river.root_module.addImport("flags", flags);
river.root_module.addImport("globber", globber);

river.addModule("wlroots", wlroots);
river.linkSystemLibrary("wlroots");

river.addModule("flags", flags);
river.addModule("globber", globber);
river.addCSourceFile(.{
.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);

river.strip = strip;
river.pie = pie;
river.omit_frame_pointer = omit_frame_pointer;
river.root_module.omit_frame_pointer = omit_frame_pointer;

b.installArtifact(river);
}
Expand All @@ -198,19 +205,19 @@ pub fn build(b: *Build) !void {
.root_source_file = .{ .path = "riverctl/main.zig" },
.target = target,
.optimize = optimize,
.strip = strip,
});
riverctl.addOptions("build_options", options);
riverctl.root_module.addOptions("build_options", options);

riverctl.addModule("flags", flags);
riverctl.addModule("wayland", wayland);
riverctl.root_module.addImport("flags", flags);
riverctl.root_module.addImport("wayland", wayland);
riverctl.linkLibC();
riverctl.linkSystemLibrary("wayland-client");

scanner.addCSource(riverctl);

riverctl.strip = strip;
riverctl.pie = pie;
riverctl.omit_frame_pointer = omit_frame_pointer;
riverctl.root_module.omit_frame_pointer = omit_frame_pointer;

b.installArtifact(riverctl);
}
Expand All @@ -221,19 +228,19 @@ pub fn build(b: *Build) !void {
.root_source_file = .{ .path = "rivertile/main.zig" },
.target = target,
.optimize = optimize,
.strip = strip,
});
rivertile.addOptions("build_options", options);
rivertile.root_module.addOptions("build_options", options);

rivertile.addModule("flags", flags);
rivertile.addModule("wayland", wayland);
rivertile.root_module.addImport("flags", flags);
rivertile.root_module.addImport("wayland", wayland);
rivertile.linkLibC();
rivertile.linkSystemLibrary("wayland-client");

scanner.addCSource(rivertile);

rivertile.strip = strip;
rivertile.pie = pie;
rivertile.omit_frame_pointer = omit_frame_pointer;
rivertile.root_module.omit_frame_pointer = omit_frame_pointer;

b.installArtifact(rivertile);
}
Expand Down
6 changes: 3 additions & 3 deletions common/flags.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const std = @import("std");
const mem = std.mem;

pub const Flag = struct {
name: []const u8,
name: [:0]const u8,
kind: enum { boolean, arg },
};

Expand All @@ -37,7 +37,7 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {

pub const Flags = flags_type: {
var fields: []const std.builtin.Type.StructField = &.{};
inline for (flags) |flag| {
for (flags) |flag| {
const field: std.builtin.Type.StructField = switch (flag.kind) {
.boolean => .{
.name = flag.name,
Expand All @@ -57,7 +57,7 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {
fields = fields ++ [_]std.builtin.Type.StructField{field};
}
break :flags_type @Type(.{ .Struct = .{
.layout = .Auto,
.layout = .auto,
.fields = fields,
.decls = &.{},
.is_tuple = false,
Expand Down
2 changes: 1 addition & 1 deletion deps/zig-wayland
Submodule zig-wayland updated from 73fed0 to 6be3eb
2 changes: 1 addition & 1 deletion deps/zig-wlroots
Submodule zig-wlroots updated from 5bc01a to 941859
2 changes: 1 addition & 1 deletion deps/zig-xkbcommon
Submodule zig-xkbcommon updated from 7e09b3 to 3a2eef
2 changes: 1 addition & 1 deletion river/Control.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn init(control: *Control) !void {
}

fn handleServerDestroy(listener: *wl.Listener(*wl.Server), _: *wl.Server) void {
const control = @fieldParentPtr(Control, "server_destroy", listener);
const control: *Control = @fieldParentPtr("server_destroy", listener);
control.global.destroy();
control.args_map.deinit();
}
Expand Down
Loading

0 comments on commit 033cad4

Please sign in to comment.