Skip to content

Commit

Permalink
add native targets
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny-chung committed Mar 12, 2024
1 parent 438fd8b commit 129f7ae
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
![watchOS](https://img.shields.io/badge/watchOS-blue)
![tvOS](https://img.shields.io/badge/tvOS-blue)

A Kotlin Multiplatform library to provide **regular date-time functionality needed with very minimal platform dependencies**. It means upgrading OS / platform SDK target versions or moving to another platform would not break your application. Same and consistent core API set is provided to all JVM, Apple, JS targets.
A Kotlin Multiplatform library to provide **regular date-time functionality needed with very minimal platform dependencies**. It means upgrading OS / platform SDK target versions or moving to another platform would not break your application. Same and consistent core API set is provided to all JVM, Apple, JS and native targets.

Comparing with the kotlinx one, this library additionally provides formatting and parsing from custom formatted string. As it has extremely few dependencies, it is very lightweight. The sum of all the artifacts among all the platforms, including source jars and javadocs, is less than 700 KB.

Expand Down
25 changes: 15 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ kotlin {
}
}
}
// val hostOs = System.getProperty("os.name")
// val isMingwX64 = hostOs.startsWith("Windows")
// val nativeTarget = when {
// hostOs == "Mac OS X" -> macosX64("native")
// hostOs == "Linux" -> linuxX64("native")
// isMingwX64 -> mingwX64("native")
// else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
// }
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" -> null // macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> {
println("Warning: Host OS is not supported in Kotlin/Native.")
null
}
}


sourceSets {
Expand Down Expand Up @@ -156,8 +159,10 @@ kotlin {
}
val jsMain by getting
val jsTest by getting
// val nativeMain by getting
// val nativeTest by getting
if (nativeTarget != null) {
val nativeMain by getting
val nativeTest by getting
}

configure(darwinTargets) {
val (mainSourceSet, testSourceSet) = when {
Expand Down
19 changes: 18 additions & 1 deletion doc/docs/Getting Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ In build.gradle.kts, add the dependency.
// ...
```

### Use in Swift / Objective-C
### Use in Swift / Objective-C (Optional)

Add a transitive export to the `framework` DSL in build.gradle.kts:
```kotlin
Expand All @@ -43,3 +43,20 @@ import shared
```

Note the framework base name `shared` is customizable.

## For Native Targets

Only macOS native target was built and published to Maven Central. For other OS targets (Linux and Windows), they are also supported, but you would have to clone the source code and build manually. It is not difficult.

In the target OS,

1. Grab a JDK with version 17 or above
2. `git clone` source code
3. Execute `./gradlew clean publishToMavenLocal`
4. In your project, add:
```kotlin
repositories {
mavenLocal()
// ...
}
```
2 changes: 1 addition & 1 deletion doc/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ title: Home
![watchOS](https://img.shields.io/badge/watchOS-blue)
![tvOS](https://img.shields.io/badge/tvOS-blue)

KDateTime is a Kotlin Multiplatform library to provide **regular date-time functionality needed with very minimal platform dependencies**. It means upgrading OS / platform SDK target versions or moving to another platform would not break your application. Same and consistent core API set is provided to all JVM, Apple, JS targets.
KDateTime is a Kotlin Multiplatform library to provide **regular date-time functionality needed with very minimal platform dependencies**. It means upgrading OS / platform SDK target versions or moving to another platform would not break your application. Same and consistent core API set is provided to all JVM, Apple, JS and native targets.

Comparing with the kotlinx one, this library additionally provides formatting and parsing from custom formatted string. As it has extremely few dependencies, it is very lightweight. The sum of all the artifacts among all the platforms, including source jars and javadocs, is less than 700 KB.

Expand Down

0 comments on commit 129f7ae

Please sign in to comment.