gamemode: WIP building gamemode from source

This commit is contained in:
PiergiorgioZagaria 2022-07-27 10:24:53 +02:00 committed by Stephen Gutekanst
parent 613f03ef13
commit d256d071e0
3 changed files with 36 additions and 7 deletions

View file

@ -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 ".";
}