Skip to content

Commit 3517bba

Browse files
committed
use -print-target-info to get swift library paths reliably
1 parent 0c57644 commit 3517bba

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

buildSrc/src/main/groovy/org/swift/swiftkit/gradle/BuildUtils.groovy

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@
1414

1515
package org.swift.swiftkit.gradle
1616

17+
import groovy.json.JsonSlurper
18+
1719
final class BuildUtils {
1820

21+
static List<String> getSwiftRuntimeLibraryPaths() {
22+
def process = ['swiftc', '-print-target-info'].execute()
23+
def output = new StringWriter()
24+
process.consumeProcessOutput(output, System.err)
25+
process.waitFor()
26+
27+
def json = new JsonSlurper().parseText(output.toString())
28+
def runtimeLibraryPaths = json.paths.runtimeLibraryPaths
29+
return runtimeLibraryPaths
30+
}
31+
1932
/// Find library paths for 'java.library.path' when running or testing projects inside this build.
2033
static def javaLibraryPaths(File rootDir) {
2134
def osName = System.getProperty("os.name")
@@ -40,19 +53,8 @@ final class BuildUtils {
4053
"${base}../../.build/${osArch}-apple-macosx/debug/"),
4154
]
4255
def releasePaths = debugPaths.collect { it.replaceAll("debug", "release") }
43-
def systemPaths =
44-
// system paths
45-
isLinux ?
46-
[
47-
"/usr/lib/swift/linux",
48-
// TODO: should we be Swiftly aware and then use the currently used path?
49-
System.getProperty("user.home") + "/.local/share/swiftly/toolchains/6.0.2/usr/lib/swift/linux"
50-
] :
51-
[
52-
// assume macOS
53-
"/usr/lib/swift/"
54-
]
55-
56-
return releasePaths + debugPaths + systemPaths
56+
def swiftRuntimePaths = getSwiftRuntimeLibraryPaths()
57+
58+
return releasePaths + debugPaths + swiftRuntimePaths
5759
}
5860
}

0 commit comments

Comments
 (0)