Jesus Martinez
Jesus Martinez

Reputation: 1

Attempting build LLVM for iOS-simulator platform instead of macOS

I’m currently testing an interesting ARM64-to-x86_64 emulator implemented within the Xcode iOS Simulator. The goal is to enable Intel Macs to run ARM64 iOS binaries.

Part of the emulator’s code relies on LLVM for compilation. However, since this project uses the iOS Simulator platform, I keep encountering a platform mismatch error during the compilation of the required emulator binaries. The error typically states something like:
'Building for iOS Simulator, but exampleLLVMlib.dylib/exampleLLVMcode.cpp is built for macOS.'

All CMakeLists.txt files are correctly configured to target the iOS Simulator platform. However, I am using the version of LLVM installed via Homebrew, which is built for macOS, and this is causing the issue.

I’m seeking support on how to build LLVM specifically for the iOS Simulator platform. I’ve tried bypassing the error by swapping platforms in the Mach-O LC_BUILD_VERSION command, but this led to serious symbol linking problems between the CPU emulator library and the iOS Simulator system libraries. To avoid ABI mismatches, I really need to compile LLVM properly for the iOS Simulator.

Here are the commands I've been trying. Despite tweaking them extensively and setting numerous environment variables, I always encounter compilation errors:

cmake -G "Unix Makefiles" ../llvm \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/ \
    -DCMAKE_OSX_ARCHITECTURES="x86_64" \
    -DLLVM_ENABLE_PROJECTS="clang" \
    -DCMAKE_OSX_DEPLOYMENT_TARGET=18.2 \
    -DLLVM_TARGETS_TO_BUILD="X86;AArch64" \
    -DLLVM_BUILD_RUNTIME=OFF
make -j$(sysctl -n hw.ncpu)

**and also this, tweaking more the commands to address the encountered errors:**

LLVM_SRC="/Users/jesusmartinez/Desktop/build-ios-simulator/llvm-project"
IOS_SIM_SDK="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"

cmake -G "Unix Makefiles" \
    -DBUILD_SHARED_LIBS=ON \
    -DLLVM_TARGET_ARCH=x86_64 \
    -DLLVM_TARGETS_TO_BUILD=X86 \
    -DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-apple-darwin17.5.0" \
    -DLLVM_ENABLE_THREADS=OFF \
    -DLLVM_TABLEGEN="${LLVM_SRC}/usr/local/opt/llvm/bin/llvm-tblgen" \
    -DCLANG_TABLEGEN="${LLVM_SRC}/usr/local/opt/llvm/bin/clang-tblgen" \
    -DCMAKE_OSX_SYSROOT="${IOS_SIM_SDK}" \
    -DCMAKE_C_COMPILER="${LLVM_SRC}/usr/local/opt/llvm/bin/clang" \
    -DCMAKE_LIBRARY_PATH="${LLVM_SRC}/usr/local/opt/llvm/lib/" \
    -DCMAKE_INCLUDE_PATH="${LLVM_SRC}/usr/local/opt/llvm/include/" \
    -DCMAKE_C_FLAGS="-arch x86_64 -target x86_64-apple-darwin17.5.0 --I${LLVM_SRC}/usr/local/opt/llvm/include/ -mios-simulator-version-min=11" \
    -DCMAKE_CXX_FLAGS="-arch x86_64 -target x86_64-apple-darwin17.5.0 -I${LLVM_SRC}usr/local/opt/llvm/include/c++/v1/ -mios-simulator-version-min=11" \
    ../llvm

Thank you in advice.

Upvotes: 0

Views: 27

Answers (0)

Related Questions