Skip to content

Commit c4a0c00

Browse files
authored
Merge pull request #2979 from gottesmm/no_longer_pass_llvm_enable_lto_into_swift_cmake_invocation
2 parents 6f139d7 + bd9d595 commit c4a0c00

File tree

3 files changed

+56
-46
lines changed

3 files changed

+56
-46
lines changed

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
include(AddSwift)
3+
4+
add_custom_target(SwiftUnitTests)
5+
6+
set_target_properties(SwiftUnitTests PROPERTIES FOLDER "Tests")
7+
8+
function(add_swift_unittest test_dirname)
9+
# *NOTE* Even though "add_unittest" does not have llvm in its name, it is a
10+
# function defined by AddLLVM.cmake.
11+
add_unittest(SwiftUnitTests ${test_dirname} ${ARGN})
12+
13+
# TODO: _add_variant_c_compile_link_flags and these tests should share some
14+
# sort of logic.
15+
#
16+
# *NOTE* The unittests are never built for the target, so we always enable LTO
17+
# *if we are asked to.
18+
if (SWIFT_TOOLS_ENABLE_LTO)
19+
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY COMPILE_FLAGS " -flto ")
20+
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY LINK_FLAGS " -flto ")
21+
endif()
22+
23+
if(SWIFT_BUILT_STANDALONE AND NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
24+
# Replace target references with full paths, so that we use LLVM's
25+
# build configuration rather than Swift's.
26+
get_target_property(libnames ${test_dirname} LINK_LIBRARIES)
27+
28+
set(new_libnames)
29+
foreach(dep ${libnames})
30+
if("${dep}" MATCHES "^(LLVM|Clang|gtest)")
31+
list(APPEND new_libnames "${LLVM_LIBRARY_OUTPUT_INTDIR}/lib${dep}.a")
32+
else()
33+
list(APPEND new_libnames "${dep}")
34+
endif()
35+
endforeach()
36+
37+
set_property(TARGET ${test_dirname} PROPERTY LINK_LIBRARIES ${new_libnames})
38+
swift_common_llvm_config(${test_dirname} support)
39+
endif()
40+
41+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
42+
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
43+
LINK_FLAGS " -Xlinker -rpath -Xlinker ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/macosx")
44+
45+
if(SWIFT_ANALYZE_CODE_COVERAGE)
46+
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
47+
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
48+
endif()
49+
elseif(${SWIFT_ENABLE_GOLD_LINKER})
50+
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
51+
LINK_FLAGS " -fuse-ld=gold")
52+
endif()
53+
endfunction()
54+
55+

unittests/CMakeLists.txt

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,5 @@
1-
add_custom_target(SwiftUnitTests)
21

3-
set_target_properties(SwiftUnitTests PROPERTIES FOLDER "Tests")
4-
5-
function(add_swift_unittest test_dirname)
6-
add_unittest(SwiftUnitTests ${test_dirname} ${ARGN})
7-
8-
if(SWIFT_BUILT_STANDALONE AND NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
9-
# Replace target references with full paths, so that we use LLVM's
10-
# build configuration rather than Swift's.
11-
get_target_property(libnames ${test_dirname} LINK_LIBRARIES)
12-
13-
set(new_libnames)
14-
foreach(dep ${libnames})
15-
if("${dep}" MATCHES "^(LLVM|Clang|gtest)")
16-
list(APPEND new_libnames "${LLVM_LIBRARY_OUTPUT_INTDIR}/lib${dep}.a")
17-
else()
18-
list(APPEND new_libnames "${dep}")
19-
endif()
20-
endforeach()
21-
22-
set_property(TARGET ${test_dirname} PROPERTY LINK_LIBRARIES ${new_libnames})
23-
swift_common_llvm_config(${test_dirname} support)
24-
endif()
25-
26-
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
27-
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
28-
LINK_FLAGS " -Xlinker -rpath -Xlinker ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/macosx")
29-
30-
if(SWIFT_ANALYZE_CODE_COVERAGE)
31-
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
32-
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
33-
endif()
34-
elseif(${SWIFT_ENABLE_GOLD_LINKER})
35-
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
36-
LINK_FLAGS " -fuse-ld=gold")
37-
endif()
38-
endfunction()
2+
include(AddSwiftUnittests)
393

404
if(SWIFT_BUILD_TOOLS)
415
# We can't link C++ unit tests unless we build the tools.

utils/build-script-impl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -588,14 +588,6 @@ function set_build_options_for_host() {
588588
)
589589
fi
590590

591-
# We need to also pass in this flag so that parts of LLVM's
592-
# build system that we use (for instance when compiling
593-
# unittests) do not use too many threads when we are using lto.
594-
if [[ $(true_false "${LLVM_ENABLE_LTO}") == "TRUE" ]]; then
595-
swift_cmake_options+=(
596-
"-DLLVM_PARALLEL_LINK_JOBS=${LLVM_NUM_PARALLEL_LTO_LINK_JOBS}"
597-
)
598-
fi
599591
swift_cmake_options+=(
600592
"-DSWIFT_PARALLEL_LINK_JOBS=${SWIFT_TOOLS_NUM_PARALLEL_LTO_LINK_JOBS}"
601593
)
@@ -1864,7 +1856,6 @@ for host in "${ALL_HOSTS[@]}"; do
18641856
-DCMAKE_CXX_FLAGS="$(swift_c_flags ${host})"
18651857
-DCMAKE_BUILD_TYPE:STRING="${SWIFT_BUILD_TYPE}"
18661858
-DLLVM_ENABLE_ASSERTIONS:BOOL=$(true_false "${SWIFT_ENABLE_ASSERTIONS}")
1867-
-DLLVM_ENABLE_LTO=$(true_false "${LLVM_ENABLE_LTO}")
18681859
-DSWIFT_ANALYZE_CODE_COVERAGE:STRING=$(toupper "${SWIFT_ANALYZE_CODE_COVERAGE}")
18691860
-DSWIFT_STDLIB_BUILD_TYPE:STRING="${SWIFT_STDLIB_BUILD_TYPE}"
18701861
-DSWIFT_STDLIB_ASSERTIONS:BOOL=$(true_false "${SWIFT_STDLIB_ENABLE_ASSERTIONS}")

0 commit comments

Comments
 (0)