From f71578f9a6d9a2e27c43ed53a82f7b991951c724 Mon Sep 17 00:00:00 2001 From: Mason Remaley Date: Thu, 15 Jan 2026 01:31:32 -0800 Subject: [PATCH] Updates to latest Zig --- build.zig | 10 ++--- build.zig.zon | 2 +- src/example.zig | 7 ++- src/linux.zig | 117 +++++++++++++++++++++++++----------------------- src/macos.zig | 44 +++++++++--------- src/windows.zig | 32 ++++++------- 6 files changed, 110 insertions(+), 102 deletions(-) diff --git a/build.zig b/build.zig index 3d56563a..05437873 100644 --- a/build.zig +++ b/build.zig @@ -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, @@ -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) { @@ -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); diff --git a/build.zig.zon b/build.zig.zon index 157f746a..7c4251f7 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -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", diff --git a/src/example.zig b/src/example.zig index 78025b5c..80444525 100644 --- a/src/example.zig +++ b/src/example.zig @@ -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()}); @@ -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; } } diff --git a/src/linux.zig b/src/linux.zig index 925c53de..10aae4f4 100644 --- a/src/linux.zig +++ b/src/linux.zig @@ -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; @@ -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(.{ @@ -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 { @@ -279,9 +282,9 @@ 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 @@ -289,7 +292,7 @@ pub fn build( { 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") }, @@ -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 @@ -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", @@ -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; @@ -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; @@ -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 @@ -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; @@ -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; @@ -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 @@ -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 @@ -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, @@ -478,37 +481,37 @@ 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, @@ -516,7 +519,7 @@ pub fn build( // 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", diff --git a/src/macos.zig b/src/macos.zig index bfd4e8b3..3f1b03e9 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -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, diff --git a/src/windows.zig b/src/windows.zig index 5d403cee..228a2e4f 100644 --- a/src/windows.zig +++ b/src/windows.zig @@ -16,32 +16,32 @@ 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 libraries - lib.linkSystemLibrary("advapi32"); - lib.linkSystemLibrary("gdi32"); - lib.linkSystemLibrary("imm32"); - lib.linkSystemLibrary("kernel32"); - lib.linkSystemLibrary("ole32"); - lib.linkSystemLibrary("oleaut32"); - lib.linkSystemLibrary("setupapi"); - lib.linkSystemLibrary("shell32"); - lib.linkSystemLibrary("user32"); - lib.linkSystemLibrary("uuid"); - lib.linkSystemLibrary("version"); - lib.linkSystemLibrary("winmm"); + lib.root_module.linkSystemLibrary("advapi32", .{}); + lib.root_module.linkSystemLibrary("gdi32", .{}); + lib.root_module.linkSystemLibrary("imm32", .{}); + lib.root_module.linkSystemLibrary("kernel32", .{}); + lib.root_module.linkSystemLibrary("ole32", .{}); + lib.root_module.linkSystemLibrary("oleaut32", .{}); + lib.root_module.linkSystemLibrary("setupapi", .{}); + lib.root_module.linkSystemLibrary("shell32", .{}); + lib.root_module.linkSystemLibrary("user32", .{}); + lib.root_module.linkSystemLibrary("uuid", .{}); + lib.root_module.linkSystemLibrary("version", .{}); + lib.root_module.linkSystemLibrary("winmm", .{}); // Add the platform specific sources - lib.addCSourceFiles(.{ + lib.root_module.addCSourceFiles(.{ .files = &sources.windows, .root = upstream.path("src"), .flags = root.flags, }); if (lib.linkage == .dynamic) { - lib.addWin32ResourceFile(.{ .file = upstream.path("src/core/windows/version.rc") }); + lib.root_module.addWin32ResourceFile(.{ .file = upstream.path("src/core/windows/version.rc") }); } // Set the platform specific build config