Swift: linking static libraries with old driver results in errors due to default WMO
!7741 (merged) enabled Whole Module Optimization for all Swift release targets through -wmo
flag. However, a regression was detected after CMake 3.26 release due to the legacy C++ compiler driver for Swift (referred to as Swift old driver) behaving differently under WMO compile mode. Swift old driver is superseded by the new Swift Driver, which is the default in latest official releases. However, the new driver is still not mandatory, and the old driver may be used by 3rd-party toolchains, during a toolchain build and from older Swift toolchains.
For detail, the Swift old driver will treat all inputs as Swift source files with -wmo
due to historical reasons. In other situations, the driver can recognize the input file type by its path extension and content. CMake, by default, append static libraries to the compiler command-line as inputs, assuming that the compiler driver can classify them and pass them to the linker/archiver directly. With WMO enabled, the old driver will unexpectedly parse binary files as source codes, resulting in compiler errors.