Skip to content

Commit 108eb91

Browse files
committed
Fix build for Zig 0.15.0-dev.1034+bd97b6618
1 parent 005c641 commit 108eb91

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

build.zig

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn build(b: *std.Build) void {
6666
const cache_include = std.fs.path.join(b.allocator, &.{ b.sysroot.?, "cache", "sysroot", "include" }) catch @panic("Out of memory");
6767
defer b.allocator.free(cache_include);
6868

69-
var dir = std.fs.openDirAbsolute(cache_include, std.fs.Dir.OpenDirOptions{ .access_sub_paths = true, .no_follow = true }) catch @panic("No emscripten cache. Generate it!");
69+
var dir = std.fs.openDirAbsolute(cache_include, .{ .access_sub_paths = true, .no_follow = true }) catch @panic("No emscripten cache. Generate it!");
7070
dir.close();
7171

7272
lib.addIncludePath(.{ .cwd_relative = cache_include });
@@ -152,11 +152,13 @@ pub fn build(b: *std.Build) void {
152152
lib.addConfigHeader(config_header);
153153
lib.installHeader(config_header.getOutput(), "SDL2/SDL_config.h");
154154

155+
// TODO: Remove compatibility shim when Zig 0.15.0 is the minimum required version.
156+
const fmt_shim = if (@hasDecl(std, "Io")) "{f}" else "{}";
155157
const revision_header = b.addConfigHeader(.{
156158
.style = .{ .cmake = b.path("include/SDL_revision.h.cmake") },
157159
.include_path = "SDL_revision.h",
158160
}, .{
159-
.SDL_REVISION = b.fmt("SDL-{}", .{lib.version.?}),
161+
.SDL_REVISION = b.fmt("SDL-" ++ fmt_shim, .{lib.version.?}),
160162
.SDL_VENDOR_INFO = "allyourcodebase.com",
161163
});
162164
lib.addConfigHeader(revision_header);
@@ -166,11 +168,15 @@ pub fn build(b: *std.Build) void {
166168
const use_hidapi = b.option(bool, "use_hidapi", "Use hidapi shared library") orelse t.abi.isAndroid();
167169

168170
if (use_hidapi) {
169-
const hidapi_lib = b.addSharedLibrary(.{
171+
const hidapi_lib = b.addLibrary(.{
170172
.name = "hidapi",
171-
.target = target,
172-
.optimize = optimize,
173-
.link_libc = true,
173+
.linkage = .dynamic,
174+
.root_module = b.createModule(.{
175+
.target = target,
176+
.optimize = optimize,
177+
.link_libc = true,
178+
.link_libcpp = true,
179+
}),
174180
});
175181
hidapi_lib.addIncludePath(sdl_include_path);
176182
hidapi_lib.addIncludePath(b.path("include-pregen"));
@@ -182,7 +188,6 @@ pub fn build(b: *std.Build) void {
182188
.flags = &.{"-std=c++11"},
183189
});
184190
hidapi_lib.linkSystemLibrary("log");
185-
hidapi_lib.linkLibCpp();
186191
lib.linkLibrary(hidapi_lib);
187192
b.installArtifact(hidapi_lib);
188193
}

0 commit comments

Comments
 (0)