Skip to content

Commit

Permalink
Move wayland protocol implementation into its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmstill committed Mar 18, 2024
1 parent 2bc4402 commit 9afd15b
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 4 deletions.
4 changes: 3 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn build(b: *std.Build) void {
const pool = b.dependency("foxwhale_pool", .{ .target = target, .optimize = optimize });
const subset_pool = b.dependency("foxwhale_subset_pool", .{ .target = target, .optimize = optimize });
const iterable_pool = b.dependency("foxwhale_iterable_pool", .{ .target = target, .optimize = optimize });
const wayland = b.dependency("foxwhale_wayland", .{ .target = target, .optimize = optimize });

const exe = b.addExecutable(.{
.name = "foxwhale",
Expand All @@ -28,6 +29,7 @@ pub fn build(b: *std.Build) void {
exe.root_module.addImport("foxwhale-pool", pool.module("foxwhale-pool"));
exe.root_module.addImport("foxwhale-subset-pool", subset_pool.module("foxwhale-subset-pool"));
exe.root_module.addImport("foxwhale-iterable-pool", iterable_pool.module("foxwhale-iterable-pool"));
exe.root_module.addImport("foxwhale-wayland", wayland.module("foxwhale-wayland"));

exe.linkSystemLibrary("c");
exe.linkSystemLibrary("gl");
Expand Down Expand Up @@ -68,7 +70,7 @@ pub fn build(b: *std.Build) void {
const foxwhale_gen = b.dependency("foxwhale_gen", .{ .target = target, .optimize = optimize });
const foxwhale_gen_exe = foxwhale_gen.artifact("foxwhale-gen");

const output_path = "src/wl/protocols.zig";
const output_path = "foxwhale-wayland/src/protocols.zig";
const gen_cmd = b.addRunArtifact(foxwhale_gen_exe);
gen_cmd.addArg("server");
gen_cmd.addArg("--input-file");
Expand Down
1 change: 1 addition & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
.foxwhale_pool = .{ .path = "foxwhale-pool" },
.foxwhale_subset_pool = .{ .path = "foxwhale-subset-pool" },
.foxwhale_iterable_pool = .{ .path = "foxwhale-iterable-pool" },
.foxwhale_wayland = .{ .path = "foxwhale-wayland" },
},

// Specifies the set of files and directories that are included in this package.
Expand Down
37 changes: 37 additions & 0 deletions foxwhale-wayland/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const std = @import("std");

// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});

// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});

_ = b.addModule("foxwhale-wayland", .{
.root_source_file = .{ .path = "src/root.zig" },
});

// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const lib_unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/root.zig" },
.target = target,
.optimize = optimize,
});

const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);

// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
}
62 changes: 62 additions & 0 deletions foxwhale-wayland/build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.{
.name = "foxwhale-wayland",
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
// with this value.
//.minimum_zig_version = "0.11.0",

// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
//.example = .{
// // When updating this field to a new URL, be sure to delete the corresponding
// // `hash`, otherwise you are communicating that you expect to find the old hash at
// // the new URL.
// .url = "https://example.com/foo.tar.gz",
//
// // This is computed from the file contents of the directory of files that is
// // obtained after fetching `url` and applying the inclusion rules given by
// // `paths`.
// //
// // This field is the source of truth; packages do not come from a `url`; they
// // come from a `hash`. `url` is just one of many possible mirrors for how to
// // obtain a package matching this `hash`.
// //
// // Uses the [multihash](https://multiformats.io/multihash/) format.
// .hash = "...",
//
// // When this is provided, the package is found in a directory relative to the
// // build root. In this case the package's hash is irrelevant and therefore not
// // computed. This field and `url` are mutually exclusive.
// .path = "foo",
//},
},

// Specifies the set of files and directories that are included in this package.
// Only files and directories listed here are included in the `hash` that
// is computed for this package.
// Paths are relative to the build root. Use the empty string (`""`) to refer to
// the build root itself.
// A directory listed here means that all files within, recursively, are included.
.paths = .{
// This makes *all* files, recursively, included in this package. It is generally
// better to explicitly list the files and directories instead, to insure that
// fetching from tarballs, file system paths, and version control all result
// in the same contents hash.
"",
// For example...
//"build.zig",
//"build.zig.zon",
//"src",
//"LICENSE",
//"README.md",
},
}
File renamed without changes.
2 changes: 2 additions & 0 deletions foxwhale-wayland/src/root.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub const Wire = @import("wire.zig").Wire;
pub const Wayland = @import("protocols.zig").Wayland;
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const endian = builtin.cpu.arch.endian();

const log = std.log.scoped(.client);

pub const wl = @import("wl/protocols.zig").Wayland(.{
pub const wl = @import("foxwhale-wayland").Wayland(.{
.wl_surface = *Window,
.wl_subsurface = *Window,
.xdg_surface = *Window,
Expand Down
1 change: 0 additions & 1 deletion src/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const os = std.os;
const Event = @import("subsystem.zig").Event;
const SubsystemIterator = @import("subsystem.zig").SubsystemIterator;
const Client = @import("client.zig").Client;
const Wire = @import("wl/wire.zig").Wire;

const wl = @import("client.zig").wl;

Expand Down
1 change: 0 additions & 1 deletion src/view.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const std = @import("std");
const prot = @import("wl/protocols.zig");
const Focus = @import("focus.zig").Focus;
const Window = @import("resource/window.zig").Window;
const BackendOutput = @import("backend/backend.zig").BackendOutput;
Expand Down

0 comments on commit 9afd15b

Please sign in to comment.