Skip to content

Commit dab60f0

Browse files
committed
Respect default search paths on Windows
1 parent 90ec47d commit dab60f0

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Sources/TSCBasic/Process.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import var Foundation.NSLocalizedDescriptionKey
1414

1515
#if os(Windows)
1616
import Foundation
17+
import WinSDK
1718
#endif
1819

1920
@_implementationOnly import TSCclibc
@@ -350,10 +351,26 @@ public final class Process {
350351
pathString: ProcessEnv.path,
351352
currentWorkingDirectory: cwdOpt
352353
)
354+
var searchPaths: [AbsolutePath] = []
355+
#if os(Windows)
356+
var buffer = Array<WCHAR>(repeating: 0, count: Int(MAX_PATH + 1))
357+
// The 32-bit Windows system directory
358+
if GetSystemDirectoryW(&buffer, .init(buffer.count)) > 0 {
359+
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))
360+
}
361+
if GetWindowsDirectoryW(&buffer, .init(buffer.count)) > 0 {
362+
let windowsDirectory = String(decodingCString: buffer, as: UTF16.self)
363+
// The 16-bit Windows system directory
364+
searchPaths.append(AbsolutePath("\(windowsDirectory)\\System"))
365+
// The Windows directory
366+
searchPaths.append(AbsolutePath(windowsDirectory))
367+
}
368+
#endif
369+
searchPaths.append(contentsOf: envSearchPaths)
353370
let value = lookupExecutablePath(
354371
filename: program,
355372
currentWorkingDirectory: cwdOpt,
356-
searchPaths: envSearchPaths
373+
searchPaths: searchPaths
357374
)
358375
return value
359376
}

0 commit comments

Comments
 (0)