Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native targets #579

Merged
merged 13 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 65 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,65 @@ name: Pipeline

on: [push, pull_request]

env:
GRADLE_OPTS: "-Dorg.gradle.internal.launcher.welcomeMessageEnabled=false"

concurrency:
cancel-in-progress: true
group: build-${{ github.event.pull_request.number || github.event.after }}
charleskorn marked this conversation as resolved.
Show resolved Hide resolved

jobs:
build:
name: "Build, Test and Publish"
runs-on: ubuntu-latest
test-matrix:
OptimumCode marked this conversation as resolved.
Show resolved Hide resolved
strategy:
matrix:
include:
- os: ubuntu-latest
tasks: check
- os: windows-latest
tasks: mingwX64Test
- os: macos-13
tasks: macosX64Test iosX64Test
- os: macos-latest
tasks: macosArm64Test iosSimulatorArm64Test
runs-on: ${{ matrix.os }}
name: Test on ${{ matrix.os }}
steps:
- name: Check out code
uses: actions/[email protected]
with:
fetch-depth: 0

- name: Validate Gradle wrapper
uses: gradle/actions/[email protected]

- name: Set up JDK
uses: actions/[email protected]
with:
java-version: 17
distribution: temurin

- name: Setup Gradle
uses: gradle/actions/[email protected]

- name: Cache konan dependencies
uses: actions/cache@v4
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Build
run: ./gradlew ${{ matrix.tasks }}

publish:
name: "Build and Publish"
needs:
- test-matrix
runs-on: macos-latest
env:
TERM: xterm-256color
GPG_KEY_ID: 6D76AD03 # Run `gpg -K` to get this, take last eight characters
GRADLE_OPTS: "-Dorg.gradle.internal.launcher.welcomeMessageEnabled=false"

permissions:
contents: write # Required to be able to publish releases, see https://docs.github.com/en/rest/reference/permissions-required-for-github-apps#permission-on-contents
Expand All @@ -21,7 +72,7 @@ jobs:
fetch-depth: 0

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v3.4.2
uses: gradle/actions/[email protected]

- name: Set up JDK
uses: actions/[email protected]
Expand All @@ -30,14 +81,19 @@ jobs:
distribution: temurin

- name: Setup Gradle
uses: gradle/[email protected]
uses: gradle/actions/[email protected]

- name: Cache konan dependencies
uses: actions/cache@v4
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-${{ hashFiles('*.gradle.kts') }}
restore-keys: |
${{ runner.os }}-gradle-

- name: Build
run: ./gradlew assemble

- name: Check
run: ./gradlew check

- name: Assemble release
run: ./gradlew assembleRelease
env:
Expand Down
15 changes: 15 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ kotlin {
nodejs()
}

// According to https://kotlinlang.org/docs/native-target-support.html
// Tier 1
macosX64()
macosArm64()
iosSimulatorArm64()
iosX64()

// Tier 2
linuxX64()
linuxArm64()
iosArm64()

// Tier 3
mingwX64()

sourceSets {
commonMain {
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.register

private val TARGETS_WITH_JAR_TASK = setOf("jvm", "js", "wasmJs")

fun Project.configureAssemble() {
tasks.register<Copy>("assembleRelease") {
description = "Prepares files for release."
Expand All @@ -33,7 +35,9 @@ fun Project.configureAssemble() {
project.extensions.getByType<PublishingExtension>().publications.names
.filter { it != "kotlinMultiplatform" }
.forEach { publicationName ->
from(tasks.named("${publicationName}Jar"))
if (publicationName in TARGETS_WITH_JAR_TASK) {
from(tasks.named("${publicationName}Jar"))
}
from(tasks.named("${publicationName}JavadocJar"))
from(tasks.named("${publicationName}SourcesJar"))

Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
kotlin.code.style=official
kotlin.daemon.jvmargs=-Xmx1g
org.gradle.jvmargs=-Xmx1g
8 changes: 8 additions & 0 deletions src/commonMain/kotlin/com/charleskorn/kaml/YamlNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public data class YamlScalar(val content: String, override val path: YamlPath) :
content.toFloat()
} catch (e: NumberFormatException) {
throw YamlScalarFormatException("Value '$content' is not a valid floating point value.", path, content)
} catch (e: IndexOutOfBoundsException) {
// Workaround for https://youtrack.jetbrains.com/issue/KT-69327
// TODO: remove once it is fixed
throw YamlScalarFormatException("Value '$content' is not a valid floating point value.", path, content)
}
}
}
Expand All @@ -77,6 +81,10 @@ public data class YamlScalar(val content: String, override val path: YamlPath) :
content.toDouble()
} catch (e: NumberFormatException) {
throw YamlScalarFormatException("Value '$content' is not a valid floating point value.", path, content)
} catch (e: IndexOutOfBoundsException) {
// Workaround for https://youtrack.jetbrains.com/issue/KT-69327
// TODO: remove once it is fixed
throw YamlScalarFormatException("Value '$content' is not a valid floating point value.", path, content)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/commonTest/kotlin/com/charleskorn/kaml/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum class KotlinTarget {
JVM,
JS,
WASM,
NATIVE,
}

expect val kotlinTarget: KotlinTarget
27 changes: 19 additions & 8 deletions src/commonTest/kotlin/com/charleskorn/kaml/YamlScalarTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import io.kotest.assertions.asClue
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.common.Platform
import io.kotest.common.platform
import io.kotest.core.test.Enabled
import io.kotest.core.test.Enabled.Companion.disabled
import io.kotest.core.test.Enabled.Companion.enabled
import io.kotest.core.test.EnabledOrReasonIf
import io.kotest.matchers.doubles.shouldBeNaN
import io.kotest.matchers.floats.shouldBeNaN
Expand Down Expand Up @@ -247,11 +248,21 @@ class YamlScalarTest : FlatFunSpec({
"",
).forEach { content ->

val ignoreValidFloatingPointsForJs: EnabledOrReasonIf = {
if (platform == Platform.JS && content in setOf("0x2", "0o2")) {
Enabled.disabled("$content is a valid floating value for JS due to dynamic cast")
} else {
Enabled.enabled
val floatingPointTestCondition: EnabledOrReasonIf = {
when (platform) {
Platform.Native ->
if (content == "1e-") {
disabled("floating point parser bug: https://youtrack.jetbrains.com/issue/KT-69327")
} else {
enabled
}
Platform.JS ->
if (content in setOf("0x2", "0o2")) {
disabled("$content is a valid floating value for JS due to dynamic cast")
} else {
enabled
}
else -> enabled
}
}

Expand All @@ -261,7 +272,7 @@ class YamlScalarTest : FlatFunSpec({

context("retrieving the value as a float") {
test("throws an appropriate exception")
.config(enabledOrReasonIf = ignoreValidFloatingPointsForJs) {
.config(enabledOrReasonIf = floatingPointTestCondition) {
val exception = shouldThrow<YamlScalarFormatException> { scalar.toFloat() }

exception.asClue {
Expand All @@ -276,7 +287,7 @@ class YamlScalarTest : FlatFunSpec({

context("retrieving the value as a double") {
test("throws an appropriate exception")
.config(enabledOrReasonIf = ignoreValidFloatingPointsForJs) {
.config(enabledOrReasonIf = floatingPointTestCondition) {
val exception = shouldThrow<YamlScalarFormatException> { scalar.toDouble() }

exception.asClue {
Expand Down
21 changes: 21 additions & 0 deletions src/nativeTest/kotlin/com/charleskorn/kaml/TestUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*

Copyright 2018-2023 Charles Korn.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

package com.charleskorn.kaml

actual val kotlinTarget: KotlinTarget = KotlinTarget.NATIVE