Skip to content

Commit

Permalink
Fix runner to build all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Martmists-GH committed Jun 1, 2024
1 parent 9274f11 commit db8f614
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 52 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/publish_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ jobs:
- '3.10'
- '3.11'
- '3.12'
runner-os:
- 'windows-latest'
- 'ubuntu-latest'
# - 'macos-latest'
runs-on: {{ matrix.runner-os }}
runs-on: 'macos-latest'
steps:
# Check out project
- uses: actions/checkout@v2
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/publish_snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ jobs:
- '3.10'
- '3.11'
- '3.12'
runner-os:
- 'windows-latest'
- 'ubuntu-latest'
# - 'macos-latest'
runs-on: {{ matrix.runner-os }}
runs-on: 'macos-latest'
steps:
# Check out project
- uses: actions/checkout@v2
Expand Down
88 changes: 46 additions & 42 deletions kpy-library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,64 @@ kotlin {
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")

val target = when {
hostOs == "Mac OS X" -> macosX64()
hostOs == "Linux" -> linuxX64()
isMingwX64 -> mingwX64()
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}
val targets = listOfNotNull(
if (hostOs == "Mac OS X") macosX64() else null,
if (!isMingwX64) linuxX64() else null,
mingwX64()
)


target.apply {
val main by compilations.getting {
targets.forEach {
it.apply {
val main by compilations.getting {

}
val python by main.cinterops.creating {
definitionFile = project.layout.projectDirectory.file("src/commonMain/cinterop/python.def")

val downloadSourcesTask = tasks.register("downloadPython${targetName}", DownloadPythonTask::class) {
version = pythonVersion
platform = when (konanTarget) {
KonanTarget.MINGW_X64 -> DownloadPythonTask.Platform.Windows
KonanTarget.LINUX_X64 -> DownloadPythonTask.Platform.Linux
else -> throw IllegalArgumentException("Unsupported target: $targetName")
}
}
val python by main.cinterops.creating {
definitionFile = project.layout.projectDirectory.file("src/commonMain/cinterop/python.def")

val downloadSourcesTask = tasks.register("downloadPython${targetName}", DownloadPythonTask::class) {
version = pythonVersion
platform = when (konanTarget) {
KonanTarget.MINGW_X64 -> DownloadPythonTask.Platform.Windows
KonanTarget.LINUX_X64 -> DownloadPythonTask.Platform.Linux
else -> throw IllegalArgumentException("Unsupported target: $targetName")
}
}

val extractSourcesTask = tasks.register("extractPython${targetName.capitalized()}", Exec::class) {
dependsOn(downloadSourcesTask)
val extractSourcesTask = tasks.register("extractPython${targetName.capitalized()}", Exec::class) {
dependsOn(downloadSourcesTask)

val outDir = project.layout.buildDirectory.dir("python-${pythonVersion.str}-${targetName}").get().asFile
val outDir =
project.layout.buildDirectory.dir("python-${pythonVersion.str}-${targetName}").get().asFile

executable = "tar"
args(
"-xzf",
downloadSourcesTask.get().tarFile.get().absolutePath,
"-C",
outDir.absolutePath
)
executable = "tar"
args(
"-xzf",
downloadSourcesTask.get().tarFile.get().absolutePath,
"-C",
outDir.absolutePath
)

outputs.dir(outDir)
outputs.dir(outDir)

when (konanTarget) {
KonanTarget.MINGW_X64 -> {
includeDirs(outDir.resolve("python/include"))
linkerOpts("-L${outDir.resolve("python").absolutePath} -lpython3")
}
KonanTarget.LINUX_X64 -> {
includeDirs(outDir.resolve("python/include/python${pythonVersion.str}"))
linkerOpts("-L${outDir.resolve("python/lib").absolutePath} -lpython3 -lresolv")
when (konanTarget) {
KonanTarget.MINGW_X64 -> {
includeDirs(outDir.resolve("python/include"))
linkerOpts("-L${outDir.resolve("python").absolutePath} -lpython3")
}

KonanTarget.LINUX_X64 -> {
includeDirs(outDir.resolve("python/include/python${pythonVersion.str}"))
linkerOpts("-L${outDir.resolve("python/lib").absolutePath} -lpython3 -lresolv")
}

else -> throw IllegalArgumentException("Unsupported target: $targetName")
}
else -> throw IllegalArgumentException("Unsupported target: $targetName")
}
}

tasks.named(interopProcessingTaskName) {
dependsOn(extractSourcesTask)
tasks.named(interopProcessingTaskName) {
dependsOn(extractSourcesTask)
}
}
}
}
Expand Down

0 comments on commit db8f614

Please sign in to comment.