Bug #113113 Build failure with Homebrew LLVM 14-19 on macOS
Submitted: 16 Nov 2023 20:26 Modified: 17 Oct 18:17
Reporter: Laurynas Biveinis (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:8.0.40 OS:MacOS
Assigned to: CPU Architecture:Any

[16 Nov 2023 20:26] Laurynas Biveinis
Description:
If one tries to build from the source code using Homebrew-packaged LLVM 16, it eventually fails with an error:
$ cmake ... -DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm@16/bin/clang -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm@16/bin/clang++
...
$ make or ninja
...
FAILED: library_output_directory/libmysqlrouter_connection_pool.1.dylib 
: && /opt/homebrew/opt/llvm@16/bin/clang++ -std=c++17 -fno-omit-frame-pointer -ftls-model=initial-exec -ffp-contract=on -Wall -Wextra -Wformat-security -Wvla -Wundef -Wmissing-format-attribute -Woverloaded-virtual -Wcast-qual -Wno-null-conversion -Wno-unused-private-field -Wconditional-uninitialized -Wdeprecated -Wno-deprecated-declarations -Wno-shorten-64-to-32 -Wextra-semi -Wheader-hygiene -Wnon-virtual-dtor -Wundefined-reinterpret-cast -Wrange-loop-analysis -Winconsistent-missing-destructor-override -Winconsistent-missing-override -Wshadow-field -Werror -DSAFE_MUTEX -DENABLED_DEBUG_SYNC -ffp-contract=on -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -dynamiclib -Wl,-headerpad_max_install_names -compatibility_version 1.0.0 -o library_output_directory/libmysqlrouter_connection_pool.1.dylib -install_name @rpath/libmysqlrouter_connection_pool.1.dylib router/src/connection_pool/src/CMakeFiles/connection_pool.dir/connection_pool.cc.o router/src/connection_pool/src/CMakeFiles/connection_pool.dir/connection_pool_component.cc.o  -Wl,-rpath,/Users/laurynas/vilniusdb/mysql-8.0.35/_build-debug-llvm-16/library_output_directory  router/src/harness/include/libharness_net_ts.a  /opt/homebrew/opt/openssl@1.1/lib/libssl.dylib  /opt/homebrew/opt/openssl@1.1/lib/libcrypto.dylib  library_output_directory/libmysqlharness_stdx.1.dylib && :
ld: archive member '/' not a mach-o file in '/Users/laurynas/vilniusdb/mysql-8.0.35/_build-debug-llvm-16/router/src/harness/include/libharness_net_ts.a'

Checking the archive file:

$ ar -t /Users/laurynas/vilniusdb/mysql-8.0.35/_build-debug-llvm-16/router/src/harness/include/libharness_net_ts.a
/
internet.cpp.o/
socket.cpp.o/

How to repeat:
See above

Suggested fix:
Looking at the archive-creating commands I can see:

[9/1192] : && /opt/homebrew/Cellar/cmake/3.27.7/bin/cmake -E rm -f router/src/harness/include/libharness_net_ts.a && /usr/bin/ar qc router/src/harness/include/libharness_net_ts.a  router/src/harness/include/CMakeFiles/harness_net_ts.dir/mysql/harness/net_ts/internet.cpp.o router/src/harness/include/CMakeFiles/harness_net_ts.dir/mysql/harness/net_ts/socket.cpp.o && /opt/homebrew/opt/llvm@16/bin/llvm-ranlib router/src/harness/include/libharness_net_ts.a && /opt/homebrew/Cellar/cmake/3.27.7/bin/cmake -E touch router/src/harness/include/libharness_net_ts.a && :

Observe that ar is /usr/bin/ar (that is, macOS system default one) but ranlib is /opt/homebrew/opt/llvm@16/bin/llvm-ranlib, thus coming from the Homebrew LLVM 16.

And indeed, adding
-DCMAKE_AR=/opt/homebrew/opt/llvm@16/bin/llvm-ar
works around the issue.

It seems that the right ar path finding logic should be added to CMake scripts
[16 Nov 2023 20:34] Laurynas Biveinis
Fixed title typo
[17 Nov 2023 14:10] Laurynas Biveinis
The same issue happens with other Homebrew LLVM versions, I have tested 14 to 17, editing the title.
(LLVM 17 has unrelated build issues in bug 113123)
[21 Nov 2023 4:31] MySQL Verification Team
Hello Laurynas,

Thank you for the report and feedback!

regards,
Umesh
[17 Oct 18:17] Laurynas Biveinis
Same with LLVM 19 (besides the expected compilation errors and warnings) on 8.0.40