Skip to content

Commit 89dafee

Browse files
committed
Add androidTarget to runtime module
1 parent ccf3b6f commit 89dafee

File tree

6 files changed

+146
-4
lines changed

6 files changed

+146
-4
lines changed

examples/kotlin-multiplatform/build.gradle

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import kotlinx.benchmark.gradle.JsBenchmarksExecutor
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23

34
plugins {
45
id 'org.jetbrains.kotlin.multiplatform'
@@ -27,6 +28,8 @@ android {
2728

2829
buildTypes {
2930
release {
31+
// isMinifyEnabled = false
32+
// proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
3033
}
3134
}
3235
compileOptions {
@@ -35,7 +38,18 @@ android {
3538
}
3639
}
3740

41+
// Could not determine the dependencies of task ':examples:kotlin-multiplatform:extractReleaseAnnotations'.
42+
// > Could not resolve all task dependencies for configuration ':examples:kotlin-multiplatform:detachedConfiguration1'.
43+
// > Could not find com.android.tools.lint:lint-gradle:31.2.2.
44+
repositories {
45+
google()
46+
}
47+
3848
kotlin {
49+
androidTarget {
50+
// Android target does not have any compilations
51+
println("android compilations: ${compilations.size()}")
52+
}
3953
jvm {
4054
compilations.create('benchmark') { associateWith(compilations.main) }
4155
}
@@ -52,8 +66,6 @@ kotlin {
5266
linuxX64()
5367
mingwX64()
5468

55-
androidTarget {}
56-
5769
applyDefaultHierarchyTemplate()
5870

5971
targets.configureEach {
@@ -86,7 +98,19 @@ kotlin {
8698

8799
nativeMain {}
88100

89-
androidMain {}
101+
androidMain {
102+
kotlin.setSrcDirs(["src/androidMain/kotlin"])
103+
}
104+
105+
forEach {
106+
// Android target has 3 source sets: androidMain, androidUnitTest, and androidInstrumentedTest
107+
println("SourceSet: $it")
108+
println(it.name)
109+
println(it.kotlin)
110+
println(it.kotlin.srcDirs)
111+
println(it.kotlin.sourceDirectories)
112+
}
113+
90114
}
91115
}
92116

@@ -175,3 +199,14 @@ rootProject.extensions.findByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.
175199
rootProject.tasks.withType(org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask.class).configureEach {
176200
args.add("--ignore-engines")
177201
}
202+
203+
java {
204+
sourceCompatibility = JavaVersion.VERSION_1_8
205+
targetCompatibility = JavaVersion.VERSION_1_8
206+
}
207+
208+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
209+
compilerOptions {
210+
jvmTarget.set(JvmTarget.JVM_1_8)
211+
}
212+
}

plugin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,4 @@ if (project.findProperty("publication_repository") == "space") {
163163

164164
apiValidation {
165165
nonPublicMarkers += ["kotlinx.benchmark.gradle.internal.KotlinxBenchmarkPluginInternalApi"]
166-
}
166+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package kotlinx.benchmark
2+
3+
actual enum class Scope {
4+
Benchmark
5+
}
6+
7+
@Target(AnnotationTarget.CLASS)
8+
actual annotation class State(actual val value: Scope)
9+
10+
@Target(AnnotationTarget.FUNCTION)
11+
actual annotation class Setup
12+
13+
@Target(AnnotationTarget.FUNCTION)
14+
actual annotation class TearDown
15+
16+
@Target(AnnotationTarget.FUNCTION)
17+
actual annotation class Benchmark
18+
19+
20+
@Target(AnnotationTarget.CLASS)
21+
actual annotation class BenchmarkMode(actual vararg val value: Mode)
22+
23+
actual enum class Mode {
24+
Throughput, AverageTime
25+
}
26+
27+
@Target(AnnotationTarget.CLASS)
28+
actual annotation class OutputTimeUnit(actual val value: BenchmarkTimeUnit)
29+
30+
actual enum class BenchmarkTimeUnit {
31+
NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES
32+
}
33+
34+
@Target(AnnotationTarget.CLASS)
35+
actual annotation class Warmup(
36+
actual val iterations: Int,
37+
actual val time: Int,
38+
actual val timeUnit: BenchmarkTimeUnit,
39+
actual val batchSize: Int
40+
)
41+
42+
@Target(AnnotationTarget.CLASS)
43+
actual annotation class Measurement(
44+
actual val iterations: Int,
45+
actual val time: Int,
46+
actual val timeUnit: BenchmarkTimeUnit,
47+
actual val batchSize: Int
48+
)
49+
50+
actual annotation class Param(actual vararg val value: String)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package kotlinx.benchmark
2+
3+
4+
internal actual fun Double.format(precision: Int, useGrouping: Boolean): String =
5+
error("Not implemented")
6+
7+
internal actual fun String.writeFile(text: String): Unit =
8+
error("Not implemented")
9+
10+
internal actual fun String.readFile(): String =
11+
error("Not implemented")
12+
13+
internal actual inline fun measureNanoseconds(block: () -> Unit): Long =
14+
error("Not implemented")

runtime/build.gradle

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
12
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
23

34
plugins {
45
alias(libs.plugins.kotlin.multiplatform)
6+
id 'com.android.library'
57
}
68

79
repositories {
810
mavenCentral()
911
}
1012

13+
android {
14+
compileSdk 34
15+
namespace = "org.jetbrains.kotlinx.examples"
16+
17+
defaultConfig {
18+
minSdk = 29
19+
targetSdk = 34
20+
versionCode = 1
21+
versionName = "1.0"
22+
23+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
24+
}
25+
26+
buildTypes {
27+
release {
28+
}
29+
}
30+
compileOptions {
31+
sourceCompatibility = JavaVersion.VERSION_1_8
32+
targetCompatibility = JavaVersion.VERSION_1_8
33+
}
34+
}
35+
1136
kotlin {
1237
// According to https://kotlinlang.org/docs/native-target-support.html
1338

@@ -41,11 +66,14 @@ kotlin {
4166
js("jsIr", IR) { nodejs() }
4267
wasm("wasmJs") { d8() }
4368

69+
androidTarget {}
70+
4471
applyDefaultHierarchyTemplate { root ->
4572
root.common { common ->
4673
common.group("jsWasmJsShared") { group ->
4774
group.withJs()
4875
group.withWasm()
76+
group.withAndroidTarget()
4977
}
5078
}
5179
}
@@ -95,6 +123,9 @@ kotlin {
95123
nativeMain {
96124
dependsOn(commonMain)
97125
}
126+
androidMain {
127+
dependsOn(commonMain)
128+
}
98129
}
99130
}
100131

@@ -128,3 +159,15 @@ tasks.withType(KotlinNativeCompile).configureEach {
128159
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
129160
)
130161
}
162+
163+
164+
java {
165+
sourceCompatibility = JavaVersion.VERSION_1_8
166+
targetCompatibility = JavaVersion.VERSION_1_8
167+
}
168+
169+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
170+
compilerOptions {
171+
jvmTarget.set(JvmTarget.JVM_1_8)
172+
}
173+
}

0 commit comments

Comments
 (0)