Skip to content

Commit ec095ac

Browse files
authored
Merge pull request #251 from rickclephas/feature/kotlin-2.4.0
Kotlin 2.4.0
2 parents f6fa4d4 + 46405c2 commit ec095ac

53 files changed

Lines changed: 369 additions & 798 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.idea/kotlinc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SWIFT_EXPORT.md

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,9 @@ For now the plugin just clones your original functions and properties to prevent
3131
**Temporary workaround:**
3232
You should disable any relevant code in Swift if you would like to try Swift export.
3333

34-
## ⚠️ `@ObjCName` is ignored
35-
36-
The `@ObjCName` annotation is (currently) ignored by Swift export.
37-
This prevents KMP-NativeCoroutines from reusing your original function or property name.
38-
39-
**Temporary workaround:**
40-
You should update your Swift code with the `Native` name suffix in order to access the generated declarations.
41-
4234
# Enabling Swift export
4335

44-
To enable Swift export with KMP-NativeCoroutines you start by following the
45-
[official documentation](https://kotlinlang.org/docs/native-swift-export.html)
46-
and enabling the experimental coroutines support:
47-
```kotlin
48-
// build.gradle.kts
49-
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.swiftexport.SWIFT_EXPORT_COROUTINES_SUPPORT_TURNED_ON
50-
51-
kotlin {
52-
// ...
53-
swiftExport {
54-
// ...
55-
configure {
56-
settings.put(SWIFT_EXPORT_COROUTINES_SUPPORT_TURNED_ON, "true")
57-
}
58-
}
59-
}
60-
```
61-
62-
Once Swift export is enabled you'll need to activate the Swift export compatibility mode:
36+
To enable Swift export with KMP-NativeCoroutines you'll need to activate the Swift export compatibility mode:
6337
```kotlin
6438
// build.gradle.kts
6539
nativeCoroutines {
@@ -72,15 +46,13 @@ nativeCoroutines {
7246
Only some coroutines related code can be used when Swift export is enabled.
7347

7448
> [!NOTE]
75-
> You can also use the generated properties for the `StateFlow.value` and `SharedFlow.replayCache` values,
76-
> but keep in mind the `@ObjCName` limitation.
49+
> You can also use the generated properties for the `StateFlow.value` and `SharedFlow.replayCache` values.
7750
7851
## Suspend functions
7952

80-
You can use suspend functions as async functions in Swift (but keep in mind the limitations):
81-
```diff
82-
- let letters = try await asyncFunction(for: randomLettersGenerator.getRandomLetters(throwException: throwException))
83-
+ let letters = try await asyncFunction(for: randomLettersGenerator.getRandomLettersNative(throwException: throwException))
53+
You can use suspend functions as async functions in Swift without any changes:
54+
```swift
55+
let letters = try await asyncFunction(for: randomLettersGenerator.getRandomLetters(throwException: throwException))
8456
```
8557

8658
> [!NOTE]
@@ -90,5 +62,5 @@ You can use suspend functions as async functions in Swift (but keep in mind the
9062
For Combine and RxSwift there are helper functions available, e.g.:
9163
```diff
9264
- let future = createFuture(for: randomLettersGenerator.getRandomLetters(throwException: throwException))
93-
+ let future = createFuture(for: { await self.randomLettersGenerator.getRandomLettersNative(throwException: throwException) })
65+
+ let future = createFuture(for: { await self.randomLettersGenerator.getRandomLetters(throwException: throwException) })
9466
```

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ buildscript {
1313

1414
allprojects {
1515
group = "com.rickclephas.kmp"
16-
version = "1.0.3"
16+
version = "1.0.3-kotlin-2.4.0-Beta2"
1717
}
1818

1919
apiValidation {

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
kotlin = "2.3.21"
2+
kotlin = "2.4.0"
33
kotlin-idea = "2.4.0-dev-2631"
44
kotlinx-coroutines = "1.10.1"
55
kotlinx-binary-compatibility-validator = "0.16.3"

kmp-nativecoroutines-compiler/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/compiler/fir/codegen/ValueParameters.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ internal fun FirExtension.buildValueParametersCopy(
4141
.let(substitutor::substituteOrSelf)
4242
.toFirResolvedTypeRef()
4343

44-
@OptIn(SymbolInternals::class)
45-
deprecationsProvider = parameter.fir.deprecationsProvider
46-
4744
// TODO: support defaultValue once exported to ObjC
4845

4946
annotations.addAll(buildAnnotationsCopy(parameter.resolvedAnnotationsWithClassIds))

kmp-nativecoroutines-compiler/src/test/generated/com/rickclephas/kmp/nativecoroutines/compiler/runners/ClassicDiagnosticsTestGenerated.java

Lines changed: 0 additions & 88 deletions
This file was deleted.

kmp-nativecoroutines-compiler/src/test/generated/com/rickclephas/kmp/nativecoroutines/compiler/runners/FirLightTreeCodegenTestGenerated.java

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
@TestMetadata("src/testData/codegen")
1717
@TestDataPath("$PROJECT_ROOT")
1818
public class FirLightTreeCodegenTestGenerated extends AbstractFirLightTreeCodegenTest {
19+
private void run(String fileName) {
20+
runTest("src/testData/codegen/" + fileName);
21+
}
22+
1923
@Test
2024
public void testAllFilesPresentInCodegen() {
2125
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("src/testData/codegen"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kt$"), true);
@@ -24,37 +28,41 @@ public void testAllFilesPresentInCodegen() {
2428
@Test
2529
@TestMetadata("annotations.kt")
2630
public void testAnnotations() {
27-
runTest("src/testData/codegen/annotations.kt");
31+
run("annotations.kt");
2832
}
2933

3034
@Test
3135
@TestMetadata("coroutinescope.kt")
3236
public void testCoroutinescope() {
33-
runTest("src/testData/codegen/coroutinescope.kt");
37+
run("coroutinescope.kt");
3438
}
3539

3640
@Test
3741
@TestMetadata("functions.kt")
3842
public void testFunctions() {
39-
runTest("src/testData/codegen/functions.kt");
43+
run("functions.kt");
4044
}
4145

4246
@Test
4347
@TestMetadata("properties.kt")
4448
public void testProperties() {
45-
runTest("src/testData/codegen/properties.kt");
49+
run("properties.kt");
4650
}
4751

4852
@Test
4953
@TestMetadata("viewmodelscope.kt")
5054
public void testViewmodelscope() {
51-
runTest("src/testData/codegen/viewmodelscope.kt");
55+
run("viewmodelscope.kt");
5256
}
5357

5458
@Nested
5559
@TestMetadata("src/testData/codegen/swift1")
5660
@TestDataPath("$PROJECT_ROOT")
5761
public class Swift1 {
62+
private void run(String fileName) {
63+
runTest("src/testData/codegen/swift1/" + fileName);
64+
}
65+
5866
@Test
5967
public void testAllFilesPresentInSwift1() {
6068
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("src/testData/codegen/swift1"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kt$"), true);
@@ -63,38 +71,42 @@ public void testAllFilesPresentInSwift1() {
6371
@Test
6472
@TestMetadata("annotations.kt")
6573
public void testAnnotations() {
66-
runTest("src/testData/codegen/swift1/annotations.kt");
74+
run("annotations.kt");
6775
}
6876

6977
@Test
7078
@TestMetadata("coroutinescope.kt")
7179
public void testCoroutinescope() {
72-
runTest("src/testData/codegen/swift1/coroutinescope.kt");
80+
run("coroutinescope.kt");
7381
}
7482

7583
@Test
7684
@TestMetadata("functions.kt")
7785
public void testFunctions() {
78-
runTest("src/testData/codegen/swift1/functions.kt");
86+
run("functions.kt");
7987
}
8088

8189
@Test
8290
@TestMetadata("properties.kt")
8391
public void testProperties() {
84-
runTest("src/testData/codegen/swift1/properties.kt");
92+
run("properties.kt");
8593
}
8694

8795
@Test
8896
@TestMetadata("viewmodelscope.kt")
8997
public void testViewmodelscope() {
90-
runTest("src/testData/codegen/swift1/viewmodelscope.kt");
98+
run("viewmodelscope.kt");
9199
}
92100
}
93101

94102
@Nested
95103
@TestMetadata("src/testData/codegen/swift3")
96104
@TestDataPath("$PROJECT_ROOT")
97105
public class Swift3 {
106+
private void run(String fileName) {
107+
runTest("src/testData/codegen/swift3/" + fileName);
108+
}
109+
98110
@Test
99111
public void testAllFilesPresentInSwift3() {
100112
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("src/testData/codegen/swift3"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kt$"), true);
@@ -103,38 +115,42 @@ public void testAllFilesPresentInSwift3() {
103115
@Test
104116
@TestMetadata("annotations.kt")
105117
public void testAnnotations() {
106-
runTest("src/testData/codegen/swift3/annotations.kt");
118+
run("annotations.kt");
107119
}
108120

109121
@Test
110122
@TestMetadata("coroutinescope.kt")
111123
public void testCoroutinescope() {
112-
runTest("src/testData/codegen/swift3/coroutinescope.kt");
124+
run("coroutinescope.kt");
113125
}
114126

115127
@Test
116128
@TestMetadata("functions.kt")
117129
public void testFunctions() {
118-
runTest("src/testData/codegen/swift3/functions.kt");
130+
run("functions.kt");
119131
}
120132

121133
@Test
122134
@TestMetadata("properties.kt")
123135
public void testProperties() {
124-
runTest("src/testData/codegen/swift3/properties.kt");
136+
run("properties.kt");
125137
}
126138

127139
@Test
128140
@TestMetadata("viewmodelscope.kt")
129141
public void testViewmodelscope() {
130-
runTest("src/testData/codegen/swift3/viewmodelscope.kt");
142+
run("viewmodelscope.kt");
131143
}
132144
}
133145

134146
@Nested
135147
@TestMetadata("src/testData/codegen/swift5")
136148
@TestDataPath("$PROJECT_ROOT")
137149
public class Swift5 {
150+
private void run(String fileName) {
151+
runTest("src/testData/codegen/swift5/" + fileName);
152+
}
153+
138154
@Test
139155
public void testAllFilesPresentInSwift5() {
140156
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("src/testData/codegen/swift5"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kt$"), true);
@@ -143,31 +159,31 @@ public void testAllFilesPresentInSwift5() {
143159
@Test
144160
@TestMetadata("annotations.kt")
145161
public void testAnnotations() {
146-
runTest("src/testData/codegen/swift5/annotations.kt");
162+
run("annotations.kt");
147163
}
148164

149165
@Test
150166
@TestMetadata("coroutinescope.kt")
151167
public void testCoroutinescope() {
152-
runTest("src/testData/codegen/swift5/coroutinescope.kt");
168+
run("coroutinescope.kt");
153169
}
154170

155171
@Test
156172
@TestMetadata("functions.kt")
157173
public void testFunctions() {
158-
runTest("src/testData/codegen/swift5/functions.kt");
174+
run("functions.kt");
159175
}
160176

161177
@Test
162178
@TestMetadata("properties.kt")
163179
public void testProperties() {
164-
runTest("src/testData/codegen/swift5/properties.kt");
180+
run("properties.kt");
165181
}
166182

167183
@Test
168184
@TestMetadata("viewmodelscope.kt")
169185
public void testViewmodelscope() {
170-
runTest("src/testData/codegen/swift5/viewmodelscope.kt");
186+
run("viewmodelscope.kt");
171187
}
172188
}
173189
}

0 commit comments

Comments
 (0)