From 0868c5fc4b0aa779a87ae990c002abbef1470e9c Mon Sep 17 00:00:00 2001 From: Gwen Mittertreiner Date: Thu, 18 Apr 2019 12:38:57 -0700 Subject: [PATCH] Fixup SourceKit module on Windows --- Sources/SourceKit/SourceKitServer.swift | 7 ++++++- Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Sources/SourceKit/SourceKitServer.swift b/Sources/SourceKit/SourceKitServer.swift index e4595293..1595722c 100644 --- a/Sources/SourceKit/SourceKitServer.swift +++ b/Sources/SourceKit/SourceKitServer.swift @@ -169,8 +169,13 @@ public final class SourceKitServer: LanguageServer { return nil } + #if os(Windows) + let pid: Int = unsafeBitCast(GetCurrentProcess(), to: Int.self) + #else + let pid: Int = Int(getpid()) + #endif let resp = try service.sendSync(InitializeRequest( - processId: Int(getpid()), + processId: pid, rootPath: nil, rootURL: (workspace?.rootPath).map { URL(fileURLWithPath: $0.pathString) }, initializationOptions: InitializationOptions(), diff --git a/Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift b/Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift index e0c4004d..7385feb0 100644 --- a/Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift +++ b/Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift @@ -42,7 +42,11 @@ final class SwiftSourceKitFramework { init(dylib path: AbsolutePath) throws { self.path = path + #if os(Windows) + self.dylib = try dlopen(path.pathString, mode: []) + #else self.dylib = try dlopen(path.pathString, mode: [.lazy, .local, .first, .deepBind]) + #endif func dlsym_required(_ handle: DLHandle, symbol: String) throws -> T { guard let sym: T = dlsym(handle, symbol: symbol) else { @@ -54,7 +58,7 @@ final class SwiftSourceKitFramework { // Workaround rdar://problem/43656704 by not constructing the value directly. // self.api = sourcekitd_functions_t( let ptr = UnsafeMutablePointer.allocate(capacity: 1) - bzero(UnsafeMutableRawPointer(ptr), MemoryLayout.stride) + memset(UnsafeMutableRawPointer(ptr), 0, MemoryLayout.stride) var api = ptr.pointee ptr.deallocate()