gamemode: WIP building gamemode from source
This commit is contained in:
parent
613f03ef13
commit
d256d071e0
3 changed files with 36 additions and 7 deletions
|
|
@ -230,8 +230,9 @@ pub const App = struct {
|
|||
if (target.os.tag == .linux) {
|
||||
exe.addPackage(gamemode.pkg);
|
||||
// TODO: choose between system lib vs buildlib?
|
||||
gamemode.link(exe);
|
||||
// gamemode.buildAndLink(b, exe);
|
||||
gamemode.linkFromSystem(exe);
|
||||
// gamemode.linkFromSource(b, exe, .{});
|
||||
// gamemode.linkFromBinary(exe);
|
||||
}
|
||||
|
||||
break :blk exe;
|
||||
|
|
|
|||
|
|
@ -1,32 +1,56 @@
|
|||
const std = @import("std");
|
||||
const LibExeObjStep = std.build.LibExeObjStep;
|
||||
|
||||
pub const pkg = std.build.Pkg{
|
||||
.name = "gamemode",
|
||||
.source = .{ .path = thisDir() ++ "/src/gamemode.zig" },
|
||||
};
|
||||
|
||||
pub const Options = struct {
|
||||
libexecdir: []const u8 = "",
|
||||
sysconfdir: []const u8 = "",
|
||||
gamemode_version: []const u8 = "",
|
||||
|
||||
// Seems to be the only option the c files for libgamemode use
|
||||
have_fn_pidfd_open: bool = true,
|
||||
};
|
||||
|
||||
/// Link system library gamemode
|
||||
pub fn link(exe: *std.build.LibExeObjStep) void {
|
||||
pub fn linkFromSystem(exe: *LibExeObjStep) void {
|
||||
exe.linkSystemLibrary("gamemode");
|
||||
}
|
||||
|
||||
// TODO: to build we still need to generate a config file called build_common.h
|
||||
// (see https://github.com/FeralInteractive/gamemode/blob/4dc99dff76218718763a6b07fc1900fa6d1dafd9/meson.build) line 151
|
||||
|
||||
/// Build and link gamemode
|
||||
pub fn buildAndLink(b: *std.build.Builder, exe: *std.build.LibExeObjStep) void {
|
||||
pub fn linkFromSource(b: *std.build.Builder, exe: *LibExeObjStep, opts: Options) void {
|
||||
var build_config = std.fs.createFileAbsolute((comptime thisDir()) ++ "/c/common/build-config.h", .{}) catch unreachable;
|
||||
defer build_config.close();
|
||||
const writer = build_config.writer();
|
||||
writer.print(
|
||||
\\#define LIBEXECDIR "{s}"
|
||||
\\#define SYSCONFDIR "{s}"
|
||||
\\#define GAMEMODE_VERSION "{s}"
|
||||
\\#define HAVE_FN_PIDFD_OPEN {}
|
||||
, .{ opts.libexecdir, opts.sysconfdir, opts.gamemode_version, @boolToInt(opts.have_fn_pidfd_open) }) catch unreachable;
|
||||
|
||||
const lib_common = b.addStaticLibrary("common", null);
|
||||
lib_common.addCSourceFiles(&.{ (comptime thisDir()) ++ "/c/common/common-helpers.c", (comptime thisDir()) ++ "/c/common/common-pidfds.c" }, &.{});
|
||||
lib_common.addIncludePath((comptime thisDir()) ++ "/c/common/");
|
||||
lib_common.linkLibC();
|
||||
|
||||
const lib_gamemode = b.addSharedLibrarySource("gamemode", null, .unversioned);
|
||||
lib_gamemode.addCSourceFile((comptime thisDir()) ++ "/c/client_impl.c", &.{});
|
||||
lib_gamemode.addIncludePath((comptime thisDir()) ++ "/c/common/");
|
||||
lib_gamemode.linkLibC();
|
||||
lib_gamemode.linkSystemLibrary("dbus-1");
|
||||
lib_gamemode.linkLibrary(lib_common);
|
||||
|
||||
exe.linkLibrary(lib_gamemode);
|
||||
}
|
||||
|
||||
// TODO:
|
||||
/// Build from provided shared library binary
|
||||
// pub fn linkFromBinary(exe: *LibExeObjStep) void {}
|
||||
|
||||
fn thisDir() []const u8 {
|
||||
return std.fs.path.dirname(@src().file) orelse ".";
|
||||
}
|
||||
|
|
|
|||
4
gamemode-zig/c/common/build-config.h
Normal file
4
gamemode-zig/c/common/build-config.h
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#define LIBEXECDIR ""
|
||||
#define SYSCONFDIR ""
|
||||
#define GAMEMODE_VERSION ""
|
||||
#define HAVE_FN_PIDFD_OPEN 1
|
||||
Loading…
Add table
Add a link
Reference in a new issue