diff --git a/cmake/targets/BuildBun.cmake b/cmake/targets/BuildBun.cmake index b2b422f234..9e4db2343b 100644 --- a/cmake/targets/BuildBun.cmake +++ b/cmake/targets/BuildBun.cmake @@ -820,8 +820,32 @@ elseif(APPLE) -fno-keep-static-consts ) else() + # Try to use lld-16 if available, otherwise fallback to lld + # Cache it so we don't have to re-run CMake to pick it up + if(NOT DEFINED LLD_NAME) + find_program(LLD_EXECUTABLE_NAME lld-${LLVM_VERSION_MAJOR}) + + if(NOT LLD_EXECUTABLE_NAME) + if(CI) + # Ensure we don't use a differing version of lld in CI vs clang + message(FATAL_ERROR "lld-${LLVM_VERSION_MAJOR} not found. Please make sure you have LLVM ${LLVM_VERSION_MAJOR}.x installed and set to lld-${LLVM_VERSION_MAJOR}") + endif() + + # To make it easier for contributors, allow differing versions of lld vs clang/cmake + find_program(LLD_EXECUTABLE_NAME lld) + endif() + + if(NOT LLD_EXECUTABLE_NAME) + message(FATAL_ERROR "LLD not found. Please make sure you have LLVM ${LLVM_VERSION_MAJOR}.x installed and lld is available in your PATH as lld-${LLVM_VERSION_MAJOR}") + endif() + + # normalize to basename so it can be used with -fuse-ld + get_filename_component(LLD_NAME ${LLD_EXECUTABLE_NAME} NAME CACHE) + message(STATUS "Using linker: ${LLD_NAME} (${LLD_EXECUTABLE_NAME})") + endif() + target_link_options(${bun} PUBLIC - -fuse-ld=lld-${LLVM_VERSION_MAJOR} + -fuse-ld=${LLD_NAME} -fno-pic -static-libstdc++ -static-libgcc