deps: add option to statically link C dependencies
This commit is contained in:
parent
7da2841ec7
commit
d8f44c96a9
31
build.zig
31
build.zig
|
@ -1,9 +1,15 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const static = b.option(
|
||||
bool,
|
||||
"static",
|
||||
"Statically link SDL2 and FreeType. Not supported on Linux.",
|
||||
) orelse false;
|
||||
|
||||
const zenolith_mod = b.dependency("zenolith", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
|
@ -16,8 +22,27 @@ pub fn build(b: *std.Build) void {
|
|||
.optimize = optimize,
|
||||
.link_libc = true,
|
||||
});
|
||||
mod.linkSystemLibrary("SDL2", .{});
|
||||
mod.linkSystemLibrary("freetype2", .{});
|
||||
|
||||
if (static) {
|
||||
if (mod.resolved_target.?.result.os.tag == .linux) {
|
||||
std.debug.print(
|
||||
\\Statically linking SDL2 is not currently possible on Linux targets.
|
||||
\\This is because andrew's SDL fork with the Zig build system doesn't work
|
||||
\\on Linux and is, in fact, not my fault :)
|
||||
\\
|
||||
, .{});
|
||||
return error.StaticLinkingNotSupported;
|
||||
}
|
||||
|
||||
const sdl2_dep = b.dependency("sdl2", .{ .target = target, .optimize = optimize });
|
||||
const freetype_dep = b.dependency("freetype", .{ .target = target, .optimize = optimize });
|
||||
|
||||
mod.linkLibrary(sdl2_dep.artifact("SDL2"));
|
||||
mod.linkLibrary(freetype_dep.artifact("freetype"));
|
||||
} else {
|
||||
mod.linkSystemLibrary("SDL2", .{});
|
||||
mod.linkSystemLibrary("freetype2", .{});
|
||||
}
|
||||
|
||||
const main_tests = b.addTest(.{
|
||||
.root_source_file = .{ .path = "src/main.zig" },
|
||||
|
|
|
@ -13,5 +13,14 @@
|
|||
.url = "git+https://git.mzte.de/zenolith/zenolith.git#ad388687cd205079aab75074a542eadc79490df7",
|
||||
.hash = "12201677a81b6f8133bbe9c7d3b2afc07b61bf632a070d13d57f995827022f6a1f54",
|
||||
},
|
||||
|
||||
.sdl2 = .{
|
||||
.url = "git+https://git.mzte.de/mirrors/SDL.git#db4a162db2f6f59f737d03f441455dc9524d5793",
|
||||
.hash = "1220c5360c9c71c215baa41b46ec18d0711059b48416a2b1cf96c7c2d87b2e8e4cf6",
|
||||
},
|
||||
.freetype = .{
|
||||
.url = "https://git.mzte.de/mirrors/freetype.git#398638fd1cb723e478658ea371fe3be1a4dce0ae.tar.gz",
|
||||
.hash = "12208c57b72e3fb5c8d5d3e667e2e21ca1d9e2b6fc3f84182b320f63933f591823da",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -134,7 +134,6 @@ pub fn run(
|
|||
);
|
||||
if (peep_ret < 0) return error.GetEvents;
|
||||
|
||||
log.debug("got {} events", .{peep_ret});
|
||||
const events = ev_buf[0..@intCast(peep_ret)];
|
||||
|
||||
// This code is responsible for building one KeyInput event out of consecutive
|
||||
|
@ -317,6 +316,14 @@ pub fn run(
|
|||
}
|
||||
}
|
||||
|
||||
/// Quits a running application by submitting a quit event to the event queue,
|
||||
/// making the application exit after all queued events were processed.
|
||||
pub fn quit(self: *Sdl2Platform) !void {
|
||||
_ = self; // Pretend this isn't global state.
|
||||
var ev = c.SDL_Event{ .quit = .{ .type = c.SDL_QUIT } };
|
||||
if (c.SDL_PushEvent(&ev) < 0) return error.PushEvent;
|
||||
}
|
||||
|
||||
pub fn deinit(self: Sdl2Platform) void {
|
||||
_ = c.FT_Done_FreeType(self.freetype);
|
||||
c.SDL_DestroyRenderer(self.renderer);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pub const c = @cImport({
|
||||
@cInclude("SDL.h");
|
||||
@cInclude("SDL2/SDL.h");
|
||||
@cInclude("freetype/freetype.h");
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue