Skip to content

Commit 33e9037

Browse files
committed
SourceKit: handle Windows codepaths better
Fill in some of the Windows codepaths that were previously missing. This allows us to at least compile the SourceKit sources. More changes are required to the build system to use the correct compiler when cross-compiling to get the dependencies correct.
1 parent 5e2c815 commit 33e9037

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

tools/SourceKit/tools/complete-test/complete-test.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,26 @@
2121
#include "llvm/Support/FileSystem.h"
2222
#include <fstream>
2323
#include <regex>
24+
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
2425
#include <unistd.h>
2526
#include <sys/param.h>
27+
#elif defined(_WIN32)
28+
#define WIN32_LEAN_AND_MEAN
29+
#define NOMINMAX
30+
#include <Windows.h>
31+
#endif
2632

2733
// FIXME: Platform compatibility.
2834
#include <dispatch/dispatch.h>
2935

3036
using namespace llvm;
3137

38+
#if defined(_WIN32)
39+
namespace {
40+
int STDOUT_FILENO = _fileno(stdout);
41+
}
42+
#endif
43+
3244
namespace {
3345
struct TestOptions {
3446
StringRef sourceFile;

tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
2727
#include "llvm/Support/FileSystem.h"
2828
#include "llvm/Support/FormatVariadic.h"
2929
#include <fstream>
30+
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
3031
#include <unistd.h>
3132
#include <sys/param.h>
33+
#elif defined(_WIN32)
34+
#define WIN32_LEAN_AND_MEAN
35+
#define NOMINMAX
36+
#include <Windows.h>
37+
#endif
3238

3339
// FIXME: Platform compatibility.
3440
#include <dispatch/dispatch.h>
@@ -37,6 +43,19 @@ using namespace llvm;
3743

3844
using namespace sourcekitd_test;
3945

46+
#if defined(_WIN32)
47+
namespace {
48+
int STDOUT_FILENO = _fileno(stdout);
49+
const constexpr size_t MAXPATHLEN = MAX_PATH + 1;
50+
char *realpath(const char *path, const char *resolved_path) {
51+
DWORD dwLength = GetFullPathNameA(path, 0, nullptr, nullptr);
52+
if (resolved_path = malloc(dwLength + 1))
53+
GetFullPathNameA(path, dwLength, resolved_path, nullptr);
54+
return resolved_path;
55+
}
56+
}
57+
#endif
58+
4059
static int handleTestInvocation(ArrayRef<const char *> Args, TestOptions &InitOpts);
4160
static bool handleResponse(sourcekitd_response_t Resp, const TestOptions &Opts,
4261
const std::string &SourceFile,

tools/SourceKit/tools/sourcekitd/bin/InProc/sourcekitdInProc.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,16 @@ UIdent sourcekitd::UIdentFromSKDUID(sourcekitd_uid_t uid) {
8080
}
8181

8282
std::string sourcekitd::getRuntimeLibPath() {
83-
// FIXME: Move to an LLVM API. Note that libclang does the same thing.
8483
#if defined(_WIN32)
85-
#error Not implemented
84+
MEMORY_BASIC_INFORMATION mbi;
85+
char path[MAX_PATH + 1];
86+
if (!VirtualQuery(static_cast<void *>(sourcekitd_initialize), &mbi,
87+
sizeof(mbi)))
88+
llvm_unreachable("call to VirtualQuery failed");
89+
if (!GetModuleFileNameA(static_cast<HINSTANCE>(mbi.AllocationBase), path,
90+
MAX_PATH))
91+
llvm_unreachable("call to GetModuleFileNameA failed");
92+
return llvm::sys::path::parent_path(path);
8693
#else
8794
// This silly cast below avoids a C++ warning.
8895
Dl_info info;

0 commit comments

Comments
 (0)