Skip to content

Commit 833da5d

Browse files
committed
Fixup SourceKit module on Windows
1 parent 6d6f899 commit 833da5d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Sources/SourceKit/SourceKitServer.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,13 @@ public final class SourceKitServer: LanguageServer {
169169
return nil
170170
}
171171

172+
#if os(Windows)
173+
let pid: Int = unsafeBitCast(GetCurrentProcess(), to: Int.self)
174+
#else
175+
let pid: Int = Int(getpid())
176+
#endif
172177
let resp = try service.sendSync(InitializeRequest(
173-
processId: Int(getpid()),
178+
processId: pid,
174179
rootPath: nil,
175180
rootURL: (workspace?.rootPath).map { URL(fileURLWithPath: $0.pathString) },
176181
initializationOptions: InitializationOptions(),

Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ final class SwiftSourceKitFramework {
4242

4343
init(dylib path: AbsolutePath) throws {
4444
self.path = path
45+
#if os(Windows)
46+
self.dylib = try dlopen(path.pathString, mode: [])
47+
#else
4548
self.dylib = try dlopen(path.pathString, mode: [.lazy, .local, .first, .deepBind])
49+
#endif
4650

4751
func dlsym_required<T>(_ handle: DLHandle, symbol: String) throws -> T {
4852
guard let sym: T = dlsym(handle, symbol: symbol) else {
@@ -54,7 +58,11 @@ final class SwiftSourceKitFramework {
5458
// Workaround rdar://problem/43656704 by not constructing the value directly.
5559
// self.api = sourcekitd_functions_t(
5660
let ptr = UnsafeMutablePointer<sourcekitd_functions_t>.allocate(capacity: 1)
61+
#if os(Windows)
62+
memset(UnsafeMutableRawPointer(ptr), 0, MemoryLayout<sourcekitd_functions_t>.stride)
63+
#else
5764
bzero(UnsafeMutableRawPointer(ptr), MemoryLayout<sourcekitd_functions_t>.stride)
65+
#endif
5866
var api = ptr.pointee
5967
ptr.deallocate()
6068

0 commit comments

Comments
 (0)