gamemode: Fix overcomplications and @import with symlinks
This commit is contained in:
parent
38a44ea3b3
commit
4ee9ba1000
6 changed files with 13 additions and 102 deletions
|
|
@ -1,56 +0,0 @@
|
|||
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 linkFromSystem(exe: *LibExeObjStep) void {
|
||||
exe.linkSystemLibrary("gamemode");
|
||||
}
|
||||
|
||||
/// Build and link gamemode
|
||||
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 ".";
|
||||
}
|
||||
|
|
@ -1,20 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
rm ./c/*
|
||||
cd ./c
|
||||
rm ./gamemode_client.h
|
||||
wget "https://github.com/FeralInteractive/gamemode/raw/master/lib/gamemode_client.h"
|
||||
wget "https://github.com/FeralInteractive/gamemode/raw/master/lib/client_impl.c"
|
||||
wget "https://github.com/FeralInteractive/gamemode/raw/master/lib/client_loader.c"
|
||||
|
||||
cd ./common
|
||||
wget "https://github.com/FeralInteractive/gamemode/raw/b11d2912e280acb87d9ad114d6c7cd8846c4ef02/common/common-helpers.c"
|
||||
wget "https://github.com/FeralInteractive/gamemode/raw/b11d2912e280acb87d9ad114d6c7cd8846c4ef02/common/common-pidfds.c"
|
||||
wget "https://github.com/FeralInteractive/gamemode/raw/b11d2912e280acb87d9ad114d6c7cd8846c4ef02/common/common-helpers.h"
|
||||
wget "https://github.com/FeralInteractive/gamemode/raw/b11d2912e280acb87d9ad114d6c7cd8846c4ef02/common/common-pidfds.h"
|
||||
|
||||
cd ../..
|
||||
|
||||
# The output from translate-c isn't perfect, so we need this fix
|
||||
zig translate-c ./c/gamemode_client.h -lc | sed "s#functor\(.*\)@alignCast\(.*\),\(.*\))#functor\1\3#" > ./src/gamemode_client.zig
|
||||
|
||||
rm -r ./zig-cache
|
||||
zig translate-c ./gamemode_client.h -lc | sed "s#functor\(.*\)@alignCast\(.*\),\(.*\))#functor\1\3#" > ./gamemode_client.zig
|
||||
|
|
|
|||
|
|
@ -644,7 +644,7 @@ pub inline fn gamemode_error_string() [*c]const u8 {
|
|||
_ = @sizeOf(c_int);
|
||||
break :blk blk_1: {
|
||||
break :blk_1 if (REAL_internal_gamemode_error_string != @ptrCast(api_call_return_cstring, @alignCast(@import("std").meta.alignment(fn () callconv(.C) [*c]const u8), @intToPtr(?*anyopaque, @as(c_int, 0))))) {} else {
|
||||
__assert_fail("REAL_internal_gamemode_error_string != NULL", "./c/gamemode_client.h", @bitCast(c_uint, @as(c_int, 237)), "const char *gamemode_error_string(void)");
|
||||
__assert_fail("REAL_internal_gamemode_error_string != NULL", "gamemode_client.h", @bitCast(c_uint, @as(c_int, 237)), "const char *gamemode_error_string(void)");
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -658,7 +658,7 @@ pub inline fn gamemode_request_start() c_int {
|
|||
_ = @sizeOf(c_int);
|
||||
break :blk blk_1: {
|
||||
break :blk_1 if (REAL_internal_gamemode_request_start != @ptrCast(api_call_return_int, @alignCast(@import("std").meta.alignment(fn () callconv(.C) c_int), @intToPtr(?*anyopaque, @as(c_int, 0))))) {} else {
|
||||
__assert_fail("REAL_internal_gamemode_request_start != NULL", "./c/gamemode_client.h", @bitCast(c_uint, @as(c_int, 263)), "int gamemode_request_start(void)");
|
||||
__assert_fail("REAL_internal_gamemode_request_start != NULL", "gamemode_client.h", @bitCast(c_uint, @as(c_int, 263)), "int gamemode_request_start(void)");
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -675,7 +675,7 @@ pub inline fn gamemode_request_end() c_int {
|
|||
_ = @sizeOf(c_int);
|
||||
break :blk blk_1: {
|
||||
break :blk_1 if (REAL_internal_gamemode_request_end != @ptrCast(api_call_return_int, @alignCast(@import("std").meta.alignment(fn () callconv(.C) c_int), @intToPtr(?*anyopaque, @as(c_int, 0))))) {} else {
|
||||
__assert_fail("REAL_internal_gamemode_request_end != NULL", "./c/gamemode_client.h", @bitCast(c_uint, @as(c_int, 292)), "int gamemode_request_end(void)");
|
||||
__assert_fail("REAL_internal_gamemode_request_end != NULL", "gamemode_client.h", @bitCast(c_uint, @as(c_int, 292)), "int gamemode_request_end(void)");
|
||||
};
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue