Skip to content

Commit 848be0d

Browse files
committed
TypeSystem: add a platform hook for library search path additions
Windows does not provide a library search path through a mechanism similar to `DT_RPATH` or `LC_RPATH`. Libraries are instead resolved via the environment variable `Path`. Add a hook to inject the default library search path into the repl instance. This is required to ensure that system libraries are available. With this, it is finally possible to run the REPL on Windows without any additional parameters.
1 parent 761429b commit 848be0d

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

lldb/include/lldb/Host/HostInfoBase.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ class HostInfoBase {
147147
FileSpec &lldb_shlib_spec, FileSpec &file_spec, bool verify) {
148148
return false;
149149
}
150+
151+
/// Return the default set of library paths to search in. This allows a
152+
/// platform specific extension for system libraries that may need to be
153+
/// resolved (e.g. `/usr/lib` on Unicies and `Path` on Windows).
154+
static std::vector<std::string> GetSwiftLibrarySearchPaths() { return {}; }
150155
#endif
151156

152157
protected:

lldb/include/lldb/Host/windows/HostInfoWindows.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class HostInfoWindows : public HostInfoBase {
4242
static bool ComputeSwiftResourceDirectory(FileSpec &lldb_shlib_spec,
4343
FileSpec &file_spec, bool verify);
4444
static llvm::Expected<llvm::StringRef> GetSDKRoot(SDKOptions options);
45+
static std::vector<std::string> GetSwiftLibrarySearchPaths();
4546
#endif
4647

4748
private:

lldb/source/Host/windows/HostInfoWindowsSwift.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313
#include "lldb/Utility/FileSpec.h"
1414
#include "lldb/Utility/LLDBLog.h"
1515
#include "lldb/Utility/Log.h"
16+
17+
#include <llvm/ADT/STLExtras.h>
18+
#include <llvm/ADT/StringExtras.h>
19+
#include <llvm/ADT/StringRef.h>
1620
#include <llvm/Support/ConvertUTF.h>
1721

22+
#include <cstdlib>
1823
#include <string>
24+
#include <vector>
1925

2026
using namespace lldb_private;
2127

@@ -60,3 +66,17 @@ llvm::Expected<llvm::StringRef> HostInfoWindows::GetSDKRoot(SDKOptions options)
6066
return g_sdkroot;
6167
return llvm::make_error<HostInfoError>("`SDKROOT` is unset");
6268
}
69+
70+
std::vector<std::string> HostInfoWindows::GetSwiftLibrarySearchPaths() {
71+
static std::once_flag g_flag;
72+
static std::vector<std::string> g_library_paths;
73+
74+
std::call_once(g_flag, []() {
75+
llvm::for_each(llvm::split(std::getenv("Path"), ";"),
76+
[](llvm::StringRef path) {
77+
g_library_paths.emplace_back(path);
78+
});
79+
});
80+
81+
return g_library_paths;
82+
}

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,6 +3528,8 @@ GetLibrarySearchPaths(const swift::SearchPathOptions &search_path_opts) {
35283528
paths.push_back(path);
35293529
for (std::string path : search_path_opts.LibrarySearchPaths)
35303530
paths.push_back(path);
3531+
for (const std::string &path : HostInfo::GetSwiftLibrarySearchPaths())
3532+
paths.emplace_back(path);
35313533
return paths;
35323534
}
35333535

0 commit comments

Comments
 (0)