• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 import org.gradle.internal.impldep.org.fusesource.jansi.AnsiRenderer.test
2 import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework
3 import org.jetbrains.kotlin.cli.common.toBooleanLenient
4 import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
5 import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
6 import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkConfig
7 
<lambda>null8 plugins {
9   kotlin("multiplatform")
10 }
11 
12 
13 val libName = "Flatbuffers"
14 group = "com.google.flatbuffers.kotlin"
15 version = "2.0.0-SNAPSHOT"
16 
<lambda>null17 kotlin {
18   explicitApi()
19   jvm()
20   js(IR) {
21     browser {
22       testTask {
23         enabled = false
24       }
25     }
26     binaries.executable()
27   }
28   macosX64()
29   macosArm64()
30   iosArm64()
31   iosSimulatorArm64()
32 
33   sourceSets {
34 
35     val commonMain by getting {
36       dependencies {
37         implementation(kotlin("stdlib-common"))
38       }
39     }
40 
41     val commonTest by getting {
42       dependencies {
43         implementation(kotlin("test"))
44       }
45 
46       kotlin.srcDir("src/commonTest/generated/kotlin/")
47     }
48     val jvmTest by getting {
49       dependencies {
50         implementation(kotlin("test-junit"))
51         implementation("com.google.flatbuffers:flatbuffers-java:2.0.3")
52       }
53     }
54     val jvmMain by getting {
55     }
56 
57     val macosX64Main by getting
58     val macosArm64Main by getting
59     val iosArm64Main by getting
60     val iosSimulatorArm64Main by getting
61 
62     val nativeMain by creating {
63       // this sourceSet will hold common cold for all iOS targets
64       dependsOn(commonMain)
65       macosArm64Main.dependsOn(this)
66       macosX64Main.dependsOn(this)
67       iosArm64Main.dependsOn(this)
68       iosSimulatorArm64Main.dependsOn(this)
69     }
70 
71     all {
72       languageSettings.optIn("kotlin.ExperimentalUnsignedTypes")
73     }
74   }
75 }
76 
77 // Fixes JS issue: https://youtrack.jetbrains.com/issue/KT-49109
<lambda>null78 rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
79   rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = "16.0.0"
80 
81 }
82 
83 // Use the default greeting
<lambda>null84 tasks.register<GenerateFBTestClasses>("generateFBTestClassesKt") {
85   inputFiles.setFrom("$rootDir/../tests/monster_test.fbs",
86     "$rootDir/../tests/dictionary_lookup.fbs",
87 // @todo Seems like nesting code generation is broken for all generators.
88 // disabling test for now.
89 //    "$rootDir/../tests/namespace_test/namespace_test1.fbs",
90 //    "$rootDir/../tests/namespace_test/namespace_test2.fbs",
91     "$rootDir/../tests/union_vector/union_vector.fbs",
92     "$rootDir/../tests/optional_scalars.fbs")
93   includeFolder.set("$rootDir/../tests/include_test")
94   outputFolder.set("${projectDir}/src/commonTest/generated/kotlin/")
95   variant.set("kotlin-kmp")
96 }
97 
98 
<lambda>null99 project.tasks.forEach {
100   if (it.name.contains("compileKotlin"))
101     it.dependsOn("generateFBTestClassesKt")
102 }
103 
intPropertynull104 fun String.intProperty() = findProperty(this).toString().toInt()
105 
106 abstract class GenerateFBTestClasses : DefaultTask() {
107   @get:InputFiles
108   abstract val inputFiles: ConfigurableFileCollection
109 
110   @get:Input
111   abstract val includeFolder: Property<String>
112 
113   @get:Input
114   abstract val outputFolder: Property<String>
115 
116   @get:Input
117   abstract val variant: Property<String>
118 
119   @Inject
120   protected open fun getExecActionFactory(): org.gradle.process.internal.ExecActionFactory? {
121     throw UnsupportedOperationException()
122   }
123 
124   init {
125     includeFolder.set("")
126   }
127 
128   @TaskAction
129   fun compile() {
130     val execAction = getExecActionFactory()!!.newExecAction()
131     val sources = inputFiles.asPath.split(":")
132     val args = mutableListOf("flatc","-o", outputFolder.get(), "--${variant.get()}")
133     if (includeFolder.get().isNotEmpty()) {
134       args.add("-I")
135       args.add(includeFolder.get())
136     }
137     args.addAll(sources)
138     println(args)
139     execAction.commandLine = args
140     print(execAction.execute())
141   }
142 }
143