Skip to content

Commit cf2c274

Browse files
committed
Gets example working in Zig, but still using SDL + needs a lot of cleanup
1 parent 35059f9 commit cf2c274

File tree

7 files changed

+22665
-21688
lines changed

7 files changed

+22665
-21688
lines changed

build.zig

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -284,34 +284,30 @@ pub fn build(b: *std.Build) void {
284284
});
285285
}
286286

287-
// Build the examples
288287
{
289-
const screen_play = b.addExecutable(.{
290-
.name = "screen_play",
288+
const video_play = b.addExecutable(.{
289+
.name = "video-play",
291290
.root_module = b.createModule(.{
291+
.root_source_file = b.path("src/video_play.zig"),
292292
.target = target,
293293
.optimize = optimize,
294294
}),
295295
});
296-
screen_play.addCSourceFile(.{
297-
.file = b.path("src/screen-play.c"),
298-
});
299-
b.installArtifact(screen_play);
300-
301-
screen_play.linkLibC();
302296

303297
const sdl = b.dependency("sdl", .{
304298
.optimize = optimize,
305299
.target = target,
306300
});
307-
screen_play.linkLibrary(sdl.artifact("SDL3"));
301+
302+
video_play.linkLibrary(sdl.artifact("SDL3"));
303+
b.installArtifact(video_play);
308304

309305
var dep: std.Build.Dependency = .{ .builder = b };
310-
linkAndInstall(b, &dep, screen_play);
306+
linkAndInstall(b, &dep, video_play);
311307

312-
const run_step = b.step("screen-play", "Run the screen-play example");
308+
const run_step = b.step("video-play", "Run the video-play example");
313309

314-
const run_cmd = b.addRunArtifact(screen_play);
310+
const run_cmd = b.addRunArtifact(video_play);
315311
run_cmd.setCwd(.{ .cwd_relative = b.getInstallPath(.bin, "") });
316312
run_step.dependOn(&run_cmd.step);
317313

@@ -349,6 +345,18 @@ const flags: []const []const u8 = &.{
349345
"-Wno-pedantic",
350346
"-D_GNU_SOURCE",
351347
"-DFASTPATH",
348+
// Translate C can't translate some of the variadic functions API so they get demoted to
349+
// externs. However, since they're present only in headers and marked as `SPA_API_IMPL` which
350+
// which defaults to `static inline`, the symbols end up being missing. We instead mark them as
351+
// weak so that we don't get duplicate symbols, but are still able to reference the C
352+
// implementations.
353+
"-DSPA_API_IMPL=__attribute__((weak))",
354+
355+
"-Ddlopen=__wrap_dlopen",
356+
"-Ddlclose=__wrap_dlclose",
357+
"-Ddlsym=__wrap_dlsym",
358+
"-Ddlerror=__wrap_dlerror",
359+
"-Ddlinfo=__wrap_dlinfo",
352360
};
353361

354362
pub const PluginAndModuleCtx = struct {

build.zig.zon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
.url = "git+https://github.com/allyourcodebase/SDL3#af9c32ce4824e0ad4337447434c40f2b672faf94",
2121
.hash = "sdl-0.0.0-i4QD0btgqAABajEXrQnyZr1xVsk7LM48w2nBmuQ5gdfr",
2222
},
23+
.zin = .{
24+
.url = "git+https://github.com/marler8997/zin#d3e230690f09debdb99dffe4586ad19f9dfb4716",
25+
.hash = "zin-0.0.0-W7QDx6kKAwCVg-wWMO4FdpvZMH66NJpc9wFDdxp5c8E2",
26+
},
2327
},
2428
.paths = .{
2529
"LICENSE",

0 commit comments

Comments
 (0)