From d81ce1949d09ead8fd48fa01a75d5c796599f37a Mon Sep 17 00:00:00 2001 From: Alastair Houghton Date: Thu, 8 Aug 2024 12:54:32 +0100 Subject: [PATCH] [Frontend][Win32] Fix runtime path to point at runtime libs. The code that generates the runtime path is not right for Windows; fix it to point at the correct place. This makes simple use of `swift test.swift` work. rdar://132598892 --- lib/Frontend/CompilerInvocation.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index dd44796999424..7924dbbc83bab 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -198,8 +198,35 @@ static void updateRuntimeLibraryPaths(SearchPathOptions &SearchPathOpts, if (LangOpts.hasFeature(Feature::Embedded)) LibSubDir = "embedded"; - llvm::sys::path::append(LibPath, LibSubDir); SearchPathOpts.RuntimeLibraryPaths.clear(); + +#if defined(_WIN32) + // Resource path looks like this: + // + // C:\...\Swift\Toolchains\6.0.0+Asserts\usr\lib\swift + // + // The runtimes are in + // + // C:\...\Swift\Runtimes\6.0.0\usr\bin + // + llvm::SmallString<128> RuntimePath(LibPath); + + llvm::sys::path::remove_filename(RuntimePath); + llvm::sys::path::remove_filename(RuntimePath); + llvm::sys::path::remove_filename(RuntimePath); + + llvm::SmallString<128> VersionWithAttrs(llvm::sys::path::filename(RuntimePath)); + size_t MaybePlus = VersionWithAttrs.find_first_of('+'); + StringRef Version = VersionWithAttrs.substr(0, MaybePlus); + + llvm::sys::path::remove_filename(RuntimePath); + llvm::sys::path::remove_filename(RuntimePath); + llvm::sys::path::append(RuntimePath, "Runtimes", Version, "usr", "bin"); + + SearchPathOpts.RuntimeLibraryPaths.push_back(std::string(RuntimePath.str())); +#endif + + llvm::sys::path::append(LibPath, LibSubDir); SearchPathOpts.RuntimeLibraryPaths.push_back(std::string(LibPath.str())); if (Triple.isOSDarwin()) SearchPathOpts.RuntimeLibraryPaths.push_back(DARWIN_OS_LIBRARY_PATH);