macOS: CMake uses a mix of tools provided by LLVM and Apple while compile with vanilla LLVM
While compiling blender on macOS (m1 pro) with llvm-17 installed via homebrew, it complained that the static library could not be recognised. Here is the warning during compilation which hints about using a wrong format for the static library,
ld: warning: ld: warning: ignoring file lib/libbf_dna.a, building for macOS-arm64 but attempting to link with file built for unknown-unsupported file format ( 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A 0x2F 0x20 0x20 0x20 0x20 0x20 0x20 0x20 )
After a bit of digging, I found out, while CMake used the 'llvm-ranlib' for CMAKE_RANLIB, for CMAKE_AR it was using '/usr/bin/ar' and not 'llvm-ar'. Which after those particular flags, produce an archive which can't be read by LLVM.
On further looking into CMake, I ran into the commit which disable loading of llvm-ar on apple platforms, which cited issues with the Apple linker. But according to this comment, ld64.lld should be a drop in replacement for the Apple linker.
Edited by Kuntal Majumder