Skip to content

Commit 8c6cf7f

Browse files
committed
Build improvements: Kotlin 1.9.20-RC, default target hierarchy, bump Okio
Updated to Kotlin 1.9.20-RC: - Kotlin 1.9.0/10 had some blockers in XCode 15 support. - Simplify WASM setup (it has been changed in 1.9.20). - Drop obsolete Native targets. Apply default target hierarchy: - Greatly simplified buildscript for native targets. - Supported targets are now runnable from gutter in the IDE. - Now all possible targets are built by default (without -Pnative.deploy flag), resulting in less confusion for contributors and CI (but longer local `check` times). - Publishing library with K2 should be possible now, no more incorrect `publishNativeKotlinMetadata` failing task. - More targets available in integration-test project. Updated Okio for: - linuxArm64 target support
1 parent a675cb3 commit 8c6cf7f

File tree

12 files changed

+80
-264
lines changed

12 files changed

+80
-264
lines changed

formats/json-okio/build.gradle.kts

+4-9
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,11 @@ tasks.named<DokkaTaskPartial>("dokkaHtmlPartial") {
5252
}
5353

5454

55-
// Right now it is used for conditional support of kotlin 1.9.0 and 1.9.20+
5655
// TODO: Remove this after okio will be updated to the version with 1.9.20 stdlib dependency
57-
val kotlin_version: String by project
58-
val isNewWasmTargetEnabled = isKotlinVersionAtLeast(kotlin_version, 1, 9, 20)
59-
if (isNewWasmTargetEnabled) {
60-
configurations.all {
61-
resolutionStrategy.eachDependency {
62-
if (requested.name == "kotlin-stdlib-wasm") {
63-
useTarget("org.jetbrains.kotlin:kotlin-stdlib-wasm-js:${requested.version}")
64-
}
56+
configurations.all {
57+
resolutionStrategy.eachDependency {
58+
if (requested.name == "kotlin-stdlib-wasm") {
59+
useTarget("org.jetbrains.kotlin:kotlin-stdlib-wasm-js:${requested.version}")
6560
}
6661
}
6762
}

formats/json-tests/build.gradle.kts

+4-17
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,11 @@ kotlin {
5050

5151
project.configureJava9ModuleInfo()
5252

53-
// Right now it is used for conditional support of kotlin 1.9.0 and 1.9.20+
5453
// TODO: Remove this after okio will be updated to the version with 1.9.20 stdlib dependency
55-
val kotlin_version: String by project
56-
val isNewWasmTargetEnabled = isKotlinVersionAtLeast(kotlin_version, 1, 9, 20)
57-
if (isNewWasmTargetEnabled) {
58-
configurations.all {
59-
resolutionStrategy.eachDependency {
60-
if (requested.name == "kotlin-stdlib-wasm") {
61-
useTarget("org.jetbrains.kotlin:kotlin-stdlib-wasm-js:${requested.version}")
62-
}
54+
configurations.all {
55+
resolutionStrategy.eachDependency {
56+
if (requested.name == "kotlin-stdlib-wasm") {
57+
useTarget("org.jetbrains.kotlin:kotlin-stdlib-wasm-js:${requested.version}")
6358
}
6459
}
6560
}
66-
67-
// TODO: Remove this after default kotlin will be updated to 1.9.20
68-
// https://youtrack.jetbrains.com/issue/KT-60212
69-
if (!isNewWasmTargetEnabled) {
70-
tasks.named("wasmD8Test", KotlinJsTest::class) {
71-
filter.excludePatterns += "kotlinx.serialization.features.EmojiTest"
72-
}
73-
}

formats/json/build.gradle

+2-11
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ tasks.named("koverVerify") {
2020
enabled = false
2121
}
2222

23-
// Right now it is used for conditional support of kotlin 1.9.0 and 1.9.20+
24-
def isNewWasmTargetEnabled = isKotlinVersionAtLeast(rootProject.properties["kotlin_version"], 1, 9, 20)
25-
2623
kotlin {
2724
sourceSets {
2825
configureEach {
@@ -42,14 +39,8 @@ kotlin {
4239
jsMain {
4340
dependsOn(sourceSets.jsWasmMain)
4441
}
45-
if (isNewWasmTargetEnabled) {
46-
wasmJsMain {
47-
dependsOn(sourceSets.jsWasmMain)
48-
}
49-
} else {
50-
wasmMain {
51-
dependsOn(sourceSets.jsWasmMain)
52-
}
42+
wasmJsMain {
43+
dependsOn(sourceSets.jsWasmMain)
5344
}
5445
}
5546
}

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
group=org.jetbrains.kotlinx
66
version=1.6.1-SNAPSHOT
77

8-
kotlin.version=1.9.0
8+
kotlin.version=1.9.20-RC
99

1010
# This version takes precedence if 'bootstrap' property passed to project
1111
kotlin.version.snapshot=1.9.255-SNAPSHOT
@@ -20,7 +20,7 @@ knit_version=0.5.0-Beta
2020
# Only for tests
2121
coroutines_version=1.6.4
2222
kover_version=0.4.2
23-
okio_version=3.5.0
23+
okio_version=3.6.0
2424

2525
kover.enabled=true
2626

gradle/configure-source-sets.gradle

+15-37
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ tasks.withType(JavaCompile).configureEach {
1414
options.release = 8
1515
}
1616

17-
// Right now it is used for conditional support of kotlin 1.9.0 and 1.9.20+
18-
def isNewWasmTargetEnabled = isKotlinVersionAtLeast(rootProject.properties["kotlin_version"], 1, 9, 20)
19-
2017
kotlin {
2118
jvm {
2219
withJava()
@@ -45,14 +42,8 @@ kotlin {
4542
}
4643
}
4744

48-
if (isNewWasmTargetEnabled) {
49-
wasmJs {
50-
d8()
51-
}
52-
} else {
53-
wasm {
54-
d8()
55-
}
45+
wasmJs {
46+
d8()
5647
}
5748

5849
sourceSets.all {
@@ -105,35 +96,22 @@ kotlin {
10596
}
10697
}
10798

108-
if(isNewWasmTargetEnabled) {
109-
wasmJsMain {
110-
kotlin {
111-
srcDir 'wasmMain/src'
112-
}
113-
dependencies {
114-
api 'org.jetbrains.kotlin:kotlin-stdlib-wasm-js'
115-
}
116-
}
11799

118-
wasmJsTest {
119-
kotlin {
120-
srcDir 'wasmTest/src'
121-
}
122-
dependencies {
123-
api 'org.jetbrains.kotlin:kotlin-test-wasm-js'
124-
}
100+
wasmJsMain {
101+
kotlin {
102+
srcDir 'wasmMain/src'
125103
}
126-
} else {
127-
wasmMain {
128-
dependencies {
129-
api 'org.jetbrains.kotlin:kotlin-stdlib-wasm'
130-
}
104+
dependencies {
105+
api 'org.jetbrains.kotlin:kotlin-stdlib-wasm-js'
131106
}
107+
}
132108

133-
wasmTest {
134-
dependencies {
135-
api 'org.jetbrains.kotlin:kotlin-test-wasm'
136-
}
109+
wasmJsTest {
110+
kotlin {
111+
srcDir 'wasmTest/src'
112+
}
113+
dependencies {
114+
api 'org.jetbrains.kotlin:kotlin-test-wasm-js'
137115
}
138116
}
139117

@@ -184,4 +162,4 @@ kotlin {
184162
}
185163
}
186164
}
187-
}
165+
}

gradle/native-targets.gradle

+30-166
Original file line numberDiff line numberDiff line change
@@ -2,178 +2,42 @@
22
* Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
/**
6-
* Specifies what subset of Native targets to build
7-
*
8-
* ALL — all possible for compilation
9-
* HOST — host-specific ones, without cross compilation (e.g. do not build linuxX64 on macOS host)
10-
* SINGLE — only for current OS (to import into IDEA / quickly run tests)
11-
* DISABLED — disable all Native targets (useful with Kotlin compiler built from sources)
12-
*
13-
* For HOST mode, all targets are still listed in .module file, so HOST mode is useful for release process.
14-
*/
15-
enum NativeState {
16-
ALL, HOST, SINGLE, DISABLED
17-
}
18-
19-
def getNativeState(String description) {
20-
if (description == null) return NativeState.SINGLE
21-
switch (description.toLowerCase()) {
22-
case 'all':
23-
case 'true':
24-
return NativeState.ALL
25-
case 'host':
26-
return NativeState.HOST
27-
case 'disabled':
28-
return NativeState.DISABLED
29-
// 'single', 'false', etc
30-
default:
31-
return NativeState.SINGLE
32-
}
33-
}
34-
35-
project.ext.ideaActive = System.getProperty('idea.active') == 'true'
36-
project.ext.nativeState = getNativeState(property('native.deploy'))
37-
project.ext.singleTargetMode = project.ext.ideaActive || (project.ext.nativeState == NativeState.SINGLE)
38-
39-
project.ext.nativeMainSets = []
40-
project.ext.nativeTestSets = []
41-
42-
/**
43-
* Disables compilation but leaves the target in .module file
44-
*/
45-
def disableCompilation(targets) {
46-
configure(targets) {
47-
compilations.all {
48-
cinterops.all { project.tasks[interopProcessingTaskName].enabled = false }
49-
compileKotlinTask.enabled = false
50-
}
51-
binaries.all { linkTask.enabled = false }
52-
53-
mavenPublication { publicationToDisable ->
54-
tasks.withType(AbstractPublishToMaven).all {
55-
onlyIf { publication != publicationToDisable }
56-
}
57-
tasks.withType(GenerateModuleMetadata).all {
58-
onlyIf { publication.get() != publicationToDisable }
59-
}
60-
}
61-
}
62-
}
63-
64-
def getHostName() {
65-
def target = System.getProperty("os.name")
66-
if (target == 'Linux') return 'linux'
67-
if (target.startsWith('Windows')) return 'windows'
68-
if (target.startsWith('Mac')) return 'macos'
69-
return 'unknown'
70-
}
71-
725
static def doesNotDependOnOkio(project) {
736
return !project.name.contains("json-okio") && !project.name.contains("json-tests")
747
}
758

769
kotlin {
7710
targets {
78-
def manager = project.ext.hostManager
79-
def linuxEnabled = manager.isEnabled(presets.linuxX64.konanTarget)
80-
def macosEnabled = manager.isEnabled(presets.macosX64.konanTarget)
81-
def winEnabled = manager.isEnabled(presets.mingwX64.konanTarget)
82-
83-
def ideaPreset = presets.linuxX64
84-
if (macosEnabled) ideaPreset = presets.macosX64
85-
if (winEnabled) ideaPreset = presets.mingwX64
86-
project.ext.ideaPreset = ideaPreset
87-
}
88-
89-
targets {
90-
delegate.metaClass.addTarget = { preset ->
91-
def target = delegate.fromPreset(preset, preset.name)
92-
project.ext.nativeMainSets.add(target.compilations['main'].kotlinSourceSets.first())
93-
project.ext.nativeTestSets.add(target.compilations['test'].kotlinSourceSets.first())
94-
}
95-
}
96-
97-
targets {
98-
if (project.ext.nativeState == NativeState.DISABLED) return
99-
100-
String[] versionComponents = (~/[.-]/).split(compilerVersion, 4)
101-
String[] versionComponents1920 = ["1", "9", "20"]
102-
def isAtLeast1920 = Arrays.compare(versionComponents, versionComponents1920) { lhs, rhs ->
103-
(lhs as int) <=> (rhs as int)
104-
} >= 0
105-
106-
if (project.ext.singleTargetMode) {
107-
fromPreset(project.ext.ideaPreset, 'native')
108-
} else {
109-
// According to https://kotlinlang.org/docs/native-target-support.html
110-
// Tier 1
111-
addTarget(presets.linuxX64)
112-
addTarget(presets.macosX64)
113-
addTarget(presets.macosArm64)
114-
addTarget(presets.iosSimulatorArm64)
115-
addTarget(presets.iosX64)
116-
117-
// Tier 2
118-
if (doesNotDependOnOkio(project)) {
119-
addTarget(presets.linuxArm64)
120-
}
121-
addTarget(presets.watchosSimulatorArm64)
122-
addTarget(presets.watchosX64)
123-
addTarget(presets.watchosArm32)
124-
addTarget(presets.watchosArm64)
125-
addTarget(presets.tvosSimulatorArm64)
126-
addTarget(presets.tvosX64)
127-
addTarget(presets.tvosArm64)
128-
addTarget(presets.iosArm64)
129-
130-
// Tier 3
131-
if (doesNotDependOnOkio(project)) {
132-
addTarget(presets.androidNativeArm32)
133-
addTarget(presets.androidNativeArm64)
134-
addTarget(presets.androidNativeX86)
135-
addTarget(presets.androidNativeX64)
136-
addTarget(presets.watchosDeviceArm64)
137-
}
138-
139-
addTarget(presets.mingwX64)
140-
141-
// Deprecated, but were provided by kotlinx.serialization; can be removed only in 1.9.20 release.
142-
if (!isAtLeast1920) {
143-
addTarget(presets.watchosX86)
144-
145-
if (doesNotDependOnOkio(project)) {
146-
addTarget(presets.iosArm32)
147-
addTarget(presets.linuxArm32Hfp)
148-
addTarget(presets.mingwX86)
149-
}
150-
}
151-
152-
}
153-
154-
if (project.ext.nativeState == NativeState.HOST) {
155-
// linux targets that can cross-compile on all three hosts
156-
def linuxCrossCompileTargets = isAtLeast1920 ? [presets.linuxX64] : [presets.linuxX64, presets.linuxArm32Hfp, presets.linuxArm64]
157-
if (getHostName() != "linux") {
158-
disableCompilation(linuxCrossCompileTargets)
159-
}
160-
}
161-
}
162-
163-
164-
sourceSets {
165-
nativeMain { dependsOn commonMain }
166-
// Empty source set is required in order to have native tests task
167-
nativeTest { dependsOn commonTest }
168-
169-
if (!project.ext.singleTargetMode) {
170-
configure(project.ext.nativeMainSets) {
171-
dependsOn nativeMain
172-
}
173-
174-
configure(project.ext.nativeTestSets) {
175-
dependsOn nativeTest
176-
}
11+
targetHierarchy.default()
12+
13+
// According to https://kotlinlang.org/docs/native-target-support.html
14+
// Tier 1
15+
linuxX64()
16+
macosX64()
17+
macosArm64()
18+
iosSimulatorArm64()
19+
iosX64()
20+
21+
// Tier 2
22+
watchosSimulatorArm64()
23+
watchosX64()
24+
watchosArm32()
25+
watchosArm64()
26+
tvosSimulatorArm64()
27+
tvosX64()
28+
tvosArm64()
29+
iosArm64()
30+
linuxArm64()
31+
32+
// Tier 3
33+
mingwX64()
34+
// https://github.com/square/okio/issues/1242#issuecomment-1759357336
35+
if (doesNotDependOnOkio(project)) {
36+
androidNativeArm32()
37+
androidNativeArm64()
38+
androidNativeX86()
39+
androidNativeX64()
40+
watchosDeviceArm64()
17741
}
17842
}
17943
}

0 commit comments

Comments
 (0)