From 1333b17bccf2a36331c2ed7901b0d125c2ecd991 Mon Sep 17 00:00:00 2001 From: Jon Mayo Date: Wed, 2 Jul 2025 22:22:20 -0700 Subject: [PATCH 1/3] fix SDL_config.h errors on older glibc glibc 2.37 and earlier does not support wcslcpy, wcslcat, strlcpy, and strlcat. Without implementing a more sophisticated detection, it is simpler to enable SDL's fallback functions for these often missing routines. example of affected systems: Linux Mint 21.3 and earlier Debian 12 (bookworm) and earlier Ubuntu 22.10 (kinetic) and earlier Fedora 37 and earlier Zorin 17.3 and earlier Also, updates README.md with some basic instructions. --- README.md | 29 +++++++++++++++++++++++++++++ build.zig | 8 ++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 49a282363d4cf..b76c8930f94f1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,32 @@ +# SDL for Zig + This is a fork of [SDL](https://www.libsdl.org/), packaged for [Zig](https://ziglang.org). Unnecessary files have been deleted, and the build system has been replaced with `build.zig`. The package provides version 2 of SDL. For version 3, consider https://github.com/castholm/SDL. + +## Getting started + +### Linking SDL2 to your project + +Fetch SDL and add to your `build.zig.zon` : +```bash +zig fetch --save=SDL git+https://github.com/allyourcodebase/SDL +``` + +Add this to your `build.zig` : +```zig +pub fn build(b: *std.Build) void { +// ... + +const sdl_dep = b.dependency("SDL", .{ + .optimize = .ReleaseFast, + .target = target, +}); + +// ... + +exe.linkLibrary(sdl_dep.artifact("SDL2")); + +// ... +} +``` diff --git a/build.zig b/build.zig index 9934ed875a951..d5a4337703525 100644 --- a/build.zig +++ b/build.zig @@ -1082,8 +1082,8 @@ fn configHeader(b: *std.Build, t: std.Target) *std.Build.Step.ConfigHeader { .HAVE_MEMMOVE = 1, .HAVE_MEMCMP = 1, .HAVE_WCSLEN = 1, - .HAVE_WCSLCPY = !is_musl, - .HAVE_WCSLCAT = !is_musl, + .HAVE_WCSLCPY = !is_linux and !is_musl, + .HAVE_WCSLCAT = !is_linux and !is_musl, .HAVE__WCSDUP = 0, .HAVE_WCSDUP = 1, .HAVE_WCSSTR = 1, @@ -1094,8 +1094,8 @@ fn configHeader(b: *std.Build, t: std.Target) *std.Build.Step.ConfigHeader { .HAVE_WCSNCASECMP = 1, .HAVE__WCSNICMP = 0, .HAVE_STRLEN = 1, - .HAVE_STRLCPY = 1, - .HAVE_STRLCAT = 1, + .HAVE_STRLCPY = !is_linux, + .HAVE_STRLCAT = !is_linux, .HAVE__STRREV = 0, .HAVE__STRUPR = 0, .HAVE__STRLWR = 0, From e5d1d44775c1ff6972df82033ba84b136973fc4b Mon Sep 17 00:00:00 2001 From: Jon Mayo Date: Thu, 17 Jul 2025 21:39:33 -0700 Subject: [PATCH 2/3] Update build.zig Co-authored-by: Jay Petacat --- build.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index d5a4337703525..f08c2da69c386 100644 --- a/build.zig +++ b/build.zig @@ -1082,8 +1082,8 @@ fn configHeader(b: *std.Build, t: std.Target) *std.Build.Step.ConfigHeader { .HAVE_MEMMOVE = 1, .HAVE_MEMCMP = 1, .HAVE_WCSLEN = 1, - .HAVE_WCSLCPY = !is_linux and !is_musl, - .HAVE_WCSLCAT = !is_linux and !is_musl, + .HAVE_WCSLCPY = !is_linux, + .HAVE_WCSLCAT = !is_linux, .HAVE__WCSDUP = 0, .HAVE_WCSDUP = 1, .HAVE_WCSSTR = 1, From 22586e98064b6a48f2a6489917b60302ccf3b585 Mon Sep 17 00:00:00 2001 From: Jon Mayo Date: Thu, 17 Jul 2025 21:39:44 -0700 Subject: [PATCH 3/3] Update build.zig Co-authored-by: Jay Petacat --- build.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index f08c2da69c386..692b1dd082db0 100644 --- a/build.zig +++ b/build.zig @@ -1094,8 +1094,8 @@ fn configHeader(b: *std.Build, t: std.Target) *std.Build.Step.ConfigHeader { .HAVE_WCSNCASECMP = 1, .HAVE__WCSNICMP = 0, .HAVE_STRLEN = 1, - .HAVE_STRLCPY = !is_linux, - .HAVE_STRLCAT = !is_linux, + .HAVE_STRLCPY = !is_linux or is_musl, + .HAVE_STRLCAT = !is_linux or is_musl, .HAVE__STRREV = 0, .HAVE__STRUPR = 0, .HAVE__STRLWR = 0,