Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
zig-version: [0.16.0]
zig-version: [0.17.0-dev.690+c5a61e899]
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![CI](https://github.com/Games-By-Mason/sdl_zig/actions/workflows/ci.yaml/badge.svg)](https://github.com/Games-By-Mason/sdl_zig/actions)

# SDL3 Zig
# SDL Zig

SDL3 ported to the Zig build system.

Expand Down
36 changes: 20 additions & 16 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const linux = @import("src/linux.zig");
const windows = @import("src/windows.zig");
const macos = @import("src/macos.zig");
const build_zon = @import("build.zig.zon");
const Translator = @import("translate_c").Translator;

const assert = std.debug.assert;

Expand Down Expand Up @@ -35,12 +36,6 @@ pub fn build(b: *std.Build) !void {
,
) orelse .static;

// Get the SO version. This is the same as the SDL version, but the major version is elided
// since it's baked into the name. This mirrors the official build process.
var sdl_so_version = comptime std.SemanticVersion.parse(build_zon.dependencies.sdl.version) catch unreachable;
assert(sdl_so_version.major == 3);
sdl_so_version.major = 0;

// Create the library
const lib = b.addLibrary(.{
.name = "SDL3",
Expand All @@ -50,7 +45,8 @@ pub fn build(b: *std.Build) !void {
.link_libc = true,
}),
.linkage = linkage,
.version = sdl_so_version,
.version = comptime std.SemanticVersion.parse(build_zon.dependencies.sdl.so_version)
catch unreachable,
});
switch (linkage) {
.dynamic => {
Expand Down Expand Up @@ -116,16 +112,24 @@ pub fn build(b: *std.Build) !void {
linux.addWaylandScannerStep(b);

// Translate the SDL headers and export them as a Zig module
const translate_c = b.addTranslateC(.{
.root_source_file = b.path("src/sdl.h"),
const translate_c = b.dependency("translate_c", .{});
const translator: Translator = .init(translate_c, .{
.c_source_file = b.path("src/sdl.h"),
.target = target,
.optimize = optimize,
// https://codeberg.org/ziglang/translate-c/issues/327
.optimize = switch (target.result.os.tag) {
.windows => switch (optimize) {
.ReleaseSafe => .ReleaseFast,
else => optimize,
},
else => optimize,
},
});
translate_c.defineCMacro("USING_GENERATED_CONFIG_H", "1");
translate_c.addIncludePath(upstream.path("include"));
translate_c.addIncludePath(upstream.path("src/video/khronos"));
const module = translate_c.addModule("sdl3");
module.linkLibrary(lib);
translator.defineCMacro("USING_GENERATED_CONFIG_H", "1");
translator.addIncludePath(upstream.path("include"));
translator.addIncludePath(upstream.path("src/video/khronos"));
translator.mod.linkLibrary(lib);
try b.modules.putNoClobber(b.graph.arena, "sdl3", translator.mod);

// Add the example
const example = b.addExecutable(.{
Expand All @@ -136,7 +140,7 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
}),
});
example.root_module.addImport("sdl3", module);
example.root_module.addImport("sdl3", translator.mod);

const build_example_step = b.step("example", "Build the example app");
build_example_step.dependOn(&example.step);
Expand Down
19 changes: 14 additions & 5 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
.{
.name = .sdl,
.fingerprint = 0xec638ccbd103848b,
.version = "1.0.1+3.4.4",
.minimum_zig_version = "0.16.0",
.version = "1.0.1+3.4.x",
.minimum_zig_version = "0.17.0",
.dependencies = .{
.sdl = .{
.url = "https://github.com/libsdl-org/SDL/archive/refs/tags/release-3.4.4.tar.gz",
.hash = "N-V-__8AAL9L9AJxY67Fhxp52_VHlLps195MF3irmi4z8Qge",
.version = "3.4.4",
.url = "git+https://github.com/libsdl-org/SDL#release-3.4.12",
.hash = "N-V-__8AAD0-9wIMzG8dsliLwybOaKczJZMCLORvnK3Bnqq4",
.version = "3.4.12",
// This is the same as the SDL version, but the major version is elided since it's baked
// into the name. This mirrors the official build process. Additionally, it must be an
// actual semantic version, it cannot for example include "x" which is used for release
// candidates.
.so_version = "0.4.12",
},
.translate_c = .{
.url = "git+https://codeberg.org/ziglang/translate-c#ee20d6a7366abfcb9290184cbdbb0372a08bd9cf",
.hash = "translate_c-0.0.0-Q_BUWrw7BwCthYKOQHra8x2h-TxIHPLQnRnP2WbHL9HX",
},
.dbus = .{
.version = "1.16.0",
Expand Down
1 change: 1 addition & 0 deletions src/sdl.zon
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@
"video/vivante/SDL_vivantevideo.c",
"video/vivante/SDL_vivantevulkan.c",
"video/wayland/SDL_waylandclipboard.c",
"video/wayland/SDL_waylandutil.c",
"video/wayland/SDL_waylandcolor.c",
"video/wayland/SDL_waylanddatamanager.c",
"video/wayland/SDL_waylanddyn.c",
Expand Down