Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5fc1b55
kn: configure targets (#53)
lauzadis Oct 29, 2024
2293711
misc: enable using `kn-main` in CI (#55)
lauzadis Nov 7, 2024
2ba27e5
kn: enable checking out submodules recursively (#56)
lauzadis Nov 18, 2024
0cb72d8
kn: add `submodules` to inputs (#57)
lauzadis Nov 18, 2024
492ec38
Fix step description
lauzadis Nov 18, 2024
c6fdc8e
Merge branch 'main' of github.com:awslabs/aws-kotlin-repo-tools into …
lauzadis Dec 12, 2024
26013a8
Add `disableCrossCompileTargets` util function
lauzadis Dec 13, 2024
4395e9d
Merge branch 'main' of github.com:awslabs/aws-kotlin-repo-tools into …
lauzadis Jan 21, 2025
f712e53
kn: commonize iOS simulator configuration (#63)
lauzadis Jan 31, 2025
ab34ff6
Check error code 405 in boot tasks
lauzadis Feb 3, 2025
7a07412
kn: Create iOS simulator boot and shutdown tasks in root project (#64)
lauzadis Feb 4, 2025
586ce30
misc: merge from main
aws-sdk-kotlin-ci Mar 11, 2025
02d4a9f
misc: merge from main
aws-sdk-kotlin-ci Mar 11, 2025
f08d5ad
misc: merge from main
aws-sdk-kotlin-ci Mar 18, 2025
791c4d6
misc: merge from main
aws-sdk-kotlin-ci Mar 18, 2025
40954d0
Remove K/N targets from `ALLOWED_PUBLICATIONS`
lauzadis Mar 18, 2025
07c11e4
Revert back to 1.1.+
lauzadis Mar 18, 2025
a0e3e17
misc: prepare to merge `kn-main` back into `main` (#78)
lauzadis Mar 18, 2025
9df2b1a
Only use kn-main if the ref has a `kn-` prefix
lauzadis Mar 18, 2025
7b5ba87
Merge branch 'kn-main-merge' into kn-main
lauzadis Mar 18, 2025
11393d3
Revert Publish.kt changes
lauzadis Mar 18, 2025
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
12 changes: 10 additions & 2 deletions .github/actions/checkout-head/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ inputs:
commands. The post-job step removes the PAT.
default: ${{ github.token }}
required: false
submodules:
description: >
Whether to checkout submodules. `true` to checkout submodules or `recursive` to recursively checkout submodules
default: 'false'
required: 'false'

runs:
using: composite
Expand All @@ -44,7 +49,9 @@ runs:
echo "ref=$ref" >> "$GITHUB_OUTPUT"
else
baseref="main"
if [ -n "$GITHUB_BASE_REF" ]; then
if [[ "$ref" == kn-* ]] && git ls-remote --exit-code --heads "https://github.com/$REPOSITORY.git" "kn-main"; then
baseref="kn-main"
elif [ -n "$GITHUB_BASE_REF" ]; then
echo "attempting GH base ref: $GITHUB_BASE_REF"
if git ls-remote --exit-code --heads "https://github.com/$REPOSITORY.git" "$GITHUB_BASE_REF"; then
baseref="$GITHUB_BASE_REF"
Expand All @@ -60,4 +67,5 @@ runs:
path: ${{ inputs.path }}
repository: ${{ inputs.repository }}
ref: ${{ steps.repo.outputs.ref }}
token: ${{ inputs.token }}
token: ${{ inputs.token }}
submodules: ${{ inputs.submodules }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.sdk.kotlin.gradle.kmp

import org.gradle.api.Project
import org.gradle.api.tasks.Exec
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest
import org.jetbrains.kotlin.konan.target.HostManager

/**
* Disables standalone mode in simulator tests since it causes issues with TLS.
* This means we need to manage the simulator state ourselves (booting, shutting down).
* https://youtrack.jetbrains.com/issue/KT-38317
*/
public fun Project.configureIosSimulatorTasks() {
if (!HostManager.hostIsMac) return

val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: "iPhone 15"
val xcrun = "/usr/bin/xcrun"

val bootTask = rootProject.tasks.maybeCreate("bootIosSimulatorDevice", Exec::class.java).apply {
isIgnoreExitValue = true
commandLine(xcrun, "simctl", "boot", simulatorDeviceName)

doLast {
val result = executionResult.get()
val code = result.exitValue
if (code != 148 && code != 149) { // ignore "simulator already running" errors
result.assertNormalExitValue()
}
}
}

val shutdownTask = rootProject.tasks.maybeCreate("shutdownIosSimulatorDevice", Exec::class.java).apply {
isIgnoreExitValue = true
commandLine(xcrun, "simctl", "shutdown", simulatorDeviceName)

doLast {
val result = executionResult.get()
val code = result.exitValue
if (code != 148 && code != 149) { // ignore "simulator already shutdown" errors
result.assertNormalExitValue()
}
}
}

allprojects {
val simulatorTasks = tasks.withType<KotlinNativeSimulatorTest>()
simulatorTasks.configureEach {
dependsOn(bootTask)
standalone.set(false)
device.set(simulatorDeviceName)
}
shutdownTask.mustRunAfter(simulatorTasks)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
*/
package aws.sdk.kotlin.gradle.kmp

import aws.sdk.kotlin.gradle.util.prop
import org.gradle.api.Project
import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven
import org.gradle.api.publish.tasks.GenerateModuleMetadata
import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.konan.target.Family
import org.jetbrains.kotlin.konan.target.HostManager
import java.io.File

internal fun <T> Project.tryGetClass(className: String): Class<T>? {
Expand Down Expand Up @@ -45,7 +51,7 @@ val Project.hasWindows: Boolean get() = hasNative || files.any { it.name == "win
* Test if a project follows the convention and needs configured for KMP (used in handful of spots where we have a
* subproject that is just a container for other projects but isn't a KMP project itself).
*/
public val Project.needsKmpConfigured: Boolean get() = hasCommon || hasJvm || hasNative || hasJs
public val Project.needsKmpConfigured: Boolean get() = hasCommon || hasJvm || hasNative || hasJs || hasJvmAndNative || hasDesktop || hasLinux || hasApple || hasWindows

@OptIn(ExperimentalKotlinGradlePluginApi::class)
fun Project.configureKmpTargets() {
Expand All @@ -64,7 +70,8 @@ fun Project.configureKmpTargets() {
return@withPlugin
}

// configure the target hierarchy, this does not actually enable the targets, just their relationships
// extend the default KMP target hierarchy
// this does not actually enable the targets, just their relationships
// see https://kotlinlang.org/docs/multiplatform-hierarchy.html#see-the-full-hierarchy-template
kmpExt.applyDefaultHierarchyTemplate {
if (hasJvmAndNative) {
Expand Down Expand Up @@ -95,24 +102,32 @@ fun Project.configureKmpTargets() {
}
}

// enable targets
// enable the targets
configureCommon()

if (hasJvm && JVM_ENABLED) {
configureJvm()
}

// FIXME Configure JS
// FIXME Configure Apple
// FIXME Configure Windows

withIf(hasLinux && NATIVE_ENABLED, kmpExt) {
configureLinux()
}

withIf(hasDesktop && NATIVE_ENABLED, kmpExt) {
configureLinux()
// FIXME Configure desktop
if (NATIVE_ENABLED) {
if (hasApple) {
kmpExt.apply { configureApple() }
}
if (hasWindows) {
kmpExt.apply { configureWindows() }
}
if (hasLinux) {
kmpExt.apply { configureLinux() }
}
if (hasDesktop) {
kmpExt.apply {
configureLinux()
configureMacos()
configureWindows()
}
}
}

kmpExt.configureSourceSetsConvention()
Expand Down Expand Up @@ -155,14 +170,31 @@ fun Project.configureJvm() {

fun Project.configureLinux() {
kotlin {
linuxX64 {
// FIXME enable tests once the target is fully implemented
tasks.named("linuxX64Test") {
enabled = false
}
}
// FIXME - Okio missing arm64 target support
// linuxArm64()
linuxX64()
linuxArm64() // FIXME - Okio missing arm64 target support
}
}

fun Project.configureApple() {
kotlin {
configureMacos()
iosSimulatorArm64()
iosArm64()
iosX64()
}
}

fun Project.configureMacos() {
kotlin {
macosX64()
macosArm64()
}
}

fun Project.configureWindows() {
kotlin {
// FIXME Set up Docker files and CMake tasks for Windows
// mingwX64()
}
}

Expand All @@ -179,8 +211,62 @@ fun KotlinMultiplatformExtension.configureSourceSetsConvention() {
}
}

internal inline fun <T> withIf(condition: Boolean, receiver: T, block: T.() -> Unit) {
if (condition) {
receiver.block()
val Project.JVM_ENABLED get() = prop("aws.kotlin.jvm")?.let { it == "true" } ?: true
val Project.NATIVE_ENABLED get() = prop("aws.kotlin.native")?.let { it == "true" } ?: true

/**
* Kotlin/Native Linux and Windows targets are generally enabled on all hosts since
* the Kotlin toolchain and backend compilers support cross compilation. We
* are using cinterop and have to compile CRT for those platforms which sometimes
* requires using docker which isn't always available in CI or setup in users environment.
*
* See [KT-30498](https://youtrack.jetbrains.com/issue/KT-30498)
*/
fun Project.disableCrossCompileTargets() {
plugins.withId("org.jetbrains.kotlin.multiplatform") {
configure<KotlinMultiplatformExtension> {
targets.withType<KotlinNativeTarget> {
val knTarget = this
when {
HostManager.hostIsMac && (knTarget.isLinux || knTarget.isWindows) -> disable(knTarget)
HostManager.hostIsLinux && knTarget.isApple -> disable(knTarget)
HostManager.hostIsMingw && (knTarget.isLinux || knTarget.isApple) -> disable(knTarget)
}
}
}
}
}

private val KotlinNativeTarget.isLinux: Boolean
get() = konanTarget.family == Family.LINUX

private val KotlinNativeTarget.isApple: Boolean
get() = konanTarget.family.isAppleFamily

private val KotlinNativeTarget.isWindows: Boolean
get() = konanTarget.family == Family.MINGW

internal fun Project.disable(knTarget: KotlinNativeTarget) {
logger.warn("disabling Kotlin/Native target: ${knTarget.name}")
knTarget.apply {
compilations.all {
cinterops.all {
tasks.named(interopProcessingTaskName).configure { enabled = false }
}
compileTaskProvider.configure { enabled = false }
}

binaries.all {
linkTaskProvider.configure { enabled = false }
}

mavenPublication {
tasks.withType<AbstractPublishToMaven>().configureEach {
onlyIf { publication != this@mavenPublication }
}
tasks.withType<GenerateModuleMetadata>().configureEach {
onlyIf { publication != this@mavenPublication }
}
}
}
}

This file was deleted.