Skip to content

Commit c12cb0f

Browse files
committed
fix(nix): add macOS support to development shell
- Configure CGO_CFLAGS with SDK root and clang builtin headers - Set MACOSX_DEPLOYMENT_TARGET to 13.0 for binary compatibility - Add DYLD_LIBRARY_PATH for macOS dynamic library resolution - Pin to llvmPackages_18 for consistency across platforms Fixes CGO compilation errors on macOS where stdarg.h and other compiler builtin headers were not found during build. Signed-off-by: Martin Wimpress <martin@wimpress.org>
1 parent 10d3c78 commit c12cb0f

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

flake.nix

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,22 @@
6262

6363
# Environment for go-clang CGO compilation and hardware acceleration
6464
shellHook = ''
65-
export CGO_LDFLAGS="-L${pkgs.llvmPackages.libclang.lib}/lib"
66-
export CPATH="${pkgs.llvmPackages.libclang.dev}/include"
65+
export CGO_LDFLAGS="-L${pkgs.llvmPackages_18.libclang.lib}/lib"
66+
export CPATH="${pkgs.llvmPackages_18.libclang.dev}/include"
6767
# Ensure vpx build finds yasm
6868
export PATH="${pkgs.yasm}/bin:${pkgs.nasm}/bin:$PATH"
6969
''
70+
+ pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
71+
# macOS: Export SDK paths for C/C++ compilation
72+
# The SDKROOT is set by Nix's stdenv wrapper, use it or fall back to xcrun
73+
# CGO needs both the SDK path and clang's builtin headers (stdarg.h, stddef.h, etc.)
74+
export CGO_CFLAGS="-isysroot ''${SDKROOT:-$(xcrun --show-sdk-path)} -I${pkgs.llvmPackages_18.libclang.lib}/lib/clang/18/include"
75+
export CPATH="${pkgs.llvmPackages_18.libclang.dev}/include:$CPATH"
76+
# Set deployment target to match ffmpeg-statigo build (macOS 13.0+)
77+
export MACOSX_DEPLOYMENT_TARGET="13.0"
78+
# macOS uses DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH
79+
export DYLD_LIBRARY_PATH="${pkgs.llvmPackages_18.libclang.lib}/lib:''${DYLD_LIBRARY_PATH:-}"
80+
''
7081
+ pkgs.lib.optionalString pkgs.stdenv.isLinux ''
7182
# Hardware acceleration: Make GPU drivers visible
7283
# NixOS mounts GPU drivers under /run/opengl-driver/lib

0 commit comments

Comments
 (0)