Skip to content

Commit a363453

Browse files
committed
Add androidTarget to runtime module
OA# pick ccf3b6f Research android target support # Conflicts: # runtime/build.gradle.kts
1 parent 0ce431e commit a363453

File tree

6 files changed

+140
-4
lines changed

6 files changed

+140
-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
sourceSets {
@@ -74,7 +86,19 @@ kotlin {
7486

7587
nativeMain {}
7688

77-
androidMain {}
89+
androidMain {
90+
kotlin.setSrcDirs(["src/androidMain/kotlin"])
91+
}
92+
93+
forEach {
94+
// Android target has 3 source sets: androidMain, androidUnitTest, and androidInstrumentedTest
95+
println("SourceSet: $it")
96+
println(it.name)
97+
println(it.kotlin)
98+
println(it.kotlin.srcDirs)
99+
println(it.kotlin.sourceDirectories)
100+
}
101+
78102
}
79103
}
80104

@@ -152,3 +176,14 @@ benchmark {
152176
register("android")
153177
}
154178
}
179+
180+
java {
181+
sourceCompatibility = JavaVersion.VERSION_1_8
182+
targetCompatibility = JavaVersion.VERSION_1_8
183+
}
184+
185+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
186+
compilerOptions {
187+
jvmTarget.set(JvmTarget.JVM_1_8)
188+
}
189+
}

plugin/build.gradle.kts

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

181181
apiValidation {
182182
nonPublicMarkers += listOf("kotlinx.benchmark.gradle.internal.KotlinxBenchmarkPluginInternalApi")
183-
}
183+
}
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.kts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
34
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
45
import java.util.*
56

67
plugins {
78
alias(libs.plugins.kotlin.multiplatform)
9+
id("com.android.library")
810
}
911

1012
repositories {
1113
mavenCentral()
1214
}
1315

16+
android {
17+
compileSdk = 34
18+
namespace = "org.jetbrains.kotlinx.examples"
19+
20+
defaultConfig {
21+
minSdk = 29
22+
targetSdk = 34
23+
24+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
25+
}
26+
27+
buildTypes {
28+
release {
29+
}
30+
}
31+
compileOptions {
32+
sourceCompatibility = JavaVersion.VERSION_1_8
33+
targetCompatibility = JavaVersion.VERSION_1_8
34+
}
35+
}
36+
1437
kotlin {
1538
jvmToolchain(8)
1639

@@ -47,12 +70,15 @@ kotlin {
4770
@OptIn(ExperimentalWasmDsl::class)
4871
wasmJs { d8() }
4972

73+
androidTarget {}
74+
5075
@OptIn(ExperimentalKotlinGradlePluginApi::class)
5176
applyDefaultHierarchyTemplate {
5277
common {
5378
group("jsWasmJsShared") {
5479
withJs()
5580
withWasmJs()
81+
withAndroidTarget()
5682
}
5783
}
5884
}
@@ -125,3 +151,14 @@ tasks.withType(KotlinNativeCompile::class).configureEach {
125151
"-opt-in=kotlinx.cinterop.ExperimentalForeignApi",
126152
)
127153
}
154+
155+
java {
156+
sourceCompatibility = JavaVersion.VERSION_1_8
157+
targetCompatibility = JavaVersion.VERSION_1_8
158+
}
159+
160+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class).configureEach {
161+
compilerOptions {
162+
jvmTarget.set(JvmTarget.JVM_1_8)
163+
}
164+
}

0 commit comments

Comments
 (0)