Skip to content

Conversation

@flexiondotorg
Copy link
Contributor

Summary

Enable FFmpeg and 20 dependencies to build on macOS arm64 within the Nix development environment, with full x264 assembly optimisation and VideoToolbox hardware encoder support.

Changes

  • Force clang compiler via FFmpeg configure flags and build environment
  • Set AS=clang for x264 on arm64 to ensure C preprocessor expands assembly macros
  • Build rav1e without git_version feature to avoid libgit2/libiconv dependency
  • Configure C++ header search order with -nostdinc++ and explicit libc++ path
  • Filter NIX_CFLAGS_COMPILE to prevent incorrect -isystem injection
  • Use Apple's /usr/bin/libtool instead of GNU libtool for library combining
  • Add VideoToolbox hardware encoder support (H.264, HEVC, ProRes)
  • Export LIBCXX_INCLUDE from flake.nix for C++ dependency builds

Root Cause

Nix dev shell provides both GCC and Clang, but CGO_CFLAGS points to Clang's builtin headers containing preprocessor features (__has_feature, __building_module) that GCC doesn't recognise. Additionally, x264's aarch64 assembly uses macros requiring C preprocessor expansion, which the bare as command skips.

Testing

  • All 17 platform-applicable libraries build successfully
  • Combined static library: lib/darwin_arm64/libffmpeg.a (63MB)
  • VideoToolbox encoders verified present at runtime
  • GitHub CI workflows pass for all architectures
  • x264 builds with full assembly optimisation (no performance penalty)

Known Limitations

  • just generate requires Linux (go-clang bindings incompatible with macOS libclang blocks)
  • Linker warnings about macOS version mismatch (14.0 vs 13.0) are cosmetic

Resolve three blocking issues for building FFmpeg and 20 dependencies on
macOS arm64 within Nix development environment:
- Force clang compiler via FFmpeg configure flags and build environment
- Disable x264 assembly on Apple Silicon (GNU macro incompatibility with
LLVM)
- Build rav1e without git_version feature to avoid libgit2/libiconv
dependency
- Configure C++ header search order with -nostdinc++ and explicit libc++
path
- Filter NIX_CFLAGS_COMPILE to prevent incorrect -isystem injection
- Use Apple's /usr/bin/libtool instead of GNU libtool for library
combining
- Add VideoToolbox hardware encoder support (H.264, HEVC, ProRes)
- Export LIBCXX_INCLUDE from flake.nix for C++ dependency builds
Root cause: Nix dev shell provides both GCC and Clang, but CGO_CFLAGS
points to Clang's builtin headers containing preprocessor features
(__has_feature, __building_module) that GCC doesn't recognise.
Verified: All 17 platform-applicable libraries build successfully,
combine into lib/darwin_arm64/libffmpeg.a (63MB), tests pass,
VideoToolbox encoders confirmed present.

Signed-off-by: Martin Wimpress <martin@wimpress.org>
x264's aarch64 .S files contain macros (T(), const, endconst) requiring
C preprocessor expansion. The bare 'as' command skips preprocessing,
causing build failures. Setting AS=clang ensures preprocessing runs
before assembly, matching Apple's Xcode toolchain behaviour.
Removes the --disable-asm workaround that caused 10-20% performance
loss.

Signed-off-by: Martin Wimpress <martin@wimpress.org>
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 6 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="internal/builder/library.go">

<violation number="1" location="internal/builder/library.go:300">
P2: LIBRARY_PATH handling is inconsistent with other environment variables. This unconditionally appends without checking for an existing value, potentially creating duplicate environment variables and losing existing paths that cargo/rustc might depend on.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Follow same pattern as LDFLAGS/CFLAGS handling - check for existing
value and prepend rather than overwrite, preventing loss of paths
that cargo/rustc might depend on.
@flexiondotorg flexiondotorg merged commit 4b9e396 into main Jan 14, 2026
5 checks passed
@flexiondotorg flexiondotorg deleted the macos-build branch January 14, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants