11
11
//===----------------------------------------------------------------------===//
12
12
13
13
import Foundation
14
+ #if os(Windows)
15
+ import WinSDK
16
+ #endif
14
17
15
18
/// The set of commandline tools used to build a tibs project.
16
19
public final class TibsToolchain {
@@ -99,7 +102,11 @@ public final class TibsToolchain {
99
102
let fsec = Float ( usec) / 1_000_000
100
103
fputs ( " warning: waiting \( fsec) second \( fsec == 1.0 ? " " : " s " ) to ensure file timestamp " +
101
104
" differs; \( reason) \n " , stderr)
105
+ #if os(Windows)
106
+ Sleep ( usec / 1000 )
107
+ #else
102
108
usleep ( usec)
109
+ #endif
103
110
}
104
111
}
105
112
}
@@ -183,6 +190,15 @@ public func findTool(name: String) -> URL? {
183
190
#if os(macOS)
184
191
p. launchPath = " /usr/bin/xcrun "
185
192
p. arguments = [ " --find " , name]
193
+ #elseif os(Windows)
194
+ var buf = [ WCHAR] ( repeating: 0 , count: Int ( MAX_PATH) )
195
+ GetWindowsDirectoryW ( & buf, DWORD ( MAX_PATH) )
196
+ let foo = DWORD ( 0 )
197
+ var wherePath = String ( decodingCString: & buf, as: UTF16 . self)
198
+ . appendingPathComponent ( " system32 " )
199
+ . appendingPathComponent ( " where.exe " )
200
+ p. launchPath = wherePath
201
+ p. arguments = [ name]
186
202
#else
187
203
p. launchPath = " /usr/bin/which "
188
204
p. arguments = [ name]
@@ -201,8 +217,13 @@ public func findTool(name: String) -> URL? {
201
217
guard var path = String ( data: data, encoding: . utf8) else {
202
218
return nil
203
219
}
220
+ #if os(Windows)
221
+ let paths = path. split { $0. isNewline }
222
+ path = String ( paths [ 0 ] ) . trimmingCharacters ( in: . whitespacesAndNewlines)
223
+ #else
204
224
if path. last == " \n " {
205
225
path = String ( path. dropLast ( ) )
206
226
}
227
+ #endif
207
228
return URL ( fileURLWithPath: path)
208
229
}
0 commit comments