Skip to content

Commit 3767ece

Browse files
committed
[CMake] Simplify two binary variables into one tri-state variable
Also remove some ancient logic to detect and ignore requests to use LLD. If people want to explicitly use LLD, they probably have a reason and we shouldn't second guess them.
1 parent 5013a02 commit 3767ece

File tree

6 files changed

+27
-49
lines changed

6 files changed

+27
-49
lines changed

CMakeLists.txt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,20 @@ set(SWIFT_COMPILER_VERSION "" CACHE STRING
147147
set(CLANG_COMPILER_VERSION "" CACHE STRING
148148
"The internal version of the Clang compiler")
149149

150-
# Indicate whether Swift should attempt to use the lld linker.
151-
if(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
152-
set(SWIFT_ENABLE_LLD_LINKER_default TRUE)
150+
# Which default linker to use. Prefer LLVM_USE_LINKER if it set, otherwise use
151+
# our own defaults. This should only be possible in a unified (not stand alone)
152+
# build environment.
153+
if(LLVM_USE_LINKER)
154+
set(SWIFT_USE_LINKER_default "${LLVM_USE_LINKER}")
155+
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
156+
set(SWIFT_USE_LINKER_default "lld")
157+
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
158+
set(SWIFT_USE_LINKER_default "")
153159
else()
154-
set(SWIFT_ENABLE_LLD_LINKER_default FALSE)
160+
set(SWIFT_USE_LINKER_default "gold")
155161
endif()
156-
set(SWIFT_ENABLE_LLD_LINKER ${SWIFT_ENABLE_LLD_LINKER_default} CACHE BOOL
157-
"Enable using the lld linker when available")
158-
159-
# Indicate whether Swift should attempt to use the gold linker.
160-
# This is not used on Darwin.
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
167-
"Enable using the gold linker when available")
162+
set(SWIFT_USE_LINKER ${SWIFT_USE_LINKER_default} CACHE STRING
163+
"Build Swift with a non-default linker")
168164

169165
set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One
170166
must specify the form of LTO by setting this to one of: 'full', 'thin'. This

cmake/modules/AddSwift.cmake

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function(_add_host_variant_c_compile_link_flags name)
116116
if(SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID)
117117
# lld can handle targeting the android build. However, if lld is not
118118
# enabled, then fallback to the linker included in the android NDK.
119-
if(NOT SWIFT_ENABLE_LLD_LINKER)
119+
if(NOT SWIFT_USE_LINKER STREQUAL "lld")
120120
swift_android_tools_path(${SWIFT_HOST_VARIANT_ARCH} tools_path)
121121
target_compile_options(${name} PRIVATE -B${tools_path})
122122
endif()
@@ -368,12 +368,9 @@ function(_add_host_variant_link_flags target)
368368
endif()
369369

370370
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
371-
if(SWIFT_ENABLE_LLD_LINKER)
371+
if(SWIFT_USE_LINKER)
372372
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>)
373+
-fuse-ld=${SWIFT_USE_LINKER}$<$<STREQUAL:${CMAKE_HOST_SYSTEM_NAME},Windows>:.exe>)
377374
endif()
378375
endif()
379376

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,9 @@ function(add_swift_unittest test_dirname)
5757
_ENABLE_EXTENDED_ALIGNED_STORAGE)
5858
endif()
5959

60-
find_program(LDLLD_PATH "ld.lld")
61-
# Strangely, macOS finds lld and then can't find it when using -fuse-ld=
62-
if(SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH AND NOT APPLE)
60+
if(SWIFT_USE_LINKER)
6361
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
64-
LINK_FLAGS " -fuse-ld=lld")
65-
elseif(SWIFT_ENABLE_GOLD_LINKER AND
66-
"${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
67-
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
68-
LINK_FLAGS " -fuse-ld=gold")
62+
LINK_FLAGS " -fuse-ld=${SWIFT_USE_LINKER}")
6963
endif()
7064

7165
if(SWIFT_ANALYZE_CODE_COVERAGE)

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function(_add_target_variant_c_compile_link_flags)
9393
if("${CFLAGS_SDK}" STREQUAL "ANDROID")
9494
# lld can handle targeting the android build. However, if lld is not
9595
# enabled, then fallback to the linker included in the android NDK.
96-
if(NOT SWIFT_ENABLE_LLD_LINKER)
96+
if(NOT SWIFT_USE_LINKER STREQUAL "lld")
9797
swift_android_tools_path(${CFLAGS_ARCH} tools_path)
9898
list(APPEND result "-B" "${tools_path}")
9999
endif()
@@ -414,20 +414,11 @@ function(_add_target_variant_link_flags)
414414
list(APPEND library_search_directories "${SWIFT_${LFLAGS_SDK}_${LFLAGS_ARCH}_ICU_I18N_LIBDIR}")
415415
endif()
416416

417-
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
418-
# FIXME: On Apple platforms, find_program needs to look for "ld64.lld"
419-
find_program(LDLLD_PATH "ld.lld")
420-
if((SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH AND NOT APPLE) OR
421-
("${LFLAGS_SDK}" STREQUAL "WINDOWS" AND
422-
NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WINDOWS"))
423-
list(APPEND result "-fuse-ld=lld")
424-
elseif(SWIFT_ENABLE_GOLD_LINKER AND
425-
"${SWIFT_SDK_${LFLAGS_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
426-
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
427-
list(APPEND result "-fuse-ld=gold.exe")
428-
else()
429-
list(APPEND result "-fuse-ld=gold")
430-
endif()
417+
if(SWIFT_USE_LINKER AND NOT SWIFT_COMPILER_IS_MSVC_LIKE)
418+
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
419+
list(APPEND result "-fuse-ld=${SWIFT_USE_LINKER}.exe")
420+
else()
421+
list(APPEND result "-fuse-ld=${SWIFT_USE_LINKER}")
431422
endif()
432423
endif()
433424

test/lit.site.cfg.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ if "@SWIFT_ENABLE_SOURCEKIT_TESTS@" == "TRUE":
116116
if "@SWIFT_HAVE_LIBXML2@" == "TRUE":
117117
config.available_features.add('libxml2')
118118

119-
if "@SWIFT_ENABLE_LLD_LINKER@" == "TRUE":
119+
if "@SWIFT_USE_LINKER@" == "lld":
120120
config.android_linker_name = "lld"
121121
else:
122-
# even if SWIFT_ENABLE_GOLD_LINKER isn't set, we cannot use BFD for Android
122+
# even if SWIFT_USE_LINKER isn't set, we cannot use BFD for Android
123123
config.android_linker_name = "gold"
124124

125125
if '@SWIFT_INCLUDE_TOOLS@' == 'TRUE':

validation-test/lit.site.cfg.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ if "@CMAKE_GENERATOR@" == "Xcode":
9898

9999
config.available_features.add("CMAKE_GENERATOR=@CMAKE_GENERATOR@")
100100

101-
if "@SWIFT_ENABLE_LLD_LINKER@" == "TRUE":
101+
if "@SWIFT_USE_LINKER@" == "lld":
102102
config.android_linker_name = "lld"
103103
else:
104-
# even if SWIFT_ENABLE_GOLD_LINKER isn't set, we cannot use BFD for Android
104+
# even if SWIFT_USE_LINKER isn't set, we cannot use BFD for Android
105105
config.android_linker_name = "gold"
106106

107107
# Let the main config do the real work.

0 commit comments

Comments
 (0)