Skip to content

Commit f862243

Browse files
committed
Extract protobuf into a separate module
1 parent 1b48790 commit f862243

File tree

77 files changed

+272
-469
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+272
-469
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package util
6+
7+
import org.gradle.api.GradleException
8+
import org.gradle.api.NamedDomainObjectContainer
9+
import org.gradle.api.Project
10+
import org.gradle.api.tasks.Exec
11+
import org.gradle.internal.extensions.stdlib.capitalized
12+
import org.gradle.kotlin.dsl.extra
13+
import org.gradle.kotlin.dsl.named
14+
import org.gradle.kotlin.dsl.provideDelegate
15+
import org.gradle.kotlin.dsl.register
16+
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
17+
import org.jetbrains.kotlin.gradle.plugin.mpp.DefaultCInteropSettings
18+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
19+
import org.jetbrains.kotlin.gradle.tasks.CInteropProcess
20+
import java.io.File
21+
import kotlin.io.resolve
22+
23+
// works with the cinterop-c Bazel project
24+
fun KotlinMultiplatformExtension.configureCLibCInterop(
25+
project: Project,
26+
bazelBuildArg: String,
27+
configureCinterop: NamedDomainObjectContainer<DefaultCInteropSettings>.(cinteropCLib: File) -> Unit,
28+
) {
29+
val globalRootDir: String by project.extra
30+
31+
val cinteropCLib = project.layout.projectDirectory.dir("$globalRootDir/cinterop-c").asFile
32+
33+
// TODO: Replace function implementation, so it does not use an internal API
34+
fun findProgram(name: String) = org.gradle.internal.os.OperatingSystem.current().findInPath(name)
35+
val checkBazel = project.tasks.register("checkBazel") {
36+
doLast {
37+
val bazelPath = findProgram("bazel")
38+
if (bazelPath != null) {
39+
logger.debug("bazel: {}", bazelPath)
40+
} else {
41+
throw GradleException("'bazel' not found on PATH. Please install Bazel (https://bazel.build/).")
42+
}
43+
}
44+
}
45+
46+
val buildCinteropCLib = project.tasks.register<Exec>("buildCinteropCLib") {
47+
group = "build"
48+
workingDir = cinteropCLib
49+
commandLine("bash", "-c", "bazel build $bazelBuildArg --config=release")
50+
inputs.files(project.fileTree(cinteropCLib) { exclude("bazel-*/**") })
51+
outputs.dir(cinteropCLib.resolve("bazel-bin"))
52+
53+
dependsOn(checkBazel)
54+
}
55+
56+
targets.filterIsInstance<KotlinNativeTarget>().forEach {
57+
it.compilations.getByName("main") {
58+
cinterops {
59+
configureCinterop(cinteropCLib)
60+
}
61+
62+
cinterops.whenObjectAdded {
63+
val interop = this
64+
65+
val interopTask = "cinterop${interop.name.capitalized()}${it.targetName.capitalized()}"
66+
project.tasks.named(interopTask, CInteropProcess::class) {
67+
dependsOn(buildCinteropCLib)
68+
}
69+
}
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)