Skip to content

Commit fecabce

Browse files
committed
limit mingw things to Windows hosts
1 parent 0e7b538 commit fecabce

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

runtime/runtime-core/build.gradle.kts

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import aws.sdk.kotlin.gradle.util.prop
22
import aws.sdk.kotlin.gradle.util.typedProp
3+
import org.jetbrains.kotlin.konan.target.HostManager
34
import java.nio.file.Files
45
import java.nio.file.Paths
56

@@ -60,21 +61,21 @@ kotlin {
6061
}
6162
}
6263

64+
if (HostManager.hostIsMingw) {
65+
mingwX64 {
66+
val mingwHome = findMingwHome()
67+
val defPath = layout.buildDirectory.file("cinterop/winver.def")
6368

64-
mingwX64 {
65-
val mingwHome = findMingwHome()
66-
val defPath = layout.buildDirectory.file("cinterop/winver.def")
69+
// Dynamically construct def file because of dynamic mingw paths
70+
val defFileTask by tasks.registering {
71+
outputs.file(defPath)
6772

68-
// Dynamically construct def file because of dynamic mingw paths
69-
val defFileTask by tasks.registering {
70-
outputs.file(defPath)
73+
val mingwLibs = Paths.get(mingwHome, "lib").toString().replace("\\", "\\\\") // Windows path shenanigans
7174

72-
val mingwLibs = Paths.get(mingwHome, "lib").toString().replace("\\", "\\\\") // Windows path shenanigans
73-
74-
doLast {
75-
Files.writeString(
76-
defPath.get().asFile.toPath(),
77-
"""
75+
doLast {
76+
Files.writeString(
77+
defPath.get().asFile.toPath(),
78+
"""
7879
package = aws.smithy.kotlin.native.winver
7980
headers = windows.h
8081
compilerOpts = \
@@ -88,28 +89,29 @@ kotlin {
8889
libraryPaths = $mingwLibs
8990
staticLibraries = libversion.a
9091
""".trimIndent(),
91-
)
92+
)
93+
}
9294
}
93-
}
9495

95-
compilations["main"].cinterops {
96-
create("winver") {
97-
val mingwIncludes = Paths.get(mingwHome, "include").toString()
98-
includeDirs(mingwIncludes)
99-
definitionFile.set(defPath)
96+
compilations["main"].cinterops {
97+
create("winver") {
98+
val mingwIncludes = Paths.get(mingwHome, "include").toString()
99+
includeDirs(mingwIncludes)
100+
definitionFile.set(defPath)
100101

101-
// Ensure that the def file is written first
102-
tasks[interopProcessingTaskName].dependsOn(defFileTask)
102+
// Ensure that the def file is written first
103+
tasks[interopProcessingTaskName].dependsOn(defFileTask)
104+
}
103105
}
104-
}
105106

106-
// TODO clean up
107-
val compilerArgs = listOf(
108-
"-Xverbose-phases=linker", // Enable verbose linking phase from the compiler
109-
"-linker-option",
110-
"-v",
111-
)
112-
compilerOptions.freeCompilerArgs.addAll(compilerArgs)
107+
// TODO clean up
108+
val compilerArgs = listOf(
109+
"-Xverbose-phases=linker", // Enable verbose linking phase from the compiler
110+
"-linker-option",
111+
"-v",
112+
)
113+
compilerOptions.freeCompilerArgs.addAll(compilerArgs)
114+
}
113115
}
114116
}
115117

0 commit comments

Comments
 (0)