Skip to content

Commit 2c07a23

Browse files
committed
Cleanup WMO forcing
This patch cleans up the handling of WMO-forcing in the workaround file. `-wmo` is passed in each of the link jobs in the non-CMP0157-enabled configuration to keep it matching the behavior of the CMP0157-enabled builds. This also moves the commentary about num-threads and WMO to the top of the file to make it clearer what is going on. Ideally the file wouldn't have to exist, but it does. The file also contains the target install-name fix that landed in CMake 3.29.8 and CMake 3.30.2, so earlier versions of CMake 3.29 will work with this build as well.
1 parent dad1ea8 commit 2c07a23

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# This file contains workarounds for dealing with bugs between CMake and the
22
# Swift compiler.
33

4-
# FIXME: This is a workaround for the broken Swift compiler that cannot
5-
# typecheck the Swift stdlib without crashing. <ADD RADAR HERE>.
6-
# This is manipulating undocumented CMake-internal variables that may
7-
# change behavior at any time and should not be relied on.
4+
# This is a workaround to avoid crashing the Swift compiler while typechecking
5+
# swiftCore. The Swift compiler must be run num-threads=0 with WMO in all build
6+
# configurations.
7+
# These must be set in CMake _before_ the Swift language is enabled.
8+
# This is manipulating undocumented CMake-internal variables that may change
9+
# behavior at any time and should not be relied on.
10+
# Otherwise CMake will generate the build graph incorrectly for this setup.
11+
# Ideally this file should not need to exist.
12+
813
set(CMAKE_Swift_NUM_THREADS 0)
914
if(POLICY CMP0157)
1015
set(CMAKE_Swift_COMPILE_OBJECT "<CMAKE_Swift_COMPILER> -num-threads ${CMAKE_Swift_NUM_THREADS} -c <DEFINES> <FLAGS> <INCLUDES> <SOURCE>")
@@ -18,14 +23,12 @@ if(POLICY CMP0157)
1823
set(CMAKE_Swift_LINK_EXECUTABLE "<CMAKE_Swift_COMPILER> -num-threads ${SwiftStdlib_NUM_LINK_JOBS} -emit-executable -o <TARGET> <FLAGS> <OBJECTS> <LINK_FLAGS> <LINK_LIBRARIES>")
1924
set(CMAKE_Swift_CREATE_SHARED_LIBRARY "<CMAKE_Swift_COMPILER> -num-threads ${SwiftStdlib_NUM_LINK_JOBS} -emit-library <CMAKE_SHARED_LIBRARY_Swift_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> ${CMAKE_Swift_IMPLIB_LINKER_FLAGS} <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
2025
else()
21-
set(CMAKE_Swift_CREATE_SHARED_LIBRARY "<CMAKE_Swift_COMPILER> -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> ${CMAKE_Swift_IMPLIB_LINKER_FLAGS} <LINK_LIBRARIES>")
26+
set(CMAKE_Swift_CREATE_SHARED_LIBRARY "<CMAKE_Swift_COMPILER> -wmo -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> ${CMAKE_Swift_IMPLIB_LINKER_FLAGS} <LINK_LIBRARIES>")
2227

23-
set(CMAKE_Swift_LINK_EXECUTABLE "<CMAKE_Swift_COMPILER> -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-executable -o <TARGET> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>")
28+
set(CMAKE_Swift_LINK_EXECUTABLE "<CMAKE_Swift_COMPILER> -wmo -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-executable -o <TARGET> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>")
2429

25-
set(CMAKE_Swift_CREATE_STATIC_LIBRARY "<CMAKE_Swift_COMPILER> -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -static -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>")
30+
set(CMAKE_Swift_CREATE_STATIC_LIBRARY "<CMAKE_Swift_COMPILER> -wmo -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -static -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>")
2631

2732
set(CMAKE_Swift_ARCHIVE_CREATE "<CMAKE_AR> crs <TARGET> <OBJECTS>")
2833
set(CMAKE_Swift_ARCHIVE_FINISH "")
29-
30-
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-wmo>)
3134
endif()

0 commit comments

Comments
 (0)