There are a bunch of examples and bits of documentation related to parts of this, but I seem to be missing the bigger picture, so I’m posting here.
I have a build consisting of a number of subprojects, where subprojects build on each other’s outputs. My problem is with one subproject that produces a shared library (.so/.dylib) and a set of dynamically created C++ sources, and the other subproject which needs those artifacts to produce a Python wheel.
Here’s what I’ve been trying:
cpp/build.gradle.kts
val sharedLibFiles by configurations.consumable("sharedLibFiles")
val cApiSourceDir by configurations.consumable("cApiSourceDir")
// A custom task which builds the shared library files and lists them in the task outputs
val sharedLib = tasks.register<SharedLibTask>("shared-lib") {
outputDir = project.layout.buildDirectory.dir("c")
}
// A custom task which has an @OutputDirectory named outputDir
val cApiSetup = tasks.register<CApiSetupTask>("api-setup")
sharedLibFiles.outgoing.artifacts(sharedLibFiles.map { it.outputs.files }) { builtBy(sharedLib) }
cApiSourceDir.outgoing.artifact(cApiSetup.map { it.outputDir })
python/build.gradle.kts
val sharedLibsBucket by configurations.dependencyScope("sharedLibFilesBucket")
val sharedLibs by configurations.resolvable("sharedLibFiles") {
extendsFrom(sharedLibsBucket)
}
val cApiSourceDirBucket by configurations.dependencyScope("cApiSourceDirBucket")
val cApiSourceDir by configurations.resolvable("cApiSourceDir") {
extendsFrom(cApiSourceDirBucket)
}
dependencies {
sharedLibsBucket(project(mapOf("path" to ":cpp",
"configuration" to "sharedLibFiles")))
cApiSourceDirBucket(project(mapOf("path" to ":cpp",
"configuration" to "cApiSourceDir")))
}
// custom task that does the python build
val buildWheel = project.tasks.register<BuildWheel>("build_wheel") {
cApiSourceDir = cApiSourceDir.map { it.artifacts().files.singleFile }
sharedLibFiles = sharedLibs.map { it.artifacts().files }
outputDir = layout.buildDirectory.dir("wheel")
}
The aim is to provide the path to the output directory to the cApiSourceDir
property of the BuildWheel
task, which is a DirectoryProperty
, and the files from the sharedLibs
configuration to the sharedLibFiles
property of the BuildWheel
task.
At the moment I can’t even get the python.gradle.kts
to compile - there are errors about being not being able to reassign a val, type mismatches, and missing operator =
. I usually see these things when there’s type mismatches which mean the Gradle magic property DSL stuff isn’t able to be invoked because the type signatures aren’t matching.
One of the other parts of the project generates various Java jars and things that get consumed by other bits of the real CPP project, which is what I’ve based the above on, but I’m basically cargo culting it and I can’t figure out what I ought to do from the other documentation.
Does anyone have a suggestion, or an example you could point me to? Thanks!