Skip to content

Commit 3e21cc3

Browse files
committed
Enable HMPP, declare missing cinterop externals
Since nativeMain sourceSet is now compiled individually, it cannot find declarations provided by cinterop. Declare them as expect and call external declarations in actuals in each native platform. Move external declarations to kotlinx.datetime.internal package.
1 parent 4135cab commit 3e21cc3

File tree

5 files changed

+57
-11
lines changed

5 files changed

+57
-11
lines changed

core/build.gradle.kts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ kotlin {
8686
// }
8787
}
8888

89+
sourceSets.all {
90+
kotlin.setSrcDirs(listOf("$name/src"))
91+
resources.setSrcDirs(listOf("$name/resources"))
92+
languageSettings.apply {
93+
// progressiveMode = true
94+
useExperimentalAnnotation("kotlin.Experimental")
95+
}
96+
}
97+
8998
targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
9099
compilations["main"].cinterops {
91100
create("date") {
@@ -108,19 +117,14 @@ kotlin {
108117
extraOpts("-Xcompile-source", "$cinteropDir/cpp/windows.cpp")
109118
}
110119
}
120+
compilations["main"].defaultSourceSet {
121+
kotlin.srcDir("nativeMain/cinterop_actuals")
122+
}
111123
compilations["test"].kotlinOptions {
112124
freeCompilerArgs += listOf("-trw")
113125
}
114126
}
115127

116-
sourceSets.all {
117-
kotlin.setSrcDirs(listOf("$name/src"))
118-
resources.setSrcDirs(listOf("$name/resources"))
119-
languageSettings.apply {
120-
// progressiveMode = true
121-
useExperimentalAnnotation("kotlin.Experimental")
122-
}
123-
}
124128

125129
sourceSets {
126130
commonMain {
@@ -177,10 +181,19 @@ kotlin {
177181
}
178182

179183
val nativeMain by getting {
184+
dependsOn(commonMain.get())
180185
}
181186

182187
val nativeTest by getting {
183188
}
189+
190+
// val mingwX64Main by getting {
191+
// kotlin.srcDir("nativeMain/cinterop_actuals")
192+
// }
193+
//
194+
// val linuxX64Main by getting {
195+
// kotlin.srcDir("nativeMain/cinterop_actuals")
196+
// }
184197
}
185198
}
186199

core/nativeMain/cinterop/date.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package = kotlinx.datetime
1+
package = kotlinx.datetime.internal
22

33
# requirements of the `date` library: https://howardhinnant.github.io/date/tz.html#Installation
44
linkerOpts.mingw_x64 = -lole32
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2019-2020 JetBrains s.r.o.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
package kotlinx.datetime
6+
7+
internal actual fun available_zone_ids(): kotlinx.cinterop.CPointer<kotlinx.cinterop.CPointerVar<kotlinx.cinterop.ByteVar>>? =
8+
kotlinx.datetime.internal.available_zone_ids()
9+
10+
internal actual fun get_system_timezone(id: kotlinx.cinterop.CValuesRef<kotlinx.datetime.TZIDVar /* = kotlinx.cinterop.ULongVarOf<kotlin.ULong> */>?): kotlinx.cinterop.CPointer<kotlinx.cinterop.ByteVar /* = kotlinx.cinterop.ByteVarOf<kotlin.Byte> */>? =
11+
kotlinx.datetime.internal.get_system_timezone(id)
12+
13+
internal actual fun offset_at_datetime(zone: kotlinx.datetime.TZID /* = kotlin.ULong */, epoch_sec: platform.posix.int64_t /* = kotlin.Long */, offset: kotlinx.cinterop.CValuesRef<kotlinx.cinterop.IntVar /* = kotlinx.cinterop.IntVarOf<kotlin.Int> */>?): kotlin.Int =
14+
kotlinx.datetime.internal.offset_at_datetime(zone, epoch_sec, offset)
15+
16+
internal actual fun offset_at_instant(zone: kotlinx.datetime.TZID /* = kotlin.ULong */, epoch_sec: platform.posix.int64_t /* = kotlin.Long */): kotlin.Int =
17+
kotlinx.datetime.internal.offset_at_instant(zone, epoch_sec)
18+
19+
internal actual fun timezone_by_name(zone_name: kotlin.String?): kotlinx.datetime.TZID /* = kotlin.ULong */ =
20+
kotlinx.datetime.internal.timezone_by_name(zone_name)
21+
22+
internal actual val TZID_INVALID: TZID
23+
get() = kotlinx.datetime.internal.TZID_INVALID

core/nativeMain/src/TimeZone.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ import kotlinx.cinterop.*
1313
import platform.posix.*
1414
import kotlin.native.concurrent.*
1515

16+
17+
internal typealias TZIDVar = kotlinx.cinterop.ULongVarOf<kotlinx.datetime.TZID>
18+
internal typealias TZID = platform.posix.size_t
19+
internal expect val TZID_INVALID: TZID
20+
internal expect fun available_zone_ids(): kotlinx.cinterop.CPointer<kotlinx.cinterop.CPointerVar<kotlinx.cinterop.ByteVar>>?
21+
internal expect fun get_system_timezone(id: kotlinx.cinterop.CValuesRef<kotlinx.datetime.TZIDVar /* = kotlinx.cinterop.ULongVarOf<kotlin.ULong> */>?): kotlinx.cinterop.CPointer<kotlinx.cinterop.ByteVar /* = kotlinx.cinterop.ByteVarOf<kotlin.Byte> */>?
22+
internal expect fun offset_at_datetime(zone: kotlinx.datetime.TZID /* = kotlin.ULong */, epoch_sec: platform.posix.int64_t /* = kotlin.Long */, offset: kotlinx.cinterop.CValuesRef<kotlinx.cinterop.IntVar /* = kotlinx.cinterop.IntVarOf<kotlin.Int> */>?): kotlin.Int
23+
internal expect fun offset_at_instant(zone: kotlinx.datetime.TZID /* = kotlin.ULong */, epoch_sec: platform.posix.int64_t /* = kotlin.Long */): kotlin.Int
24+
internal expect fun timezone_by_name(zone_name: kotlin.String?): kotlinx.datetime.TZID /* = kotlin.ULong */
25+
1626
public actual open class TimeZone internal constructor(private val tzid: TZID, actual val id: String) {
1727

1828
actual companion object {

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ group=org.jetbrains.kotlinx
22
version=0.0.1
33
versionSuffix=SNAPSHOT
44

5-
#kotlin.mpp.enableGranularSourceSetsMetadata=true
6-
#kotlin.mpp.enableCompatibilityMetadataVariant=true
5+
kotlin.mpp.enableGranularSourceSetsMetadata=true
6+
kotlin.mpp.enableCompatibilityMetadataVariant=true
77

88
# Workaround for Bintray treating .sha512 files as artifacts
99
# https://github.com/gradle/gradle/issues/11412

0 commit comments

Comments
 (0)