@@ -25,6 +25,7 @@ import java.io.File
2525fun KotlinMultiplatformExtension.configureCLibCInterop (
2626 project : Project ,
2727 bazelTask : String ,
28+ cinteropTaskDependsOn : List <Any > = emptyList(),
2829 configureCinterop : NamedDomainObjectContainer <DefaultCInteropSettings >.(cLibSource: File , cLibOutDir: File ) -> Unit ,
2930) {
3031 val buildTargetName = bazelTask.split(" :" ).last()
@@ -56,6 +57,7 @@ fun KotlinMultiplatformExtension.configureCLibCInterop(
5657 val interopTask = " cinterop${interop.name.capitalized()}${this @configureEach.targetName.capitalized()} "
5758 project.tasks.named(interopTask, CInteropProcess ::class ) {
5859 dependsOn(buildCinteropCLib)
60+ cinteropTaskDependsOn.forEach { dependsOn(it) }
5961 }
6062 }
6163 }
@@ -76,12 +78,7 @@ fun KotlinMultiplatformExtension.configureCLibCInterop(
7678fun KotlinMultiplatformExtension.configureCLibDependency (
7779 project : Project ,
7880 bazelTask : String ,
79- bazelExtractIncludeTask : String? = null,
80- bazelExtractIncludeOutputDir : Provider <Directory >? = null,
8181) {
82- require((bazelExtractIncludeTask == null ) == (bazelExtractIncludeOutputDir == null )) {
83- " Either both bazelExtractIncludeTask and bazelExtractIncludeOutputDir must be specified or neither."
84- }
8582 val buildTargetName = bazelTask.split(" :" ).last()
8683 val prebuiltLibDir = project.cLibPrebuiltDepsDir.resolve(buildTargetName)
8784
@@ -106,21 +103,6 @@ fun KotlinMultiplatformExtension.configureCLibDependency(
106103 }
107104 }
108105
109- if (bazelExtractIncludeTask != null ) {
110- val includeDir = bazelExtractIncludeOutputDir!! .get().asFile
111- project.tasks.register<Exec >(" buildIncludeDirCLib${buildTargetName.capitalized()} " ) {
112- dependsOn(" :checkBazel" )
113- group = " build"
114- workingDir = project.cinteropLibDir
115- commandLine(
116- " bash" ,
117- " -c" ,
118- " ./extract_include_dir.sh //prebuilt-deps/grpc_fat:grpc_include_dir $includeDir "
119- )
120- outputs.dir(includeDir.resolve(" include" ))
121- }
122- }
123-
124106 project.tasks.register(" buildDependencyAllTargetsForCLib${buildTargetName.capitalized()} " ) {
125107 group = " build"
126108 targets.withType<KotlinNativeTarget >().forEach { target ->
@@ -135,6 +117,26 @@ fun KotlinMultiplatformExtension.configureCLibDependency(
135117 }
136118}
137119
120+ fun Project.registerBuildCLibIncludeDirTask (
121+ bazelTask : String ,
122+ bazelExtractIncludeOutputDir : Provider <Directory >,
123+ ): TaskProvider <Exec > {
124+ val buildTargetName = bazelTask.split(" :" ).last()
125+ val includeDir = bazelExtractIncludeOutputDir.get().asFile
126+ return project.tasks.register<Exec >(" buildIncludeDirCLib${buildTargetName.capitalized()} " ) {
127+ dependsOn(" :checkBazel" )
128+ group = " build"
129+ workingDir = project.cinteropLibDir
130+ commandLine(
131+ " bash" ,
132+ " -c" ,
133+ " ./extract_include_dir.sh //prebuilt-deps/grpc_fat:grpc_include_dir $includeDir "
134+ )
135+ outputs.dir(includeDir.resolve(" include" ))
136+ }
137+ }
138+
139+
138140private val Project .cLibPrebuiltDepsDir: File get() = cinteropLibDir.resolve(" prebuilt-deps" )
139141
140142private val Project .bazelBuildDir: Directory
0 commit comments