Skip to content

Commit 526127b

Browse files
committed
build: only use gold on ELF targets
gold only supports ELF. This adds two new helper functions (is_windows_based_sdk and is_elfish_sdk) to ensure that we dont try to use gold on non-ELF targets. This comes up when trying to setup cross-compilation for the standard library for Windows. The ELF check is implemented as the negation of Darwin (which uses MachO) and Windows (which uses COFF). The reason for this is that there are additional targets which also use ELF. Rather than enumerating the larger set, enumerate the smaller set (windows) and use the negation.
1 parent 8a16921 commit 526127b

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,25 @@ function(is_darwin_based_sdk sdk_name out_var)
7676
endif()
7777
endfunction()
7878

79+
function(is_windows_based_sdk sdk_name out_var)
80+
if("${sdk_name}" STREQUAL "WINDOWS" OR
81+
"${sdk_name}" STREQUAL "CYGWIN")
82+
set(${out_var} TRUE PARENT_SCOPE)
83+
else()
84+
set(${out_var} FALSE PARENT_SCOPE)
85+
endif()
86+
endfunction()
87+
88+
function(is_elfish_sdk sdk_name out_var)
89+
is_darwin_based_sdk("${sdk_name}" IS_DARWIN)
90+
is_windows_based_sdk("${sdk_name}" IS_WINDOWS)
91+
if(IS_DARWIN OR IS_WINDOWS)
92+
set(${out_var} FALSE PARENT_SCOPE)
93+
else()
94+
set(${out_var} TRUE PARENT_SCOPE)
95+
endif()
96+
endfunction()
97+
7998
# Usage:
8099
# _add_variant_c_compile_link_flags(
81100
# SDK sdk
@@ -871,7 +890,8 @@ function(_add_swift_library_single target name)
871890
RESULT_VAR_NAME link_flags
872891
)
873892

874-
if(SWIFT_ENABLE_GOLD_LINKER)
893+
is_elfish_sdk("${SWIFTLIB_SINGLE_SDK}" IS_ELFISH)
894+
if(SWIFT_ENABLE_GOLD_LINKER AND IS_ELFISH)
875895
list(APPEND link_flags "-fuse-ld=gold")
876896
endif()
877897

@@ -1512,9 +1532,8 @@ function(_add_swift_executable_single name)
15121532
"-Xlinker" "@executable_path/../lib/swift/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}")
15131533
endif()
15141534

1515-
if(SWIFT_ENABLE_GOLD_LINKER AND
1516-
( "${SWIFTEXE_SINGLE_SDK}" STREQUAL "LINUX" ) )
1517-
# Extend the link_flags for the gold linker.
1535+
is_elfish_sdk("${SWIFTLIB_SINGLE_SDK}" IS_ELFISH)
1536+
if(SWIFT_ENABLE_GOLD_LINKER AND IS_ELFISH)
15181537
list(APPEND link_flags "-fuse-ld=gold")
15191538
endif()
15201539

0 commit comments

Comments
 (0)