@@ -74,7 +74,9 @@ kotlin {
74
74
}
75
75
}
76
76
// Tier 3
77
- target(" mingwX64" )
77
+ common(" windows" ) {
78
+ target(" mingwX64" )
79
+ }
78
80
}
79
81
80
82
jvm {
@@ -143,24 +145,11 @@ kotlin {
143
145
when {
144
146
konanTarget.family == org.jetbrains.kotlin.konan.target.Family .MINGW -> {
145
147
compilations[" main" ].cinterops {
146
- create(" date" ) {
147
- val cinteropDir = " $projectDir /native/cinterop"
148
- val dateLibDir = " ${project(" :" ).projectDir} /thirdparty/date"
149
- headers(" $cinteropDir /public/cdate.h" )
150
- defFile(" native/cinterop/date.def" )
151
- extraOpts(" -Xsource-compiler-option" , " -I$cinteropDir /public" )
152
- extraOpts(" -Xsource-compiler-option" , " -DONLY_C_LOCALE=1" )
153
- // needed to be able to use std::shared_mutex to implement caching.
154
- extraOpts(" -Xsource-compiler-option" , " -std=c++17" )
155
- // the date library headers, needed for some pure calculations.
156
- extraOpts(" -Xsource-compiler-option" , " -I$dateLibDir /include" )
157
- // the main source for the platform bindings.
158
- extraOpts(" -Xcompile-source" , " $cinteropDir /cpp/windows.cpp" )
148
+ create(" declarations" ) {
149
+ defFile(" $projectDir /windows/cinterop/definitions.def" )
150
+ headers(" $projectDir /windows/cinterop/definitions.h" )
159
151
}
160
152
}
161
- compilations[" main" ].defaultSourceSet {
162
- kotlin.srcDir(" native/cinterop_actuals" )
163
- }
164
153
}
165
154
konanTarget.family == org.jetbrains.kotlin.konan.target.Family .LINUX -> {
166
155
// do nothing special
@@ -173,8 +162,6 @@ kotlin {
173
162
}
174
163
}
175
164
}
176
-
177
-
178
165
sourceSets {
179
166
commonMain {
180
167
dependencies {
@@ -321,10 +308,10 @@ tasks {
321
308
322
309
val downloadWindowsZonesMapping by tasks.registering {
323
310
description = " Updates the mapping between Windows-specific and usual names for timezones"
324
- val output = " $projectDir /native/cinterop/public/windows_zones.hpp"
325
- val initialFileContents = File (output).readBytes()
311
+ val output = " $projectDir /windows/src/WindowsZoneNames.kt"
326
312
outputs.file(output)
327
313
doLast {
314
+ val initialFileContents = try { File (output).readBytes() } catch (e: Throwable ) { ByteArray (0 ) }
328
315
val documentBuilderFactory = DocumentBuilderFactory .newInstance()
329
316
// otherwise, parsing fails since it can't find the dtd
330
317
documentBuilderFactory.setFeature(" http://apache.org/xml/features/nonvalidating/load-external-dtd" , false )
@@ -336,11 +323,13 @@ val downloadWindowsZonesMapping by tasks.registering {
336
323
xmlDoc.documentElement.normalize()
337
324
val mapZones = xmlDoc.getElementsByTagName(" mapZone" )
338
325
val mapping = linkedMapOf<String , String >()
326
+ mapping[" UTC" ] = " UTC"
339
327
for (i in 0 until mapZones.length) {
340
328
val mapZone = mapZones.item(i)
341
329
val windowsName = mapZone.attributes.getNamedItem(" other" ).nodeValue
342
330
val usualNames = mapZone.attributes.getNamedItem(" type" ).nodeValue
343
331
for (usualName in usualNames.split(' ' )) {
332
+ if (usualName == " " ) continue
344
333
val oldWindowsName = mapping[usualName] // don't do it in `put` to preserve the order in the map
345
334
if (oldWindowsName == null ) {
346
335
mapping[usualName] = windowsName
@@ -353,31 +342,23 @@ val downloadWindowsZonesMapping by tasks.registering {
353
342
val bos = ByteArrayOutputStream ()
354
343
PrintWriter (bos).use { out ->
355
344
out .println (""" // generated with gradle task `$name `""" )
356
- out .println (""" #include <unordered_map>""" )
357
- out .println (""" #include <string>""" )
358
- out .println (""" static const std::unordered_map<std::string, std::string> standard_to_windows = {""" )
345
+ out .println (""" package kotlinx.datetime""" )
346
+ out .println (""" internal val standardToWindows: Map<String, String> = mutableMapOf(""" )
359
347
for ((usualName, windowsName) in sortedMapping) {
360
- out .println (" \t { \" $usualName \" , \" $windowsName \" } ," )
348
+ out .println (" \" $usualName \" to \" $windowsName \" ," )
361
349
}
362
- out .println (" }; " )
363
- out .println (""" static const std::unordered_map<std::string, std::string> windows_to_standard = { """ )
350
+ out .println (" ) " )
351
+ out .println (""" internal val windowsToStandard: Map<String, String> = mutableMapOf( """ )
364
352
val reverseMap = sortedMapOf<String , String >()
365
353
for ((usualName, windowsName) in mapping) {
366
354
if (reverseMap[windowsName] == null ) {
367
355
reverseMap[windowsName] = usualName
368
356
}
369
357
}
370
358
for ((windowsName, usualName) in reverseMap) {
371
- out .println (" \t { \" $windowsName \" , \" $usualName \" }," )
372
- }
373
- out .println (" };" )
374
- out .println (""" static const std::unordered_map<std::string, size_t> zone_ids = {""" )
375
- var i = 0
376
- for ((usualName, windowsName) in sortedMapping) {
377
- out .println (" \t { \" $usualName \" , $i }," )
378
- ++ i
359
+ out .println (" \" $windowsName \" to \" $usualName \" ," )
379
360
}
380
- out .println (" }; " )
361
+ out .println (" ) " )
381
362
}
382
363
val newFileContents = bos.toByteArray()
383
364
if (! (initialFileContents contentEquals newFileContents)) {
0 commit comments