Description
Both darwin-arm64 and darwin-amd64 preset builds fail during the CMake build process when GoogleTest attempts to run test discovery on Darwin/macOS executables from a Linux build host. The cross-compiled binaries cannot be executed on Linux, causing the build to fail.
Steps to Reproduce
- Configure the darwin-arm64 preset:
cd barretenberg/cpp
cmake --preset darwin-arm64
- Build the project:
cmake --build build-darwin-arm64 -j$(nproc)
Similarly for darwin-amd64:
- Configure the darwin-amd64 preset:
cd barretenberg/cpp
cmake --preset darwin-amd64
- Build the project:
cmake --build build-darwin-amd64 -j$(nproc)
Error Messages
darwin-arm64:
/mnt/user-data/jonathan/aztec-packages-2/barretenberg/cpp/build-darwin-arm64/bin/crypto_blake3s_full_tests: 4: Syntax error: ")" unexpected
CMake Error at /usr/share/cmake-3.28/Modules/GoogleTestAddTests.cmake:112 (message):
Error running test executable.
darwin-amd64:
/mnt/user-data/jonathan/aztec-packages-2/barretenberg/cpp/build-darwin-amd64/bin/crypto_blake2s_tests: 1: ����h��!H__PAGEZEROx__TEXT__text__TEXT�,���,�__stubs__TEXT�: not found
/mnt/user-data/jonathan/aztec-packages-2/barretenberg/cpp/build-darwin-amd64/bin/crypto_blake2s_tests: 7: Syntax error: ")" unexpected
CMake Error at /usr/share/cmake-3.28/Modules/GoogleTestAddTests.cmake:112 (message):
Error running test executable.
Root Cause
The build system is using GoogleTest's automatic test discovery feature (gtest_discover_tests) which attempts to execute the compiled test binaries to discover test cases. When cross-compiling for Darwin/macOS on a Linux host, these Mach-O executables cannot be run on Linux, resulting in syntax errors when the shell tries to interpret them as scripts.
The error messages show:
- Binary format signatures being interpreted as shell commands (e.g.,
__PAGEZERO, __TEXT)
- Shell syntax errors when encountering binary data
Suggested Fix
Several possible solutions:
- Disable test discovery for cross-compilation: Use
gtest_add_tests instead of gtest_discover_tests when cross-compiling
- Conditional test discovery: Only enable automatic test discovery when not cross-compiling:
if(CMAKE_CROSSCOMPILING)
gtest_add_tests(TARGET ${test_target})
else()
gtest_discover_tests(${test_target})
endif()
- Use BUILD_TESTING flag: Allow users to disable test building entirely during cross-compilation:
option(BUILD_TESTING "Build tests" ON)
if(BUILD_TESTING AND NOT CMAKE_CROSSCOMPILING)
# Add test targets
endif()
- Defer test discovery: Use
DISCOVERY_MODE PRE_TEST to delay discovery until test execution time (when presumably on the target platform)
Environment
- Build presets: darwin-arm64, darwin-amd64
- Host system: Linux
- Target system: Darwin/macOS
- Toolchain: OSXCross with Apple SDK
- CMake version: 3.28
- Affected component: GoogleTest test discovery
Impact
This prevents cross-compilation of the project for macOS/Darwin targets from Linux hosts, which is critical for:
- CI/CD pipelines that build for multiple platforms
- Linux-based build servers producing macOS binaries
- Developer workflows on Linux targeting macOS
Workaround
As a temporary workaround, users can:
- Build without tests by modifying CMakeLists.txt to skip test targets
- Build on native macOS hardware instead of cross-compiling
- Use a macOS VM or container for building
Description
Both
darwin-arm64anddarwin-amd64preset builds fail during the CMake build process when GoogleTest attempts to run test discovery on Darwin/macOS executables from a Linux build host. The cross-compiled binaries cannot be executed on Linux, causing the build to fail.Steps to Reproduce
cd barretenberg/cpp cmake --preset darwin-arm64cmake --build build-darwin-arm64 -j$(nproc)Similarly for darwin-amd64:
cd barretenberg/cpp cmake --preset darwin-amd64cmake --build build-darwin-amd64 -j$(nproc)Error Messages
darwin-arm64:
darwin-amd64:
Root Cause
The build system is using GoogleTest's automatic test discovery feature (
gtest_discover_tests) which attempts to execute the compiled test binaries to discover test cases. When cross-compiling for Darwin/macOS on a Linux host, these Mach-O executables cannot be run on Linux, resulting in syntax errors when the shell tries to interpret them as scripts.The error messages show:
__PAGEZERO,__TEXT)Suggested Fix
Several possible solutions:
gtest_add_testsinstead ofgtest_discover_testswhen cross-compilingDISCOVERY_MODE PRE_TESTto delay discovery until test execution time (when presumably on the target platform)Environment
Impact
This prevents cross-compilation of the project for macOS/Darwin targets from Linux hosts, which is critical for:
Workaround
As a temporary workaround, users can: