Charlie Tapping
04/16/2023, 11:10 AMtasks.register<Exec>("skynet") {
dependsOn(":bin:nativeBinaries")
val bin = "./bin/build/bin/native/debugExecutable/skynet.kexe"
executable = "sh"
args = listOf("-c", bin)
}
However I wanted to declare it like so
val nativeBinaries by project("bin").tasks.existing
val nativeBinaries by tasks.existing
tasks.register<Exec>("skynet") {
dependsOn(nativeBinaries)
But I can’t seem to get a reference to it?
For context the nativeBinaries task exists in a kotlin native submodule called “bin”Adam S
04/16/2023, 11:15 AMCharlie Tapping
04/16/2023, 11:20 AMephemient
04/16/2023, 11:21 AMCharlie Tapping
04/16/2023, 11:21 AMtasks.register<Exec>("skynet") {
dependsOn(":bin:nativeBinaries")
val bin = "./bin/build/bin/native/debugExecutable/skynet.kexe"
executable = "sh"
args = listOf("-c", bin)
}
Adam S
04/16/2023, 11:29 AM:bin
project so it doesn’t produce an executable, it produces a library. And then it the root project also set up Kotlin/Native, add a dependency on :bin
, and a custom K/N target with an exec
This stuff can be really complicated in Gradle, but if you explained what’s going on, or what error you get, or why the task needs to be run in a separate subproject, then maybe there’s a better wayCharlie Tapping
04/16/2023, 12:06 PMephemient
04/16/2023, 12:13 PMkotlin {
for (target in listOf(linuxX64(), linuxArm64(), macosArm64(), macosX64(), mingwX64())) {
target.binaries.executable {
entryPoint("...")
}
}
}
you can configure executable { runTaskProvider?.configure { ... } }
if you want to specify args or environment variableskotlin {
targets.withType<KotlinNativeTarget> {
binaries.matching { it.outputKind == NativeOutputKind.EXECUTABLE }.all {
artifacts.add(
configurations.create("${this@withType.name}${name.capitalized()}") {
isCanBeConsumed = true
isCanBeResolved = false
attributes {
attribute(KotlinPlatformType.attribute, KotlinPlatformType.native)
attribute(KotlinNativeTarget.konanTargetAttribute, konanTarget.name)
attribute(KotlinNativeTarget.kotlinNativeBuildTypeAttribute, buildType.name)
attribute(Usage.USAGE_ATTRIBUTE, objects.named("native-binary"))
}
}.name,
this.linkTaskProvider
)
}
}
}
and consume the specific one,
val hostSkynetBinary by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = true
attributes {
attribute(KotlinPlatformType.attribute, KotlinPlatformType.native)
attribute(KotlinNativeTarget.konanTargetAttribute, HostManager.host.name)
attribute(KotlinNativeTarget.kotlinNativeBuildTypeAttribute, "DEBUG")
attribute(Usage.USAGE_ATTRIBUTE, objects.named("native-binary"))
}
}
dependencies {
hostSkynetBinary(project(":bin"))
}
tasks.register("skynet", Exec::class) {
inputs.files(hostSkynetBinary)
commandLine("/bin/sh", "-c")
argumentProviders.add { listOf("${hostSkynetBinary.singleFile}/*.kexe") }
}
Charlie Tapping
04/16/2023, 12:29 PMrunDebugExecutableNative
and runReleaseExecutableNative
. It just I couldn’t get these working at first because of the wizard generated config which targeted x86 binaries