Skip to content

Commit ea1a260

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

File tree

6 files changed

+22703
-21121
lines changed

6 files changed

+22703
-21121
lines changed

build.zig

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,41 @@ pub fn build(b: *std.Build) void {
321321
run_cmd.addArgs(args);
322322
}
323323
}
324+
325+
{
326+
const screen_play = b.addExecutable(.{
327+
.name = "zscreen_play",
328+
.root_module = b.createModule(.{
329+
.root_source_file = b.path("src/screen_play.zig"),
330+
.target = target,
331+
.optimize = optimize,
332+
}),
333+
});
334+
335+
const sdl = b.dependency("sdl", .{
336+
.optimize = optimize,
337+
.target = target,
338+
});
339+
340+
screen_play.linkLibrary(sdl.artifact("SDL3"));
341+
screen_play.addIncludePath(b.path("src")); // XXX: temp
342+
b.installArtifact(screen_play);
343+
344+
var dep: std.Build.Dependency = .{ .builder = b };
345+
linkAndInstall(b, &dep, screen_play);
346+
347+
const run_step = b.step("zscreen-play", "Run the screen-play example");
348+
349+
const run_cmd = b.addRunArtifact(screen_play);
350+
run_cmd.setCwd(.{ .cwd_relative = b.getInstallPath(.bin, "") });
351+
run_step.dependOn(&run_cmd.step);
352+
353+
run_cmd.step.dependOn(b.getInstallStep());
354+
355+
if (b.args) |args| {
356+
run_cmd.addArgs(args);
357+
}
358+
}
324359
}
325360

326361
/// You may call this externally to link to libpipewire and install its dependencies alongside the
@@ -349,6 +384,19 @@ const flags: []const []const u8 = &.{
349384
"-Wno-pedantic",
350385
"-D_GNU_SOURCE",
351386
"-DFASTPATH",
387+
// Translate C can't translate some of the variadic functions API so they get demoted to
388+
// externs. However, since they're present only in headers and marked as `SPA_API_IMPL` which
389+
// which defaults to `static inline`, the symbols end up being missing. We instead mark them as
390+
// weak so that we don't get duplicate symbols, but are still able to reference the C
391+
// implementations.
392+
"-DSPA_API_IMPL=__attribute__((weak))",
393+
394+
// XXX: better way to do this?
395+
"-Ddlopen=__wrap_dlopen",
396+
"-Ddlclose=__wrap_dlclose",
397+
"-Ddlsym=__wrap_dlsym",
398+
"-Ddlerror=__wrap_dlerror",
399+
"-Ddlinfo=__wrap_dlinfo",
352400
};
353401

354402
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)