1+ package utilities
2+
3+ import org.gradle.api.Project
4+ import org.gradle.kotlin.dsl.support.serviceOf
5+ import org.gradle.process.ExecOperations
6+ import java.io.ByteArrayOutputStream
7+ import java.io.File
8+
9+ private fun Project.swiftRuntimeLibraryPaths (): List <String > {
10+ val stdout = ByteArrayOutputStream ()
11+ serviceOf<ExecOperations >().exec {
12+ workingDir(projectDir)
13+ commandLine(" swiftc" , " -print-target-info" )
14+ standardOutput = stdout
15+ }
16+ return json.decodeFromString<SwiftcTargetInfo >(stdout.toString()).paths.runtimeLibraryPaths
17+ }
18+
19+ fun Project.javaLibraryPaths (rootDir : File ? ): List <String > {
20+ val osName = System .getProperty(" os.name" )
21+ val osArch = System .getProperty(" os.arch" )
22+ val isLinux = osName.lowercase().contains(" linux" )
23+ val base = if (rootDir == null ) " " else " ${rootDir} /"
24+
25+ val triple = if (isLinux) {
26+ val arch = if (osArch == " amd64" || osArch == " x86_64" ) " x86_64" else osArch
27+ " ${arch} -unknown-linux-gnu"
28+ } else {
29+ val arch = if (osArch == " aarch64" ) " arm64" else osArch
30+ " ${arch} -apple-macosx"
31+ }
32+
33+ val paths: List <String > = listOf (" release" , " debug" ).flatMap { configuration ->
34+ listOf (
35+ " ${base} .build/${triple} /$configuration /" ,
36+ " ${base} ../../.build/${triple} /$configuration /" ,
37+ )
38+ }
39+ val swiftRuntimePaths = swiftRuntimeLibraryPaths()
40+
41+ return paths + swiftRuntimePaths
42+ }
0 commit comments