Skip to content

Commit 4ddfc91

Browse files
qwwdfsadelizarov
authored andcommitted
Kotlin/Native support
* Using Gradle 4.7 * Using Kotlin/Native 0.9-dev-2922 Fixes #246
1 parent 5f73827 commit 4ddfc91

36 files changed

+1551
-92
lines changed

build.gradle

+5-2
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,13 @@ def internal = sourceless + ['benchmarks', 'knit', 'js-stub', 'binary-compatibil
101101

102102
// Reconfigure source sets to avoid long "src/main/kotlin/fqn"
103103
configure(subprojects.findAll { !it.name.contains(sourceless) && it.name != "benchmarks" }) {
104+
def projectName = it.name
104105
sourceSets {
105106
main.kotlin.srcDirs = ['src']
106107
test.kotlin.srcDirs = ['test']
107-
main.resources.srcDirs = ['resources']
108+
if (!projectName.endsWith("-native")) {
109+
main.resources.srcDirs = ['resources']
110+
}
108111
}
109112
}
110113

@@ -135,7 +138,7 @@ configure(subprojects.findAll { !internal.contains(it.name) && it.name != 'kotli
135138
// --------------- Configure sub-projects that are published ---------------
136139

137140
// todo: native is not published yet
138-
def unpublished = internal + ['kotlinx-coroutines-rx-example', 'example-frontend-js', 'kotlinx-coroutines-core-native']
141+
def unpublished = internal + ['kotlinx-coroutines-rx-example', 'example-frontend-js']
139142

140143
def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/"
141144
def core_docs_file = "$projectDir/core/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"

common/kotlinx-coroutines-core-common/src/channels/ConflatedChannel.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
package kotlinx.coroutines.experimental.channels
66

7-
import kotlinx.coroutines.experimental.selects.ALREADY_SELECTED
8-
import kotlinx.coroutines.experimental.selects.SelectInstance
7+
import kotlinx.coroutines.experimental.selects.*
98

109
/**
1110
* Channel that buffers at most one element and conflates all subsequent `send` and `offer` invocations,
@@ -43,6 +42,7 @@ public open class ConflatedChannel<E> : AbstractChannel<E>() {
4342
when (sendResult) {
4443
null -> return OFFER_SUCCESS
4544
is Closed<*> -> return sendResult
45+
else -> Unit // todo:KLUDGE: works around native BE bug
4646
}
4747
// otherwise there was receiver in queue, retry super.offerInternal
4848
}

common/kotlinx-coroutines-core-common/src/channels/LinkedListChannel.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
package kotlinx.coroutines.experimental.channels
66

7-
import kotlinx.coroutines.experimental.selects.ALREADY_SELECTED
8-
import kotlinx.coroutines.experimental.selects.SelectInstance
7+
import kotlinx.coroutines.experimental.selects.*
98

109
/**
1110
* Channel with linked-list buffer of a unlimited capacity (limited only by available memory).
@@ -32,6 +31,7 @@ public open class LinkedListChannel<E> : AbstractChannel<E>() {
3231
when (sendResult) {
3332
null -> return OFFER_SUCCESS
3433
is Closed<*> -> return sendResult
34+
else -> Unit // todo:KLUDGE: works around native BE bug
3535
}
3636
// otherwise there was receiver in queue, retry super.offerInternal
3737
}

common/kotlinx-coroutines-core-common/test/channels/ChannelsTest.kt

+10-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package kotlinx.coroutines.experimental.channels
66

77
import kotlinx.coroutines.experimental.*
8+
import kotlin.coroutines.experimental.*
89
import kotlin.math.*
910
import kotlin.test.*
1011

@@ -132,7 +133,7 @@ class ChannelsTest: TestBase() {
132133

133134
@Test
134135
fun testMapToSendChannel() = runTest {
135-
val c = produce<Int> {
136+
val c = produce<Int>(coroutineContext) {
136137
testList.asReceiveChannel().mapTo(channel) { it + 10 }
137138
}
138139
assertEquals(testList.map { it + 10 }, c.toList())
@@ -327,7 +328,7 @@ class ChannelsTest: TestBase() {
327328
@Test
328329
fun testFilterToSendChannel() = runTest {
329330
repeat(3) { mod ->
330-
val c = produce<Int> {
331+
val c = produce<Int>(coroutineContext) {
331332
testList.asReceiveChannel().filterTo(channel) { it % 2 == mod }
332333
}
333334
assertEquals(testList.filter { it % 2 == mod }, c.toList())
@@ -354,7 +355,7 @@ class ChannelsTest: TestBase() {
354355
@Test
355356
fun testFilterNotToSendChannel() = runTest {
356357
repeat(3) { mod ->
357-
val c = produce<Int> {
358+
val c = produce<Int>(coroutineContext) {
358359
testList.asReceiveChannel().filterNotTo(channel) { it % 2 == mod }
359360
}
360361
assertEquals(testList.filterNot { it % 2 == mod }, c.toList())
@@ -381,7 +382,7 @@ class ChannelsTest: TestBase() {
381382
@Test
382383
fun testFilterNotNullToSendChannel() = runTest {
383384
repeat(3) { mod ->
384-
val c = produce<Int> {
385+
val c = produce<Int>(coroutineContext) {
385386
testList.asReceiveChannel().map { it.takeIf { it % 2 == mod } }.filterNotNullTo(channel)
386387
}
387388
assertEquals(testList.map { it.takeIf { it % 2 == mod } }.filterNotNull(), c.toList())
@@ -408,7 +409,7 @@ class ChannelsTest: TestBase() {
408409
@Test
409410
fun testFilterIndexedToChannel() = runTest {
410411
repeat(3) { mod ->
411-
val c = produce<Int> {
412+
val c = produce<Int>(coroutineContext) {
412413
testList.asReceiveChannel().filterIndexedTo(channel) { index, _ -> index % 2 == mod }
413414
}
414415
assertEquals(testList.filterIndexed { index, _ -> index % 2 == mod }, c.toList())
@@ -425,7 +426,7 @@ class ChannelsTest: TestBase() {
425426

426427
@Test
427428
fun testToChannel() = runTest {
428-
val c = produce<Int> {
429+
val c = produce<Int>(coroutineContext) {
429430
testList.asReceiveChannel().toChannel(channel)
430431
}
431432
assertEquals(testList, c.toList())
@@ -446,7 +447,7 @@ class ChannelsTest: TestBase() {
446447

447448
@Test
448449
fun testMapIndexedToSendChannel() = runTest {
449-
val c = produce<Int> {
450+
val c = produce<Int>(coroutineContext) {
450451
testList.asReceiveChannel().mapIndexedTo(channel) { index, i -> index + i }
451452
}
452453
assertEquals(testList.mapIndexed { index, i -> index + i }, c.toList())
@@ -472,7 +473,7 @@ class ChannelsTest: TestBase() {
472473
@Test
473474
fun testMapNotNullToSendChannel() = runTest {
474475
repeat(3) { mod ->
475-
val c = produce<Int> {
476+
val c = produce<Int>(coroutineContext) {
476477
testList.asReceiveChannel().mapNotNullTo(channel) { i -> i.takeIf { i % 2 == mod } }
477478
}
478479
assertEquals(testList.mapNotNull { i -> i.takeIf { i % 2 == mod } }, c.toList())
@@ -499,7 +500,7 @@ class ChannelsTest: TestBase() {
499500
@Test
500501
fun testMapIndexedNotNullToSendChannel() = runTest {
501502
repeat(3) { mod ->
502-
val c = produce<Int> {
503+
val c = produce<Int>(coroutineContext) {
503504
testList.asReceiveChannel().mapIndexedNotNullTo(channel) { index, i -> index.takeIf { i % 2 == mod } }
504505
}
505506
assertEquals(testList.mapIndexedNotNull { index, i -> index.takeIf { i % 2 == mod } }, c.toList())

common/kotlinx-coroutines-core-common/test/sync/MutexTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
package kotlinx.coroutines.experimental.sync
66

77
import kotlinx.coroutines.experimental.*
8-
import kotlin.test.*
98
import kotlin.coroutines.experimental.*
9+
import kotlin.test.*
1010

1111
class MutexTest : TestBase() {
1212
@Test
@@ -87,7 +87,7 @@ class MutexTest : TestBase() {
8787

8888
// owner firstOwner
8989
mutex.lock(firstOwner)
90-
val secondLockJob = launch {
90+
val secondLockJob = launch(coroutineContext) {
9191
mutex.lock(secondOwner)
9292
}
9393

core/kotlinx-coroutines-core/src/internal/ArrayCopy.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
package kotlinx.coroutines.experimental.internal
66

7-
internal actual fun <E> arraycopy(source: Array<E>, srcPos: Int, destination: Array<E?>, destinationStart: Int, length: Int){
7+
internal actual fun <E> arraycopy(
8+
source: Array<E>,
9+
srcPos: Int,
10+
destination: Array<E?>,
11+
destinationStart: Int,
12+
length: Int
13+
) {
814
System.arraycopy(source, srcPos, destination, destinationStart, length)
915
}

core/kotlinx-coroutines-core/src/internal/Concurrent.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package kotlinx.coroutines.experimental.internal
77
import java.util.concurrent.*
88
import kotlin.concurrent.withLock as withLockJvm
99

10-
internal actual fun <E> subscriberList(): MutableList<E> = CopyOnWriteArrayList<E>()
10+
internal actual fun <E> subscriberList(): SubscribersList<E> = CopyOnWriteArrayList<E>()
1111

1212
@Suppress("ACTUAL_WITHOUT_EXPECT")
1313
internal actual typealias ReentrantLock = java.util.concurrent.locks.ReentrantLock

gradle.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ version = 0.23.4-SNAPSHOT
66
group = org.jetbrains.kotlinx
77

88
kotlin_version = 1.2.51
9-
kotlin_native_version = 0.7-dev-1436
9+
kotlin_native_version = 0.9-dev-2922
1010
junit_version = 4.12
11-
atomicFU_version = 0.10.3
11+
atomicFU_version = 0.11.0
1212
html_version = 0.6.8
1313
lincheck_version=1.9
1414
dokka_version = 0.9.16-rdev-2-mpp-hacks
15-
bintray_version = 1.7.3
15+
bintray_version = 1.8.2-SNAPSHOT
1616

1717
gradle_node_version = 1.2.0
1818
node_version = 8.9.3

gradle/atomicfu-native.gradle

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
// todo: this does not work in Kotlin/Native
6-
7-
//dependencies {
8-
// compile "org.jetbrains.kotlinx:atomicfu-native:$atomicFU_version"
9-
//}
5+
dependencies {
6+
implementation "org.jetbrains.kotlinx:atomicfu-native:$atomicFU_version"
7+
}

gradle/compile-native.gradle

+19-24
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,30 @@
22
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
apply plugin: 'konan'
5+
apply plugin: "kotlin-platform-native"
66

7-
def libraryName = project.name
8-
def testProgramName = libraryName + "-test"
7+
apply from: project.rootProject.file('gradle/maven-central.gradle')
98

10-
konanArtifacts {
11-
library(libraryName, targets: ["ios_arm64", "ios_x64", "macos_x64"]) {
12-
artifactName libraryName.replace('-', '_')
13-
enableMultiplatform true
14-
dependencies {
15-
"artifact$libraryName" "org.jetbrains.kotlinx:atomicfu-native:$atomicFU_version"
16-
}
17-
}
18-
// TODO: THIS IS A WORKAROUND: Cannot do tests together with publishing in Kotlin/Native
19-
if (!rootProject.properties["publish"]) {
20-
program(testProgramName, targets: ["macos_x64"]) {
21-
srcDir 'src/test/kotlin'
22-
commonSourceSet 'test'
23-
libraries {
24-
artifact libraryName
9+
sourceSets {
10+
main {
11+
component {
12+
target "ios_arm64", "ios_arm32", "ios_x64", "macos_x64", "linux_x64", "mingw_x64"
13+
outputKinds = [KLIBRARY]
14+
pom {
15+
withXml(configureMavenCentralMetadata)
2516
}
26-
extraOpts '-tr'
2717
}
2818
}
2919
}
3020

31-
task test(dependsOn: run)
32-
33-
// TODO: THIS IS A WORKAROUND: Cannot do tests together with publishing in Kotlin/Native
34-
if (rootProject.properties["publish"]) {
35-
publishToMavenLocal.dependsOn(build)
21+
dependencies {
22+
expectedBy project(':kotlinx-coroutines-core-common')
3623
}
24+
25+
if (project.hasProperty("teamcity")) {
26+
afterEvaluate {
27+
runTestDebug {
28+
args '--ktest_logger=TEAMCITY'
29+
}
30+
}
31+
}

gradle/maven-central.gradle

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
// --------------- pom configuration ---------------
6+
7+
def pomConfig = {
8+
licenses {
9+
license {
10+
name "The Apache Software License, Version 2.0"
11+
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
12+
distribution "repo"
13+
}
14+
}
15+
developers {
16+
developer {
17+
id "JetBrains"
18+
name "JetBrains Team"
19+
organization "JetBrains"
20+
organizationUrl "http://www.jetbrains.com"
21+
}
22+
}
23+
24+
scm {
25+
url "https://github.com/Kotlin/kotlinx.coroutines"
26+
}
27+
}
28+
29+
project.ext.configureMavenCentralMetadata = {
30+
def root = it.asNode()
31+
// NOTE: Don't try to move top-level things (especially "description") to the pomConfig block
32+
// because they would resolve incorrectly to top-level project properties in Gradle/Groovy
33+
root.appendNode('name', project.name)
34+
root.appendNode('description', 'Coroutines support libraries for Kotlin')
35+
root.appendNode('url', 'https://github.com/Kotlin/kotlinx.coroutines')
36+
root.children().last() + pomConfig
37+
}

gradle/node-js.gradle

+9
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,12 @@ task populateNodeModules(type: Copy, dependsOn: [compileKotlin2Js]) {
4343
}
4444

4545
npmInstall.dependsOn populateNodeModules
46+
47+
// Workaround the problem with Node downloading
48+
repositories.whenObjectAdded {
49+
if (it instanceof IvyArtifactRepository) {
50+
metadataSources {
51+
artifact()
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)