Skip to content
Draft
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
10 changes: 5 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ pub fn build(b: *std.Build) !void {
b.installArtifact(lib);

// Set the include path
lib.addIncludePath(upstream.path("include"));
lib.addIncludePath(upstream.path("src"));
lib.root_module.addIncludePath(upstream.path("include"));
lib.root_module.addIncludePath(upstream.path("src"));

// Compile the generic sources
lib.addCSourceFiles(.{
lib.root_module.addCSourceFiles(.{
.files = &sources.generic,
.root = upstream.path("src"),
.flags = flags,
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn build(b: *std.Build) !void {
.ReleaseSmall, .ReleaseFast => @as(i64, 1),
},
});
lib.addConfigHeader(build_config_h);
lib.root_module.addConfigHeader(build_config_h);

// Configure the build for the target platform
switch (target.result.os.tag) {
Expand All @@ -125,7 +125,7 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
}),
});
example.linkLibrary(lib);
example.root_module.linkLibrary(lib);

const build_example_step = b.step("example", "Build the example app");
build_example_step.dependOn(&example.step);
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.name = .sdl,
.fingerprint = 0xec638ccbd103848b,
.version = "0.0.0",
.minimum_zig_version = "0.15.0",
.minimum_zig_version = "0.16.0-dev.2193+fc517bd01",
.dependencies = .{
.sdl = .{
.url = "https://github.com/libsdl-org/SDL/archive/refs/tags/release-3.4.0.tar.gz",
Expand Down
7 changes: 6 additions & 1 deletion src/example.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ const c = @cImport({
@cInclude("SDL3/SDL.h");
});

const Io = std.Io;

pub fn main() void {
var threaded_io: Io.Threaded = .init_single_threaded;
const io = threaded_io.io();

// Initialize SDL
if (!c.SDL_Init(c.SDL_INIT_VIDEO)) {
std.debug.panic("{s}", .{c.SDL_GetError()});
Expand Down Expand Up @@ -34,7 +39,7 @@ pub fn main() void {
var event: c.SDL_Event = undefined;
while (c.SDL_PollEvent(&event)) {
if (event.type == c.SDL_EVENT_QUIT) {
std.process.cleanExit();
std.process.cleanExit(io);
return;
}
}
Expand Down
117 changes: 60 additions & 57 deletions src/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ pub fn build(
{
// Set up the config include write file step
const generated = b.addWriteFiles();
lib.addIncludePath(generated.getDirectory());
lib.root_module.addIncludePath(generated.getDirectory());

// Provide the D-Bus headers
{
const dbus = b.dependency("dbus", .{});
lib.addIncludePath(dbus.path("."));
lib.root_module.addIncludePath(dbus.path("."));

const version_string = build_zon.dependencies.dbus.version;
const version = comptime std.SemanticVersion.parse(version_string) catch unreachable;
Expand All @@ -44,7 +44,10 @@ pub fn build(
.DBUS_VERSION = version_string,
},
);
_ = generated.addCopyFile(dbus_config.getOutput(), dbus_config.include_path);
_ = generated.addCopyFile(
dbus_config.getOutputFile(),
dbus_config.include_path,
);

if (target.cTypeByteSize(.int) == 2) {
dbus_config.addValues(.{
Expand Down Expand Up @@ -103,21 +106,21 @@ pub fn build(
// Provide the IBus headers
{
// The headers are here
lib.addIncludePath(b.dependency("ibus", .{}).path("src"));
lib.root_module.addIncludePath(b.dependency("ibus", .{}).path("src"));

// They depend on the GLib headers, which require some configuration
lib.addIncludePath(b.path("deps/glib/upstream/include"));
lib.addIncludePath(b.path("deps/glib/upstream/include/glib"));
lib.addIncludePath(b.path("deps/glib/upstream/include/gmodule"));
lib.addIncludePath(b.path("deps/glib/cached/include"));
lib.addIncludePath(b.path("deps/glib/cached/include/glib"));
lib.addIncludePath(b.path("deps/glib/cached/include/gmodule"));
lib.root_module.addIncludePath(b.path("deps/glib/upstream/include"));
lib.root_module.addIncludePath(b.path("deps/glib/upstream/include/glib"));
lib.root_module.addIncludePath(b.path("deps/glib/upstream/include/gmodule"));
lib.root_module.addIncludePath(b.path("deps/glib/cached/include"));
lib.root_module.addIncludePath(b.path("deps/glib/cached/include/glib"));
lib.root_module.addIncludePath(b.path("deps/glib/cached/include/gmodule"));

const glib_config = b.addConfigHeader(.{
.style = .{ .cmake = b.path("deps/glib/glibconfig.h.in") },
.include_path = "glibconfig.h",
}, .{});
_ = generated.addCopyFile(glib_config.getOutput(), glib_config.include_path);
_ = generated.addCopyFile(glib_config.getOutputFile(), glib_config.include_path);

// Configure glib
{
Expand Down Expand Up @@ -279,17 +282,17 @@ pub fn build(
}, .{
.GLIB_VERSIONS = @embedFile("../deps/glib/glib_versions.h"),
});
_ = generated.addCopyFile(version_h.getOutput(), version_h.include_path);
_ = generated.addCopyFile(version_h.getOutputFile(), version_h.include_path);

lib.addIncludePath(b.path("deps/glib/include"));
lib.root_module.addIncludePath(b.path("deps/glib/include"));
}

// Provide the X11 headers
{
{
const x11 = b.dependency("x11", .{});

lib.addIncludePath(x11.path("include"));
lib.root_module.addIncludePath(x11.path("include"));

const config = b.addConfigHeader(.{
.style = .{ .autoconf_undef = x11.path("include/X11/XlibConf.h.in") },
Expand All @@ -298,7 +301,7 @@ pub fn build(
.XTHREADS = 1,
.XUSE_MTSAFE_API = 1,
});
_ = generated.addCopyFile(config.getOutput(), config.include_path);
_ = generated.addCopyFile(config.getOutputFile(), config.include_path);
}

// Provide the Xcursor headers
Expand All @@ -314,13 +317,13 @@ pub fn build(
.XCURSOR_LIB_MINOR = @as(i64, version.minor),
.XCURSOR_LIB_REVISION = @as(i64, version.patch),
});
_ = generated.addCopyFile(config.getOutput(), config.include_path);
_ = generated.addCopyFile(config.getOutputFile(), config.include_path);
}
}

// Provide the liburing headers
{
lib.addIncludePath(b.path("deps/liburing/include"));
lib.root_module.addIncludePath(b.path("deps/liburing/include"));
const compat_h = b.addConfigHeader(.{
.style = .{ .autoconf_undef = b.path("deps/liburing/compat.h.in") },
.include_path = "liburing/compat.h",
Expand All @@ -334,7 +337,7 @@ pub fn build(
.HAS_FUTEX_WAITV = 1,
.HAS_IDTYPE_T = 1,
});
_ = generated.addCopyFile(compat_h.getOutput(), compat_h.include_path);
_ = generated.addCopyFile(compat_h.getOutputFile(), compat_h.include_path);

const version_string = build_zon.dependencies.decor.version;
const version = comptime std.SemanticVersion.parse(version_string) catch unreachable;
Expand All @@ -345,14 +348,14 @@ pub fn build(
.IO_URING_VERSION_MAJOR = @as(i64, version.major),
.IO_URING_VERSION_MINOR = @as(i64, version.minor),
});
_ = generated.addCopyFile(version_h.getOutput(), version_h.include_path);
_ = generated.addCopyFile(version_h.getOutputFile(), version_h.include_path);
}

// Provide the pipewire headers
{
const pipewire = b.dependency("pipewire", .{});
lib.addIncludePath(pipewire.path("spa/include"));
lib.addIncludePath(pipewire.path("src"));
lib.root_module.addIncludePath(pipewire.path("spa/include"));
lib.root_module.addIncludePath(pipewire.path("src"));
const version_string = build_zon.dependencies.pipewire.version;
const api_version_string = build_zon.dependencies.pipewire.api_version;
const version = comptime std.SemanticVersion.parse(version_string) catch unreachable;
Expand All @@ -365,7 +368,7 @@ pub fn build(
.PIPEWIRE_VERSION_MICRO = @as(i64, version.patch),
.PIPEWIRE_API_VERSION = api_version_string,
});
_ = generated.addCopyFile(config_h.getOutput(), config_h.include_path);
_ = generated.addCopyFile(config_h.getOutputFile(), config_h.include_path);
}

// Provide the pulseaudio headers
Expand All @@ -377,7 +380,7 @@ pub fn build(
else => "pulseaudio",
};
if (b.lazyDependency(pulseaudio_name, .{})) |pulseaudio| {
lib.addIncludePath(pulseaudio.path("src"));
lib.root_module.addIncludePath(pulseaudio.path("src"));
const version_string = build_zon.dependencies.pulseaudio.version;
const version = comptime std.SemanticVersion.parse(version_string) catch unreachable;
const api_version_string = build_zon.dependencies.pulseaudio.api_version;
Expand All @@ -393,16 +396,16 @@ pub fn build(
.PA_API_VERSION = api_version,
.PA_PROTOCOL_VERSION = protocol_version,
});
_ = generated.addCopyFile(version_h.getOutput(), version_h.include_path);
_ = generated.addCopyFile(version_h.getOutputFile(), version_h.include_path);
}
}

// Provide the Wayland headers
{
const wayland = b.dependency("wayland", .{});
lib.addIncludePath(wayland.path("src"));
lib.addIncludePath(wayland.path("cursor"));
lib.addIncludePath(wayland.path("egl"));
lib.root_module.addIncludePath(wayland.path("src"));
lib.root_module.addIncludePath(wayland.path("cursor"));
lib.root_module.addIncludePath(wayland.path("egl"));

// Provide the config header
const version_string = build_zon.dependencies.wayland.version;
Expand All @@ -416,14 +419,14 @@ pub fn build(
.WAYLAND_VERSION_MICRO = @as(i64, version.patch),
.WAYLAND_VERSION = version_string,
});
_ = generated.addCopyFile(version_h.getOutput(), version_h.include_path);
_ = generated.addCopyFile(version_h.getOutputFile(), version_h.include_path);
}

// Provide the Direct Rendering Manager headers
{
lib.addIncludePath(b.path("deps/drm/include"));
lib.addIncludePath(b.path("deps/drm/include/drm"));
lib.addIncludePath(b.path("deps/mesa/include/gbm"));
lib.root_module.addIncludePath(b.path("deps/drm/include"));
lib.root_module.addIncludePath(b.path("deps/drm/include/drm"));
lib.root_module.addIncludePath(b.path("deps/mesa/include/gbm"));
}

// Provide the Alsa headers
Expand All @@ -432,8 +435,8 @@ pub fn build(
_ = generated.addCopyDirectory(alsa.path("include"), "alsa", .{
.include_extensions = &.{".h"},
});
lib.addIncludePath(generated.getDirectory());
lib.addIncludePath(b.path("deps/alsa/include"));
lib.root_module.addIncludePath(generated.getDirectory());
lib.root_module.addIncludePath(b.path("deps/alsa/include"));
}

// Provide the Fribidi headers
Expand Down Expand Up @@ -467,7 +470,7 @@ pub fn build(

.FRIBIDI_MSVC_BUILD_PLACEHOLDER = "",
});
_ = generated.addCopyFile(version_h.getOutput(), version_h.include_path);
_ = generated.addCopyFile(version_h.getOutputFile(), version_h.include_path);

const unicode_version_h = b.addConfigHeader(.{
.style = .blank,
Expand All @@ -478,45 +481,45 @@ pub fn build(
.FRIBIDI_UNICODE_MINOR_VERSION = @as(i64, unicode_version.minor),
.FRIBIDI_UNICODE_MICRO_VERSION = @as(i64, unicode_version.patch),
});
_ = generated.addCopyFile(unicode_version_h.getOutput(), unicode_version_h.include_path);
_ = generated.addCopyFile(unicode_version_h.getOutputFile(), unicode_version_h.include_path);

lib.addIncludePath(fribidi.path("lib"));
lib.root_module.addIncludePath(fribidi.path("lib"));
}

// Provide upstream headers that don't require any special handling
lib.addIncludePath(b.dependency("egl", .{}).path("api"));
lib.addIncludePath(b.dependency("opengl", .{}).path("api"));
lib.addIncludePath(b.dependency("xkbcommon", .{}).path("include"));
lib.addIncludePath(b.dependency("xorgproto", .{}).path("include"));
lib.addIncludePath(b.dependency("xext", .{}).path("include"));
lib.addIncludePath(b.dependency("usb", .{}).path("libusb"));
lib.addIncludePath(b.dependency("xi", .{}).path("include"));
lib.addIncludePath(b.dependency("xfixes", .{}).path("include"));
lib.addIncludePath(b.dependency("xrandr", .{}).path("include"));
lib.addIncludePath(b.dependency("xrender", .{}).path("include"));
lib.addIncludePath(b.dependency("xscrnsaver", .{}).path("include"));
lib.addIncludePath(b.dependency("jack", .{}).path("common"));
lib.addIncludePath(b.dependency("sndio", .{}).path("libsndio"));
lib.addIncludePath(b.path("deps/wayland/protocols"));
lib.addIncludePath(b.dependency("decor", .{}).path("src"));
lib.addIncludePath(b.path("deps/mesa/include"));
lib.addIncludePath(b.dependency("thai", .{}).path("include"));
lib.root_module.addIncludePath(b.dependency("egl", .{}).path("api"));
lib.root_module.addIncludePath(b.dependency("opengl", .{}).path("api"));
lib.root_module.addIncludePath(b.dependency("xkbcommon", .{}).path("include"));
lib.root_module.addIncludePath(b.dependency("xorgproto", .{}).path("include"));
lib.root_module.addIncludePath(b.dependency("xext", .{}).path("include"));
lib.root_module.addIncludePath(b.dependency("usb", .{}).path("libusb"));
lib.root_module.addIncludePath(b.dependency("xi", .{}).path("include"));
lib.root_module.addIncludePath(b.dependency("xfixes", .{}).path("include"));
lib.root_module.addIncludePath(b.dependency("xrandr", .{}).path("include"));
lib.root_module.addIncludePath(b.dependency("xrender", .{}).path("include"));
lib.root_module.addIncludePath(b.dependency("xscrnsaver", .{}).path("include"));
lib.root_module.addIncludePath(b.dependency("jack", .{}).path("common"));
lib.root_module.addIncludePath(b.dependency("sndio", .{}).path("libsndio"));
lib.root_module.addIncludePath(b.path("deps/wayland/protocols"));
lib.root_module.addIncludePath(b.dependency("decor", .{}).path("src"));
lib.root_module.addIncludePath(b.path("deps/mesa/include"));
lib.root_module.addIncludePath(b.dependency("thai", .{}).path("include"));

// Provide vendored headers that don't require any special handling
lib.addIncludePath(b.path("deps/xcb/include"));
lib.addIncludePath(b.path("deps/udev/include"));
lib.root_module.addIncludePath(b.path("deps/xcb/include"));
lib.root_module.addIncludePath(b.path("deps/udev/include"));
}

// Add the platform specific SDL sources
lib.addCSourceFiles(.{
lib.root_module.addCSourceFiles(.{
.files = &(sources.unix ++ sources.linux ++ sources.x11 ++ sources.pthread),
.root = upstream.path("src"),
.flags = root.flags,
});

// Provide the Wayland protocols
for (@as([]const []const u8, &sources.wayland_protocols)) |xml| {
lib.addCSourceFile(.{
lib.root_module.addCSourceFile(.{
.file = b.path(b.pathJoin(&.{
"deps",
"wayland",
Expand Down
44 changes: 22 additions & 22 deletions src/macos.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@ pub fn build(
const upstream = b.dependency("sdl", .{});

// Add the platform specific dependency include paths
lib.addIncludePath(b.dependency("egl", .{}).path("api"));
lib.addIncludePath(b.dependency("opengl", .{}).path("api"));
lib.root_module.addIncludePath(b.dependency("egl", .{}).path("api"));
lib.root_module.addIncludePath(b.dependency("opengl", .{}).path("api"));

// Link with the platform specific system frameworks
lib.linkFramework("Cocoa");
lib.linkFramework("IOKit");
lib.linkFramework("ForceFeedback");
lib.linkFramework("CoreVideo");
lib.linkFramework("CoreAudio");
lib.linkFramework("CoreHaptics");
lib.linkFramework("CoreFoundation");
lib.linkFramework("CoreMedia");
lib.linkFramework("CoreGraphics");
lib.linkFramework("Carbon");
lib.linkFramework("Metal");
lib.linkFramework("QuartzCore");
lib.linkFramework("AudioToolbox");
lib.linkFramework("AVFoundation");
lib.linkFramework("Foundation");
lib.linkFramework("GameController");
lib.linkFramework("CoreBluetooth");
lib.linkFramework("UniformTypeIdentifiers");
lib.linkSystemLibrary("iconv");
lib.root_module.linkFramework("Cocoa", .{});
lib.root_module.linkFramework("IOKit", .{});
lib.root_module.linkFramework("ForceFeedback", .{});
lib.root_module.linkFramework("CoreVideo", .{});
lib.root_module.linkFramework("CoreAudio", .{});
lib.root_module.linkFramework("CoreHaptics", .{});
lib.root_module.linkFramework("CoreFoundation", .{});
lib.root_module.linkFramework("CoreMedia", .{});
lib.root_module.linkFramework("CoreGraphics", .{});
lib.root_module.linkFramework("Carbon", .{});
lib.root_module.linkFramework("Metal", .{});
lib.root_module.linkFramework("QuartzCore", .{});
lib.root_module.linkFramework("AudioToolbox", .{});
lib.root_module.linkFramework("AVFoundation", .{});
lib.root_module.linkFramework("Foundation", .{});
lib.root_module.linkFramework("GameController", .{});
lib.root_module.linkFramework("CoreBluetooth", .{});
lib.root_module.linkFramework("UniformTypeIdentifiers", .{});
lib.root_module.linkSystemLibrary("iconv", .{});

// Add the platform specific sources
const objc_flags = root.flags.* ++ [_][]const u8{"-fobjc-arc"};
lib.addCSourceFiles(.{
lib.root_module.addCSourceFiles(.{
.files = &(sources.cocoa ++ sources.darwin ++ sources.mac ++ sources.unix ++ sources.pthread),
.root = upstream.path("src"),
.flags = &objc_flags,
Expand Down
Loading