93 lines
2.7 KiB
Zig
93 lines
2.7 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.build.Builder) !void {
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
const lib = b.addSharedLibrary(.{
|
|
.name = "rofi_nheko",
|
|
.root_source_file = .{ .path = "src/main.zig" },
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
|
|
lib.linkLibC();
|
|
lib.linkSystemLibrary("glib-2.0");
|
|
lib.linkSystemLibrary("gio-unix-2.0");
|
|
lib.linkSystemLibrary("rofi");
|
|
lib.linkSystemLibrary("cairo");
|
|
|
|
lib.addModule("glib-log", b.dependency("glib_log", .{}).module("zig-glib-log"));
|
|
|
|
lib.strip = optimize != .Debug;
|
|
|
|
const install_step = b.addInstallArtifact(lib, .{
|
|
.dest_dir = .{ .override = .{ .custom = "lib/rofi" } },
|
|
});
|
|
|
|
b.getInstallStep().dependOn(&install_step.step);
|
|
|
|
lib.step.dependOn(&(try NhdbusGen.init(lib)).step);
|
|
}
|
|
|
|
const NhdbusGen = struct {
|
|
step: std.build.Step,
|
|
lib: *std.build.LibExeObjStep,
|
|
|
|
pub fn init(lib: *std.build.LibExeObjStep) !*NhdbusGen {
|
|
const self = try lib.step.owner.allocator.create(NhdbusGen);
|
|
self.* = .{
|
|
.step = std.build.Step.init(.{
|
|
.id = .custom,
|
|
.name = "nhdbus-gen",
|
|
.owner = lib.step.owner,
|
|
.makeFn = make,
|
|
}),
|
|
.lib = lib,
|
|
};
|
|
return self;
|
|
}
|
|
|
|
fn make(step: *std.build.Step, _: *std.Progress.Node) !void {
|
|
const self = @fieldParentPtr(NhdbusGen, "step", step);
|
|
const b = self.lib.step.owner;
|
|
|
|
const c_basename = "nhdbus";
|
|
|
|
const nhdbus_path = try std.fmt.allocPrint(
|
|
b.allocator,
|
|
"{s}/c/{s}.c",
|
|
.{ b.cache_root.path.?, c_basename },
|
|
);
|
|
defer b.allocator.free(nhdbus_path);
|
|
|
|
const include_path = nhdbus_path[0 .. nhdbus_path.len - c_basename.len - ".c".len];
|
|
|
|
try std.fs.cwd().makePath(include_path);
|
|
|
|
self.lib.addIncludePath(.{ .path = include_path });
|
|
self.lib.addCSourceFile(.{ .file = .{ .path = nhdbus_path }, .flags = &.{} });
|
|
|
|
var child = std.ChildProcess.init(&.{
|
|
"gdbus-codegen",
|
|
"--interface-prefix",
|
|
"im.nheko.Nheko",
|
|
"--generate-c-code",
|
|
c_basename,
|
|
"--c-namespace",
|
|
c_basename,
|
|
"--c-generate-object-manager",
|
|
"--output-directory",
|
|
include_path,
|
|
"nheko-dbus.xml",
|
|
}, b.allocator);
|
|
|
|
const term = try child.spawnAndWait();
|
|
|
|
switch (term) {
|
|
.Exited => |code| if (code != 0) return error.UnexpectedExitCode,
|
|
else => return error.UncleanExit,
|
|
}
|
|
}
|
|
};
|