From e2ee06b97a2b017cd2a3e5a1784b42bc7cf23b8a Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 24 Mar 2025 21:35:07 +0800 Subject: [PATCH 1/8] Update build for 0.14 --- build.zig | 36 ++++++++++++++++----------------- build.zig.zon | 5 +++-- build/freetype/build.zig | 14 ++++++------- build/wayland_scanner/build.zig | 4 ++-- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/build.zig b/build.zig index f6e8bc1..d5ef338 100644 --- a/build.zig +++ b/build.zig @@ -12,7 +12,7 @@ pub fn build(b: *std.Build) !void { const sdl_ttf_dep = b.dependency("sdl_ttf", .{}); const freetype_dep = b.dependency("freetype", .{}); const wayland_scanner_dep = b.dependency("wayland_scanner", .{ - .target = b.host, + .target = b.graph.host, .optimize = .ReleaseFast, }); const font_dep = b.dependency("fonts", .{}); @@ -41,12 +41,12 @@ pub fn build(b: *std.Build) !void { .ReleaseFast, .ReleaseSmall, .ReleaseSafe => 0, .Debug => 3, }; - lib.defineCMacro("SDL_ASSERT_LEVEL", b.fmt("{d}", .{SDL_ASSERT_LEVEL})); + lib.root_module.addCMacro("SDL_ASSERT_LEVEL", b.fmt("{d}", .{SDL_ASSERT_LEVEL})); if (optimize != .Debug) { - lib.defineCMacro("NDEBUG", "1"); - lib.defineCMacro("__FILE__", "\"__FILE__\""); - lib.defineCMacro("__LINE__", "0"); + lib.root_module.addCMacro("NDEBUG", "1"); + lib.root_module.addCMacro("__FILE__", "\"__FILE__\""); + lib.root_module.addCMacro("__LINE__", "0"); } lib.linkLibC(); @@ -65,7 +65,7 @@ pub fn build(b: *std.Build) !void { lib.linkSystemLibrary("version"); lib.linkSystemLibrary("oleaut32"); lib.linkSystemLibrary("ole32"); - lib.defineCMacro("SDL_USE_BUILTIN_OPENGL_DEFINITIONS", "1"); + lib.root_module.addCMacro("SDL_USE_BUILTIN_OPENGL_DEFINITIONS", "1"); }, .macos => { lib.addCSourceFiles(.{ @@ -78,7 +78,7 @@ pub fn build(b: *std.Build) !void { .files = &objective_c_src_files, .flags = &.{"-fobjc-arc"}, }); - lib.defineCMacro("SDL_USE_BUILTIN_OPENGL_DEFINITIONS", "1"); + lib.root_module.addCMacro("SDL_USE_BUILTIN_OPENGL_DEFINITIONS", "1"); // TODO: re-check which frameworks are needed lib.linkFramework("AudioToolbox"); @@ -94,14 +94,14 @@ pub fn build(b: *std.Build) !void { lib.linkFramework("CoreVideo"); lib.linkFramework("ForceFeedback"); lib.linkFramework("Foundation"); - lib.linkFrameworkWeak("GameController"); + lib.linkFramework("GameController"); lib.linkFramework("IOKit"); - lib.linkFrameworkWeak("Metal"); - lib.linkFrameworkWeak("QuartzCore"); - lib.linkFrameworkWeak("UniformTypeIdentifiers"); + lib.linkFramework("Metal"); + lib.linkFramework("QuartzCore"); + lib.linkFramework("UniformTypeIdentifiers"); lib.linkSystemLibrary("objc"); - const sdk = std.zig.system.darwin.getSdk(b.allocator, b.host.result) orelse + const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse @panic("macOS SDK is missing"); lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); lib.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); @@ -376,7 +376,7 @@ pub fn build(b: *std.Build) !void { inline for (std.meta.fields(@TypeOf(values))) |f| { const value = b.fmt("{any}", .{@field(values, f.name)}); - lib.defineCMacro(f.name, value); + lib.root_module.addCMacro(f.name, value); } // SDL3_DYNAMIC_API=/my/actual/libSDL3.so.0 @@ -387,7 +387,7 @@ pub fn build(b: *std.Build) !void { // Avoid // SDL/include/build_config/SDL_build_config_minimal.h - lib.defineCMacro("SDL_build_config_minimal_h_", "1"); + lib.root_module.addCMacro("SDL_build_config_minimal_h_", "1"); //-- @@ -523,7 +523,7 @@ pub fn build(b: *std.Build) !void { SDL_ttf.linkLibrary(freetype_dep.artifact("freetype")); if (target.result.os.tag == .macos) { - const sdk = std.zig.system.darwin.getSdk(b.allocator, b.host.result) orelse + const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse @panic("macOS SDK is missing"); SDL_ttf.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); SDL_ttf.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); @@ -582,7 +582,7 @@ pub fn build(b: *std.Build) !void { exe.root_module.addImport("sdl", module); if (target.result.os.tag == .macos) { - const sdk = std.zig.system.darwin.getSdk(b.allocator, b.host.result) orelse + const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse @panic("macOS SDK is missing"); exe.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); exe.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); @@ -855,7 +855,7 @@ pub fn build(b: *std.Build) !void { exe.linkLibrary(test_utils); if (target.result.os.tag == .macos) { - const sdk = std.zig.system.darwin.getSdk(b.allocator, b.host.result) orelse + const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse @panic("macOS SDK is missing"); exe.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); exe.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); @@ -928,7 +928,7 @@ pub fn build(b: *std.Build) !void { exe.linkLibrary(lib); if (target.result.os.tag == .macos) { - const sdk = std.zig.system.darwin.getSdk(b.allocator, b.host.result) orelse + const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse @panic("macOS SDK is missing"); exe.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); exe.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); diff --git a/build.zig.zon b/build.zig.zon index b9851ca..20693ab 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -3,8 +3,9 @@ // SPDX-License-Identifier: Zlib .{ - .name = "sdl", - .version = "0.0.0", + .name = .sdl, + .version = "0.0.1", + .fingerprint = 0xec638ccb9c209e38, .paths = .{""}, .dependencies = .{ .sdl = .{ diff --git a/build/freetype/build.zig b/build/freetype/build.zig index d3f77f1..6026a2d 100644 --- a/build/freetype/build.zig +++ b/build/freetype/build.zig @@ -20,9 +20,9 @@ pub fn build(b: *std.Build) !void { }); { if (optimize != .Debug) { - lib.defineCMacro("NDEBUG", "1"); - lib.defineCMacro("__FILE__", "\"__FILE__\""); - lib.defineCMacro("__LINE__", "0"); + lib.root_module.addCMacro("NDEBUG", "1"); + lib.root_module.addCMacro("__FILE__", "\"__FILE__\""); + lib.root_module.addCMacro("__LINE__", "0"); } lib.addCSourceFiles(.{ @@ -72,9 +72,9 @@ pub fn build(b: *std.Build) !void { .flags = &.{}, }); - lib.defineCMacro("FT2_BUILD_LIBRARY", "1"); - lib.defineCMacro("HAVE_UNISTD_H", ""); - lib.defineCMacro("HAVE_FCNTL_H", ""); + lib.root_module.addCMacro("FT2_BUILD_LIBRARY", "1"); + lib.root_module.addCMacro("HAVE_UNISTD_H", ""); + lib.root_module.addCMacro("HAVE_FCNTL_H", ""); switch (target.result.os.tag) { .windows => { @@ -109,7 +109,7 @@ pub fn build(b: *std.Build) !void { lib.installHeadersDirectory(freetype_dep.path("include/freetype"), "freetype", .{}); if (target.result.os.tag == .macos) { - const sdk = std.zig.system.darwin.getSdk(b.allocator, b.host.result) orelse + const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse @panic("macOS SDK is missing"); lib.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); lib.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); diff --git a/build/wayland_scanner/build.zig b/build/wayland_scanner/build.zig index 77cec0f..e491f4e 100644 --- a/build/wayland_scanner/build.zig +++ b/build/wayland_scanner/build.zig @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) !void { const expat = b.addStaticLibrary(.{ .name = "expat", - .target = b.host, + .target = b.graph.host, .optimize = optimize, }); { @@ -68,7 +68,7 @@ pub fn build(b: *std.Build) !void { const wayland_scanner = b.addExecutable(.{ .name = "wayland-scanner", - .target = b.host, + .target = b.graph.host, .optimize = optimize, }); { From 30da8388f8d96628b32e99d937b7d8c794cd69f3 Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 1 Apr 2025 10:20:06 +0800 Subject: [PATCH 2/8] Zig 0.14 fingerprint field for child packages --- build/fonts/build.zig.zon | 3 ++- build/freetype/build.zig.zon | 3 ++- build/wayland_scanner/build.zig.zon | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/build/fonts/build.zig.zon b/build/fonts/build.zig.zon index a40d593..9239bd0 100644 --- a/build/fonts/build.zig.zon +++ b/build/fonts/build.zig.zon @@ -3,8 +3,9 @@ // SPDX-License-Identifier: Zlib .{ - .name = "fonts", + .name = .fonts, .version = "0.0.0", + .fingerprint = 0x7303e8fb6c57db3a, .paths = .{""}, .dependencies = .{ .intel_one_mono = .{ diff --git a/build/freetype/build.zig.zon b/build/freetype/build.zig.zon index 2b3c07c..6b8bef9 100644 --- a/build/freetype/build.zig.zon +++ b/build/freetype/build.zig.zon @@ -3,8 +3,9 @@ // SPDX-License-Identifier: Zlib .{ - .name = "freetype", + .name = .freetype, .version = "0.0.0", + .fingerprint = 0xac2059b689838d78, .paths = .{""}, .dependencies = .{ // NOTE: matches SDL_ttf's external/freetype submodule diff --git a/build/wayland_scanner/build.zig.zon b/build/wayland_scanner/build.zig.zon index 85986a5..e9ee660 100644 --- a/build/wayland_scanner/build.zig.zon +++ b/build/wayland_scanner/build.zig.zon @@ -3,8 +3,9 @@ // SPDX-License-Identifier: Zlib .{ - .name = "wayland_scanner", + .name = .wayland_scanner, .version = "0.0.0", + .fingerprint = 0x501ba345c1864a85, .paths = .{""}, .dependencies = .{ .wayland = .{ From e07973c3d9f00f30cdcdc842a8fde2ff9942459b Mon Sep 17 00:00:00 2001 From: Mark Delk Date: Sun, 1 Jun 2025 21:33:10 -0500 Subject: [PATCH 3/8] fix expat build issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` install └─ install wayland-scanner └─ zig build-exe wayland-scanner Debug native └─ zig build-lib expat Debug native └─ configure cmake header dependency to expat_config.h failure error: /home/user/.cache/zig/p/1220ac6fead249f922d08168f43295090ba7d6e7567e0314dc06cf2fb9ce11ed2bea/expat/expat_config.h.cmake:7: unable to substitute variable: error: MissingValue error: /home/user/.cache/zig/p/1220ac6fead249f922d08168f43295090ba7d6e7567e0314dc06cf2fb9ce11ed2bea/expat/expat_config.h.cmake:120: unable to substitute variable: error: MissingValue error: /home/user/.cache/zig/p/1220ac6fead249f922d08168f43295090ba7d6e7567e0314dc06cf2fb9ce11ed2bea/expat/expat_config.h.cmake:123: unable to substitute variable: error: MissingValue error: HeaderConfigFailed ``` --- build/wayland_scanner/build.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build/wayland_scanner/build.zig b/build/wayland_scanner/build.zig index e491f4e..17ee201 100644 --- a/build/wayland_scanner/build.zig +++ b/build/wayland_scanner/build.zig @@ -34,6 +34,13 @@ pub fn build(b: *std.Build) !void { .style = .{ .cmake = expat_dep.path("expat/expat_config.h.cmake") }, .include_path = "expat_config.h", }, .{ + .BYTEORDER = @as(i64, switch (b.graph.host.result.cpu.arch.endian()) { + .little => 1234, + .big => 4321, + }), + .off_t = null, + .size_t = "unsigned", + .HAVE_STDLIB_H = 1, .HAVE_STRINGS_H = 1, .HAVE_STRING_H = 1, From 8af8d392562e7af2a12b9b86fabe0ef4cef43553 Mon Sep 17 00:00:00 2001 From: Mark Delk Date: Sun, 1 Jun 2025 22:06:11 -0500 Subject: [PATCH 4/8] fix linux build for zig 0.14 --- build.zig | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/build.zig b/build.zig index d5ef338..f82e6ef 100644 --- a/build.zig +++ b/build.zig @@ -360,7 +360,32 @@ pub fn build(b: *std.Build) !void { .SDL_PROCESS_POSIX = 1, .SDL_PROCESS_DUMMY = 1, + + .SDL_DEFAULT_ASSERT_LEVEL = null, + .SDL_AUDIO_DRIVER_ALSA_DYNAMIC = "", + .SDL_AUDIO_DRIVER_JACK_DYNAMIC = "", + .SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC = "", + .SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC = "", + .SDL_AUDIO_DRIVER_SNDIO_DYNAMIC = "", + .SDL_LIBUSB_DYNAMIC = "", + .SDL_UDEV_DYNAMIC = "", + .SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC = "", + .SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM = "", + .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC = "", + .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR = "", + .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL = "", + .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR = "", + .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR = "", + .SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS = "", + .SDL_CAMERA_DRIVER_PIPEWIRE_DYNAMIC = "", }; + lib.installConfigHeader(b.addConfigHeader(.{ .style = .{ .cmake = sdl_dep.path( "include/build_config/SDL_build_config.h.cmake", From d210400ef1a619014483991216f431a22066154e Mon Sep 17 00:00:00 2001 From: Mark Delk Date: Mon, 2 Jun 2025 22:24:37 -0500 Subject: [PATCH 5/8] re-fetch dependencies to fix legacy hash zig issue --- build.zig.zon | 4 ++-- build/fonts/build.zig.zon | 4 ++-- build/freetype/build.zig.zon | 2 +- build/wayland_scanner/build.zig.zon | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index 20693ab..a772784 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -10,11 +10,11 @@ .dependencies = .{ .sdl = .{ .url = "git+https://github.com/libsdl-org/SDL?ref=preview-3.1.8#22422f7748d5128135995ed34c8f8012861c7332", - .hash = "122099222def404a93508de2e17e8347f4ae5c043e82f2edef0fa370586af1915c6d", + .hash = "N-V-__8AAJlxgwOZIi3vQEqTUI3i4X6DR_SuXAQ-gvLt7w-j", }, .sdl_ttf = .{ .url = "git+https://github.com/libsdl-org/SDL_ttf?ref=main#767a91cc47d964e9512feae7feae0a6f3dc762f6", - .hash = "1220d88904c7398472e77670ff3a736d0050b6c501dc315f88708e05f8232060000f", + .hash = "N-V-__8AAPCAGQDYiQTHOYRy53Zw_zpzbQBQtsUB3DFfiHCO", }, .freetype = .{ .path = "build/freetype", diff --git a/build/fonts/build.zig.zon b/build/fonts/build.zig.zon index 9239bd0..9b962cf 100644 --- a/build/fonts/build.zig.zon +++ b/build/fonts/build.zig.zon @@ -9,8 +9,8 @@ .paths = .{""}, .dependencies = .{ .intel_one_mono = .{ - .url = "git+https://github.com/intel/intel-one-mono#V1.3.0", - .hash = "1220f1af56308368aac7a289e4d7ab23fc7688368aa3decc0d1a28e3f9f477dcb3b4", + .url = "git+https://github.com/intel/intel-one-mono?ref=V1.3.0#08d42d257a3211cf2427b35bc2eeab4622d042c8", + .hash = "N-V-__8AACfYKwHxr1Ywg2iqx6KJ5NerI_x2iDaKo97MDRoo", }, }, } diff --git a/build/freetype/build.zig.zon b/build/freetype/build.zig.zon index 6b8bef9..07c3b14 100644 --- a/build/freetype/build.zig.zon +++ b/build/freetype/build.zig.zon @@ -11,7 +11,7 @@ // NOTE: matches SDL_ttf's external/freetype submodule .freetype = .{ .url = "git+https://github.com/libsdl-org/freetype?ref=VER-2-13-2#920c5502cc3ddda88f6c7d85ee834ac611bb11cc", - .hash = "1220b81f6ecfb3fd222f76cf9106fecfa6554ab07ec7fdc4124b9bb063ae2adf969d", + .hash = "N-V-__8AAKLKpwC4H27Ps_0iL3bPkQb-z6ZVSrB-x_3EEkub", }, }, } diff --git a/build/wayland_scanner/build.zig.zon b/build/wayland_scanner/build.zig.zon index e9ee660..f100bef 100644 --- a/build/wayland_scanner/build.zig.zon +++ b/build/wayland_scanner/build.zig.zon @@ -9,12 +9,12 @@ .paths = .{""}, .dependencies = .{ .wayland = .{ - .url = "git+https://gitlab.freedesktop.org/wayland/wayland.git#1.22.0", - .hash = "12204035d74e1978e3e4067d81d1a74aff5eaf6a80cc70aade59ee46247489e3a131", + .url = "git+https://gitlab.freedesktop.org/wayland/wayland.git?ref=1.22.0#b2649cb3ee6bd70828a17e50beb16591e6066288", + .hash = "N-V-__8AABF0FwBANddOGXjj5AZ9gdGnSv9er2qAzHCq3lnu", }, .expat = .{ - .url = "git+https://github.com/libexpat/libexpat#R_2_6_1", - .hash = "1220ac6fead249f922d08168f43295090ba7d6e7567e0314dc06cf2fb9ce11ed2bea", + .url = "git+https://github.com/libexpat/libexpat?ref=R_2_6_1#a590b2d5846865412182805b853dd91d18f38c8d", + .hash = "N-V-__8AADuJGgisb-rSSfki0IFo9DKVCQun1udWfgMU3AbP", }, }, } From 6aaf0d53c334b1ed97557efe14e8f8a23d1a51e8 Mon Sep 17 00:00:00 2001 From: Mark Delk Date: Sat, 21 Jun 2025 14:37:20 -0500 Subject: [PATCH 6/8] more zig 0.14 fixes * support dynamic builds * have to edit a header file on linux to get around a cmake zig issue --- build.zig | 126 +++++++++++++++++++-------------------- build/freetype/build.zig | 17 ++++-- src/fix_header.zig | 59 ++++++++++++++++++ 3 files changed, 134 insertions(+), 68 deletions(-) create mode 100644 src/fix_header.zig diff --git a/build.zig b/build.zig index f82e6ef..18db861 100644 --- a/build.zig +++ b/build.zig @@ -8,9 +8,18 @@ pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); + const linkage = b.option( + std.builtin.LinkMode, + "linkage", + "`.static` or `.dynamic` (default is `.dynamic`)", + ) orelse .dynamic; + const sdl_dep = b.dependency("sdl", .{}); const sdl_ttf_dep = b.dependency("sdl_ttf", .{}); - const freetype_dep = b.dependency("freetype", .{}); + const freetype_dep = b.dependency("freetype", .{ + .linkage = linkage, + .optimize = optimize, + }); const wayland_scanner_dep = b.dependency("wayland_scanner", .{ .target = b.graph.host, .optimize = .ReleaseFast, @@ -19,11 +28,14 @@ pub fn build(b: *std.Build) !void { // - const lib = b.addStaticLibrary(.{ + const lib = b.addLibrary(.{ .name = "SDL3", - .target = target, - .optimize = optimize, - .strip = true, + .linkage = linkage, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = target, + .optimize = optimize, + }), }); { lib.addIncludePath(sdl_dep.path("src")); @@ -345,8 +357,6 @@ pub fn build(b: *std.Build) !void { .SDL_CAMERA_DRIVER_DUMMY = 1, .SDL_CAMERA_DRIVER_V4L2 = 1, - // #define DYNAPI_NEEDS_DLOPEN 1 - .SDL_USE_IME = 1, .SDL_LIBDECOR_VERSION_MAJOR = 0, @@ -360,38 +370,34 @@ pub fn build(b: *std.Build) !void { .SDL_PROCESS_POSIX = 1, .SDL_PROCESS_DUMMY = 1, - - .SDL_DEFAULT_ASSERT_LEVEL = null, - .SDL_AUDIO_DRIVER_ALSA_DYNAMIC = "", - .SDL_AUDIO_DRIVER_JACK_DYNAMIC = "", - .SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC = "", - .SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC = "", - .SDL_AUDIO_DRIVER_SNDIO_DYNAMIC = "", - .SDL_LIBUSB_DYNAMIC = "", - .SDL_UDEV_DYNAMIC = "", - .SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC = "", - .SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM = "", - .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC = "", - .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR = "", - .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL = "", - .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR = "", - .SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON = "", - .SDL_VIDEO_DRIVER_X11_DYNAMIC = "", - .SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR = "", - .SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT = "", - .SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES = "", - .SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 = "", - .SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR = "", - .SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS = "", - .SDL_CAMERA_DRIVER_PIPEWIRE_DYNAMIC = "", }; - lib.installConfigHeader(b.addConfigHeader(.{ - .style = .{ .cmake = sdl_dep.path( - "include/build_config/SDL_build_config.h.cmake", - ) }, + const fix_header_exe = b.addExecutable(.{ + .name = "fix-header", + .root_module = b.createModule(.{ + .root_source_file = b.path("src/fix_header.zig"), + .target = b.graph.host, + .optimize = optimize, + }), + }); + const fix_header = b.addRunArtifact(fix_header_exe); + { + fix_header.addFileArg(sdl_dep.path("include/build_config/SDL_build_config.h.cmake")); + } + const fixed_header = fix_header.captureStdOut(); + + const installFixedHeader = b.addInstallFile(fixed_header, "fixed_header.h"); + + const config_header = b.addConfigHeader(.{ + .style = .{ .cmake = fixed_header }, .include_path = "SDL_build_config.h", - }, values)); + }, values); + + // NOTE: needed to allow `b.addConfigHeader` to use a generated + // file with `.cmake`. (zig build system issue?) + config_header.step.dependOn(&installFixedHeader.step); + + lib.installConfigHeader(config_header); lib.addCSourceFiles(.{ .root = sdl_dep.path(""), @@ -404,15 +410,19 @@ pub fn build(b: *std.Build) !void { lib.root_module.addCMacro(f.name, value); } + if (linkage == .dynamic) { + lib.setVersionScript(sdl_dep.path("src/dynapi/SDL_dynapi.sym")); + } + // SDL3_DYNAMIC_API=/my/actual/libSDL3.so.0 // // If we want to _avoid_ dyn api, we can do so: - // lib.defineCMacro("SDL_dynapi_h_", "1"); - // lib.defineCMacro("SDL_DYNAMIC_API", "0"); + // lib.root_module.addCMacro("SDL_dynapi_h_", "1"); + // lib.root_module.addCMacro("SDL_DYNAMIC_API", "0"); // Avoid // SDL/include/build_config/SDL_build_config_minimal.h - lib.root_module.addCMacro("SDL_build_config_minimal_h_", "1"); + // lib.root_module.addCMacro("SDL_build_config_minimal_h_", "1"); //-- @@ -510,25 +520,14 @@ pub fn build(b: *std.Build) !void { b.installArtifact(lib); } - // needed to allow SDL_ttf to #include "SDL.h" - const sdl_for_libs = b.addStaticLibrary(.{ - .name = "SDL3-for-libs", - .target = target, - .optimize = optimize, - .root_source_file = b.addWriteFiles().add("stub.c", ""), - .strip = true, - }); - { - sdl_for_libs.addIncludePath(sdl_dep.path("include")); - sdl_for_libs.installHeadersDirectory(sdl_dep.path("include"), "", .{}); - b.installArtifact(sdl_for_libs); - } - - const SDL_ttf = b.addStaticLibrary(.{ + const SDL_ttf = b.addLibrary(.{ .name = "SDL3_ttf", - .target = target, - .optimize = optimize, - .strip = true, + .linkage = linkage, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = target, + .optimize = optimize, + }), }); { SDL_ttf.addCSourceFiles(.{ @@ -546,6 +545,7 @@ pub fn build(b: *std.Build) !void { SDL_ttf.installHeadersDirectory(sdl_ttf_dep.path("include/SDL3_ttf"), "SDL3_ttf", .{}); SDL_ttf.linkLibrary(freetype_dep.artifact("freetype")); + SDL_ttf.linkLibrary(lib); if (target.result.os.tag == .macos) { const sdk = std.zig.system.darwin.getSdk(b.allocator, b.graph.host.result) orelse @@ -555,7 +555,7 @@ pub fn build(b: *std.Build) !void { SDL_ttf.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/lib" }) }); } - SDL_ttf.linkLibrary(sdl_for_libs); + SDL_ttf.addIncludePath(sdl_dep.path("include")); b.installArtifact(SDL_ttf); } @@ -570,7 +570,6 @@ pub fn build(b: *std.Build) !void { \\}); \\pub const fonts = @import("fonts"); ), - .link_libc = true, }); { module.linkLibrary(lib); @@ -602,7 +601,6 @@ pub fn build(b: *std.Build) !void { .target = target, .root_source_file = b.path(b.fmt("src/{s}.zig", .{name})), .optimize = optimize, - .strip = true, }); exe.root_module.addImport("sdl", module); @@ -1050,14 +1048,14 @@ const generic_src_files = [_][]const u8{ "src/gpu/vulkan/SDL_gpu_vulkan.c", "src/haptic/SDL_haptic.c", - "src/haptic/dummy/SDL_syshaptic.c", + // "src/haptic/dummy/SDL_syshaptic.c", "src/hidapi/SDL_hidapi.c", "src/joystick/SDL_gamepad.c", "src/joystick/SDL_joystick.c", "src/joystick/SDL_steam_virtual_gamepad.c", - // "src/joystick/dummy/SDL_sysjoystick.c", + "src/joystick/dummy/SDL_sysjoystick.c", "src/joystick/controller_type.c", "src/joystick/virtual/SDL_virtualjoystick.c", @@ -1103,7 +1101,7 @@ const generic_src_files = [_][]const u8{ "src/power/SDL_power.c", "src/process/SDL_process.c", - "src/process/dummy/SDL_dummyprocess.c", + // "src/process/dummy/SDL_dummyprocess.c", "src/render/SDL_d3dmath.c", "src/render/SDL_render.c", @@ -1179,7 +1177,7 @@ const generic_src_files = [_][]const u8{ "src/timer/SDL_timer.c", "src/tray/SDL_tray_utils.c", - "src/tray/dummy/SDL_tray.c", + // "src/tray/dummy/SDL_tray.c", "src/video/SDL_RLEaccel.c", "src/video/SDL_blit.c", diff --git a/build/freetype/build.zig b/build/freetype/build.zig index 6026a2d..da9db6a 100644 --- a/build/freetype/build.zig +++ b/build/freetype/build.zig @@ -8,15 +8,24 @@ pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); + const linkage = b.option( + std.builtin.LinkMode, + "linkage", + "`.static` or `.dynamic` (default is `.dynamic`)", + ) orelse .dynamic; + const freetype_dep = b.dependency("freetype", .{}); // - const lib = b.addStaticLibrary(.{ + const lib = b.addLibrary(.{ .name = "freetype", - .target = target, - .optimize = optimize, - .strip = true, + .linkage = linkage, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = target, + .optimize = optimize, + }), }); { if (optimize != .Debug) { diff --git a/src/fix_header.zig b/src/fix_header.zig new file mode 100644 index 0000000..70ab2e7 --- /dev/null +++ b/src/fix_header.zig @@ -0,0 +1,59 @@ +// SPDX-FileCopyrightText: © Zlib Mark Delk +// +// SPDX-License-Identifier: Zlib + +// Needed to fix the following issue, until https://github.com/ziglang/zig/issues/21265 is addressed. +// +// Remove lines containing `@` +// +// ``` +// #cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC @SDL_VIDEO_DRIVER_X11_DYNAMIC@ +// ``` +// +const std = @import("std"); + +pub const std_options: std.Options = .{ + .log_level = .debug, +}; + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer if (gpa.deinit() == .leak) @panic("found memory leaks"); + const allocator = gpa.allocator(); + + const args = try std.process.argsAlloc(allocator); + defer std.process.argsFree(allocator, args); + + if (args.len != 2) { + std.log.err( + \\Wrong number of arguments. + \\ Usage: {s} {{header}} > {{output.h}} + \\ + , .{args[0]}); + std.process.exit(1); + } + const input_file = try std.fs.cwd().openFile(args[1], .{}); + errdefer input_file.close(); + + const reader = input_file.reader(); + const writer = std.io.getStdOut().writer(); + + var line_buf = std.ArrayList(u8).init(allocator); + defer line_buf.deinit(); + + while (reader.streamUntilDelimiter(line_buf.writer(), '\n', null)) { + if (line_buf.getLastOrNull() == '\r') _ = line_buf.pop(); + defer line_buf.clearRetainingCapacity(); + + const line = line_buf.items; + + if (std.mem.count(u8, line, "@") == 0) { + _ = try writer.write(line); + } + + _ = try writer.write("\n"); + } else |err| switch (err) { + error.EndOfStream => {}, + else => |e| return e, + } +} From 3a02cb4b85b3e22f72fa16cd0b9ba3c00a9bf737 Mon Sep 17 00:00:00 2001 From: Mark Delk Date: Sat, 21 Jun 2025 15:46:33 -0500 Subject: [PATCH 7/8] update readme --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e482bfe..856bb9b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ SPDX-License-Identifier: Zlib # SDL.zig -Build [SDL](https://github.com/libsdl-org/SDL) using [zig](https://ziglang.org) (version 0.13.0). +Build [SDL](https://github.com/libsdl-org/SDL) 3 using [zig](https://ziglang.org) (version 0.14.1). Also includes @@ -16,6 +16,10 @@ Also includes TODO +## Alternatives / anti-endorsement + +You'll probably want to use https://github.com/castholm/SDL instead, it's more complete and better maintained. + ## Tests Build all of SDL's test programs: @@ -28,7 +32,7 @@ Build and run a specific SDL test: ``` zig build sdl-test-testaudiohotplug -zig build sdl-test-testcamera -- --camera 'Razer Kiyo' +zig build sdl-test-testcamera ``` ## Examples From 05286130584fd56b3707e8144878ee54e7ed950f Mon Sep 17 00:00:00 2001 From: Mark Delk Date: Sat, 21 Jun 2025 15:49:14 -0500 Subject: [PATCH 8/8] better ci --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++++++++ .github/workflows/reuse.yaml | 15 -------------- 2 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/reuse.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..feb8e3b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: © 2025 Mark Delk +# +# SPDX-License-Identifier: Zlib + +name: ci + +on: [pull_request] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: license check + uses: fsfe/reuse-action@v4 + + - name: setup zig + uses: mlugg/setup-zig@v2 + with: + version: 0.14.1 + + - name: Install SDL dependencies + run: | + sudo apt-get update -y + sudo apt-get install -y build-essential git make pkg-config cmake ninja-build gnome-desktop-testing libasound2-dev libpulse-dev libaudio-dev libjack-dev libsndio-dev libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev libxtst-dev libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libdbus-1-dev libibus-1.0-dev libudev-dev libpipewire-0.3-dev libwayland-dev libdecor-0-dev liburing-dev + + - name: zig build + run: zig build --summary all + + - name: Build SDL test programs + run: zig build --summary all sdl-test + + - name: Build SDL example programs + run: zig build --summary all sdl-examples + + - name: Build Zig examples + run: zig build --summary all zig-examples diff --git a/.github/workflows/reuse.yaml b/.github/workflows/reuse.yaml deleted file mode 100644 index 36718ab..0000000 --- a/.github/workflows/reuse.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-FileCopyrightText: © 2024 Mark Delk -# -# SPDX-License-Identifier: Zlib - -name: REUSE Compliance Check - -on: [push, pull_request] - -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: REUSE Compliance Check - uses: fsfe/reuse-action@v4