From a75a0418be2945653b92302847c55b6376f1866a Mon Sep 17 00:00:00 2001 From: Greg Benz Date: Fri, 10 Jul 2026 13:09:10 -0500 Subject: [PATCH] Fix macOS x86_64 cross-builds with bundled dependencies --- .github/workflows/cmake_mac.yml | 57 ++++++++++++++++++++++++++++++++- CMakeLists.txt | 11 +++++++ docs/building.md | 20 ++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake_mac.yml b/.github/workflows/cmake_mac.yml index ced89f5e..9dccd1e9 100644 --- a/.github/workflows/cmake_mac.yml +++ b/.github/workflows/cmake_mac.yml @@ -18,6 +18,8 @@ jobs: cc: clang cxx: clang++ cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DUHDR_ENABLE_WERROR=1' + run_tests: true + expected_arch: arm64 # - name: "macOS latest ARM64 clang rel ninja with deps" @@ -26,6 +28,8 @@ jobs: cc: clang cxx: clang++ cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_BUILD_DEPS=1 -DUHDR_ENABLE_WERROR=1' + run_tests: true + expected_arch: arm64 # - name: "macOS latest ARM64 clang rel ninja static" @@ -34,6 +38,29 @@ jobs: cc: clang cxx: clang++ cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DBUILD_SHARED_LIBS=0 -DUHDR_ENABLE_WERROR=1' + run_tests: true + expected_arch: arm64 + + # + - name: "macOS-15 Intel clang rel ninja" + os: macos-15-intel + build_type: Release + cc: clang + cxx: clang++ + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_ENABLE_INSTALL=1 -DUHDR_ENABLE_WERROR=1' + run_tests: true + run_cli_smoke: true + expected_arch: x86_64 + + # + - name: "macOS latest ARM64 cross x86_64 clang rel ninja with deps" + os: macos-latest + build_type: Release + cc: clang + cxx: clang++ + cmake-opts: '-DUHDR_BUILD_TESTS=1 -DUHDR_ENABLE_LOGS=1 -DUHDR_BUILD_DEPS=1 -DUHDR_ENABLE_WERROR=1 -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0' + run_tests: false + expected_arch: x86_64 steps: - name: Checkout the repository @@ -65,6 +92,34 @@ jobs: - name: Build run: cmake --build build --config ${{ matrix.config.build_type }} + - name: Verify artifact architecture + env: + EXPECTED_ARCH: ${{ matrix.config.expected_arch }} + shell: bash + run: | + artifacts=( + build/libuhdr.a + build/ultrahdr_app + build/ultrahdr_unit_test + ) + if [[ -e build/libuhdr.dylib ]]; then + artifacts+=(build/libuhdr.dylib) + fi + if [[ -e build/turbojpeg/src/turbojpeg-build/libjpeg.a ]]; then + artifacts+=(build/turbojpeg/src/turbojpeg-build/libjpeg.a) + fi + for artifact in "${artifacts[@]}"; do + test "$(lipo -archs "$artifact")" = "$EXPECTED_ARCH" + done + - name: Test + if: matrix.config.run_tests working-directory: build - run: ctest --build-config ${{ matrix.config.build_type }} \ No newline at end of file + run: ctest --build-config ${{ matrix.config.build_type }} + + - name: Test CLI + if: matrix.config.run_cli_smoke + run: | + build/ultrahdr_app -m 0 -p tests/data/raw_p010_image.p010 -w 1280 -h 720 -a 0 -z build/cli-smoke.jpeg + build/ultrahdr_app -m 1 -j build/cli-smoke.jpeg -P + build/ultrahdr_app -m 1 -j build/cli-smoke.jpeg -o 1 -O 5 -z build/cli-smoke.raw diff --git a/CMakeLists.txt b/CMakeLists.txt index cb4ca18f..f0481c88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -431,6 +431,17 @@ endif() if(DEFINED UHDR_ANDROID_NDK_PATH) list(APPEND UHDR_CMAKE_ARGS -DUHDR_ANDROID_NDK_PATH=${UHDR_ANDROID_NDK_PATH}) endif() +if(APPLE) + if(DEFINED CMAKE_OSX_ARCHITECTURES AND NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") + list(APPEND UHDR_CMAKE_ARGS "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}") + endif() + if(DEFINED CMAKE_OSX_DEPLOYMENT_TARGET AND NOT "${CMAKE_OSX_DEPLOYMENT_TARGET}" STREQUAL "") + list(APPEND UHDR_CMAKE_ARGS "-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}") + endif() + if(DEFINED CMAKE_OSX_SYSROOT AND NOT "${CMAKE_OSX_SYSROOT}" STREQUAL "") + list(APPEND UHDR_CMAKE_ARGS "-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}") + endif() +endif() # opengl es libraries if(UHDR_ENABLE_GLES) diff --git a/docs/building.md b/docs/building.md index 755502fb..1aa81f90 100644 --- a/docs/building.md +++ b/docs/building.md @@ -140,6 +140,26 @@ ninja ctest ``` +#### Cross-compiling for Intel on Apple Silicon + +From the libultrahdr source directory, build a thin x86_64 binary on an Apple +Silicon Mac: + +```sh +cmake -G Ninja -S . -B build-x86_64 \ + -DCMAKE_OSX_ARCHITECTURES=x86_64 \ + -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \ + -DUHDR_BUILD_DEPS=1 \ + -DUHDR_BUILD_TESTS=1 +cmake --build build-x86_64 +``` + +`UHDR_BUILD_DEPS=1` builds libjpeg-turbo and test dependencies for the +requested architecture. When using installed dependencies instead, they must +contain an x86_64 slice. Only one value in `CMAKE_OSX_ARCHITECTURES` is +supported per build; universal arm64+x86_64 builds are not supported. Running +the x86_64 tests on Apple Silicon requires Rosetta 2. + This will generate the following files under `build_directory`: **libuhdr.{version}.dylib** - Shared library for the libuhdr API