-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
Description
When C++ interop is enabled, which usually would cause the program to linked with the swiftCxxStdlib module, but if it's not actually used (dependency scanning didn't find it used) in a explicit module build on Windows, linking fails with
lld-link: error: could not open 'swiftCxxStdlib.lib': no such file or directory
The swiftCxxStdlib module must be statically linked currently for Windows and the Windows SDK provides the static version libswiftCxxStdlib.lib only. Hence the linker trying to link with the dynamic version swiftCxxStdlib.lib fails.
This is because in the following code the Context.getModuleByName("CxxStdlib") call won't find the module if dependency scanning didn't find it actually used (hasStaticCxxStdlib == false) and registerCxxInteropLibraries will emit the dynamic version of the library file name.
if (Context.LangOpts.EnableCXXInterop) {
bool hasStaticCxx = false;
bool hasStaticCxxStdlib = false;
if (const auto *M = Context.getModuleByName(CXX_MODULE_NAME))
hasStaticCxx = M->isStaticLibrary();
if (Context.LangOpts.Target.getOS() == llvm::Triple::Win32)
if (const auto *M = Context.getModuleByName("CxxStdlib"))
hasStaticCxxStdlib = M->isStaticLibrary();
dependencies::registerCxxInteropLibraries(Context.LangOpts.Target,
getSwiftModule()->getName().str(),
hasStaticCxx,
hasStaticCxxStdlib,
Context.LangOpts.CXXStdlib,
registerLinkLibrary);
}
Reproduction
Input nocpp.swift
// Anything that doesn't use CxxStdlibCommand
swiftc nocpp.swift -cxx-interoperability-mode=default -explicit-module-build
...
lld-link: error: could not open 'swiftCxxStdlib.lib': no such file or directory
The case where the std clang module is used (CRT depends on it) but not the Swift CxxStdlib module.
Input crt.swift
import CRTCommand
swiftc crt.swift -cxx-interoperability-mode=default -explicit-module-build
...
lld-link: error: could not open 'swiftCxxStdlib.lib': no such file or directory
Expected behavior
Successful build/link
Environment
The main branch on Windows
Additional information
No response