fix(sdl): example builds on Zig 0.16 macOS arm64 - #231
Conversation
…mismatch
Zig 0.16's bundled clang ships an arm_neon.h that uses the FP8 type
`__mfp8` and `__builtin_neon_*` intrinsics gated on target features that
aren't enabled by default on macOS arm64. SDL2's SDL_cpuinfo.h transitively
includes <arm_neon.h> when __ARM_NEON is set, which triggered ~5636
@cImport translation errors:
arm_vector_types.h:20: typedef __mfp8 mfloat8_t;
error: type specifier missing, defaults to 'int'
arm_vector_types.h:93: typedef ... mfloat8_t mfloat8x8_t;
error: unknown type name 'mfloat8x8_t'
arm_neon.h:246: __builtin_neon_vbfdotq_f32
error: use of unknown builtin
SDL exposes SDL_DISABLE_ARM_NEON_H as the documented escape hatch for
exactly this case. We don't call NEON intrinsics from Zig — SDL still
uses NEON internally in its precompiled library — so disabling the
transitive header include is safe.
Applied to both @cImport sites (src/sdl.zig and src/audio.zig).
PR SummaryLow Risk Overview Both SDL Reviewed by Cursor Bugbot for commit 3be0098. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Code Review
This pull request defines SDL_DISABLE_ARM_NEON_H as 1 before importing SDL2 headers in backends/sdl/src/audio.zig and backends/sdl/src/sdl.zig. This change prevents compilation errors on macOS arm64 with Zig 0.16 caused by a transitive inclusion of <arm_neon.h> and a mismatch with the FP8 type. There are no review comments, and I have no additional feedback to provide.
7 PRs since v0.34.1: - #225 fix(raylib): takeScreenshot handles absolute paths (closes #224) - #230 fix(raylib): replace rename trick with direct libc write (closes #229 — Linux EXDEV + Windows compile + Ubuntu X11) - #231 fix(sdl): SDL_DISABLE_ARM_NEON_H for Zig 0.16 arm_neon.h mismatch - #226 chore(backends): Zig 0.16 sweep on sdl + raylib + null (closes #221) - #227 chore(bgfx): build cleanly on Zig 0.16.0 + zbgfx pin bump (closes #219) - #228 chore(wgpu): build cleanly on Zig 0.16.0 + snorm-dev pin (closes #220, refs bronter/wgpu_native_zig#46) - #216 fix(codegen): sanitize plugin idents in resolve() emit (closes #212)
Summary
The SDL backend's
example/build was failing with ~5636 errors on macOSarm64 + Zig 0.16. Reproduces on
origin/main; not caused by #226's zonbump. Pre-existing toolchain issue, now fixed.
Root cause
Zig 0.16's bundled clang headers (
lib/include/arm_vector_types.h,arm_neon.h) use the FP8 type__mfp8and__builtin_neon_*intrinsicsthat are gated on target features (
+fp8, etc.) which aren't enabled bydefault for the host's
apple_m*CPU. SDL2'sSDL_cpuinfo.hdoes#if !defined(SDL_DISABLE_ARM_NEON_H) && defined(__ARM_NEON)→#include <arm_neon.h>, transitively pulling Zig's broken-for-this-CPUheader into the
@cImporttranslation unit.First 5 errors from the broken build:
Fix
Define
SDL_DISABLE_ARM_NEON_H(SDL's official escape hatch) at every@cImportsite for SDL2 in the backend:backends/sdl/src/sdl.zigbackends/sdl/src/audio.zig(separate cImport for SDL_mixer)We don't call NEON intrinsics from Zig — SDL still uses NEON internally
in its precompiled library — so disabling the transitive header include
is safe and surgical.
Verification (macOS arm64, Zig 0.16.0)
cd backends/sdl/example && zig build— green (was 5636 errors)cd backends/sdl && zig build— greencd backends/sdl && zig build test— greencd backends/sdl && zig build -Dtarget=x86_64-linux-gnu— greencd backends/sdl && zig build -Dtarget=x86_64-windows-gnu— green(Example cross-compile to Linux still fails, but on a pre-existing
unconditional
linkFramework("Cocoa")inexample/build.zig— unrelatedto this fix.)
Related / upstream
The underlying issue — Zig 0.16 shipping FP8-aware
arm_neon.hwithoutdefaulting
+fp8for apple_m* CPUs — is arguably a Zig stdlib bug worthfiling upstream. Any C library that includes
<arm_neon.h>from a publicheader (not just SDL2) will hit this. Workaround here is SDL-specific;
a generalized fix would live in ziglang/zig.
Test plan