Skip to content

Commit 79bed6c

Browse files
authored
Merge pull request swiftlang#31481 from compnerd/not-everything-that-glitters-is-gold
build: default the lld/gold enabling as per reality
2 parents 271289f + c6cc769 commit 79bed6c

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,22 @@ set(CLANG_COMPILER_VERSION "" CACHE STRING
148148
"The internal version of the Clang compiler")
149149

150150
# Indicate whether Swift should attempt to use the lld linker.
151-
set(SWIFT_ENABLE_LLD_LINKER TRUE CACHE BOOL
151+
if(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
152+
set(SWIFT_ENABLE_LLD_LINKER_default TRUE)
153+
else()
154+
set(SWIFT_ENABLE_LLD_LINKER_default FALSE)
155+
endif()
156+
set(SWIFT_ENABLE_LLD_LINKER ${SWIFT_ENABLE_LLD_LINKER_default} CACHE BOOL
152157
"Enable using the lld linker when available")
153158

154159
# Indicate whether Swift should attempt to use the gold linker.
155160
# This is not used on Darwin.
156-
set(SWIFT_ENABLE_GOLD_LINKER TRUE CACHE BOOL
161+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin OR CMAKE_SYSTEM_NAME STREQUAL Windows)
162+
set(SWIFT_ENABLE_GOLD_LINKER_default FALSE)
163+
else()
164+
set(SWIFT_ENABLE_GOLD_LINKER_default TRUE)
165+
endif()
166+
set(SWIFT_ENABLE_GOLD_LINKER ${SWIFT_ENABLE_GOLD_LINKER_default} CACHE BOOL
157167
"Enable using the gold linker when available")
158168

159169
set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One

cmake/modules/AddSwift.cmake

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,12 @@ function(_add_host_variant_link_flags target)
368368
endif()
369369

370370
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
371-
# FIXME: On Apple platforms, find_program needs to look for "ld64.lld"
372-
find_program(LDLLD_PATH "ld.lld")
373-
if((SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH AND NOT APPLE) OR
374-
(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS AND NOT CMAKE_SYSTEM_NAME STREQUAL WINDOWS))
375-
target_link_options(${target} PRIVATE -fuse-ld=lld)
376-
elseif(SWIFT_ENABLE_GOLD_LINKER AND
377-
"${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
378-
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
379-
target_link_options(${target} PRIVATE -fuse-ld=gold.exe)
380-
else()
381-
target_link_options(${target} PRIVATE -fuse-ld=gold)
382-
endif()
371+
if(SWIFT_ENABLE_LLD_LINKER)
372+
target_link_options(${target} PRIVATE
373+
-fuse-ld=lld$<$<STREQUAL:${CMAKE_HOST_SYSTEM_NAME},Windows>:.exe>)
374+
elseif(SWIFT_ENABLE_GOLD_LINKER)
375+
target_link_options(${target} PRIVATE
376+
-fuse-ld=gold$<$<STREQUAL:${CMAKE_HOST_SYSTEM_NAME},Windows>:.exe>)
383377
endif()
384378
endif()
385379

0 commit comments

Comments
 (0)