-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* mpp, library and test configuration in convention plugin * targets configuration using shortcuts in place * add ability to run tests with both release and debug native binaries * setup js jarn lock store
- Loading branch information
olme04
committed
Jan 12, 2022
1 parent
f777ace
commit efac91d
Showing
20 changed files
with
2,188 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import org.gradle.api.* | ||
import org.jetbrains.kotlin.gradle.dsl.* | ||
import org.jetbrains.kotlin.gradle.plugin.* | ||
|
||
class TargetBuilder internal constructor( | ||
private val sourceSets: NamedDomainObjectContainer<KotlinSourceSet>, | ||
private val name: String | ||
) { | ||
fun main(block: KotlinSourceSet.() -> Unit) { | ||
sourceSets.getByName("${name}Main").block() | ||
} | ||
|
||
fun test(block: KotlinSourceSet.() -> Unit) { | ||
sourceSets.getByName("${name}Test").block() | ||
} | ||
} | ||
|
||
fun KotlinMultiplatformExtension.configureCommon(block: TargetBuilder.() -> Unit) { | ||
TargetBuilder(sourceSets, "common").block() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import org.jetbrains.kotlin.gradle.plugin.* | ||
|
||
//TODO may be remove part of annotations | ||
fun LanguageSettingsBuilder.optInForTest() { | ||
optIn("kotlin.time.ExperimentalTime") | ||
optIn("kotlin.ExperimentalStdlibApi") | ||
|
||
optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") | ||
optIn("kotlinx.coroutines.InternalCoroutinesApi") | ||
optIn("kotlinx.coroutines.ObsoleteCoroutinesApi") | ||
optIn("kotlinx.coroutines.FlowPreview") | ||
optIn("kotlinx.coroutines.DelicateCoroutinesApi") | ||
|
||
optIn("io.ktor.util.InternalAPI") | ||
optIn("io.ktor.utils.io.core.internal.DangerousInternalIoApi") | ||
|
||
optIn("io.rsocket.kotlin.TransportApi") | ||
optIn("io.rsocket.kotlin.ExperimentalMetadataApi") | ||
optIn("io.rsocket.kotlin.ExperimentalStreamsApi") | ||
optIn("io.rsocket.kotlin.RSocketLoggingApi") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import org.gradle.api.* | ||
import org.jetbrains.kotlin.gradle.dsl.* | ||
|
||
fun Project.kotlin(configure: Action<KotlinMultiplatformExtension>): Unit = extensions.configure("kotlin", configure) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
org.jetbrains.kotlin.multiplatform | ||
`kotlinx-atomicfu` | ||
} | ||
|
||
kotlin { | ||
sourceSets.all { | ||
languageSettings { | ||
progressiveMode = true | ||
|
||
optIn("kotlin.RequiresOptIn") | ||
|
||
//TODO: kludge, this is needed now, | ||
// as ktor isn't fully supports kotlin 1.5.3x opt-in changes | ||
// will be not needed after ktor 2.0.0 | ||
optIn("io.ktor.utils.io.core.ExperimentalIoApi") | ||
|
||
if (name.contains("test", ignoreCase = true)) optInForTest() | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
buildSrc/src/main/kotlin/rsocket.template.library.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
plugins { | ||
id("rsocket.multiplatform") | ||
id("rsocket.publication") | ||
} | ||
|
||
kotlin { | ||
explicitApi() | ||
|
||
sourceSets { | ||
commonTest { | ||
dependencies { | ||
implementation(project(":rsocket-test")) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import org.gradle.api.* | ||
import org.jetbrains.kotlin.gradle.dsl.* | ||
import org.jetbrains.kotlin.gradle.targets.js.yarn.* | ||
import java.io.* | ||
|
||
enum class JsTarget( | ||
val supportBrowser: Boolean, | ||
val supportNodejs: Boolean | ||
) { | ||
Browser(true, false), | ||
Nodejs(false, true), | ||
Both(true, true) | ||
} | ||
|
||
fun KotlinMultiplatformExtension.configureJs( | ||
jsTarget: JsTarget = JsTarget.Both, | ||
block: TargetBuilder.() -> Unit = {} | ||
) { | ||
js { | ||
useCommonJs() | ||
|
||
//configure running tests for JS | ||
if (jsTarget.supportBrowser) browser { | ||
testTask { | ||
useKarma { | ||
useConfigDirectory(project.jsDir("karma.config.d")) | ||
useChromeHeadless() | ||
} | ||
} | ||
} | ||
if (jsTarget.supportNodejs) nodejs { | ||
testTask { | ||
useMocha { | ||
timeout = "600s" | ||
} | ||
} | ||
} | ||
} | ||
TargetBuilder(sourceSets, "js").block() | ||
} | ||
|
||
//should be called only in root project | ||
fun Project.configureYarn() { | ||
yarn.lockFileDirectory = project.jsDir("yarn") | ||
} | ||
|
||
private fun Project.jsDir(folder: String): File = rootDir.resolve("gradle").resolve("js").resolve(folder) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import org.jetbrains.kotlin.gradle.dsl.* | ||
|
||
fun KotlinMultiplatformExtension.configureJvm(block: TargetBuilder.() -> Unit = {}) { | ||
jvm { | ||
testRuns.all { | ||
executionTask.configure { | ||
// ActiveProcessorCount is used here, to make sure local setup is similar as on CI | ||
// Github Actions linux runners have 2 cores | ||
jvmArgs("-Xmx4g", "-XX:ActiveProcessorCount=2") | ||
} | ||
} | ||
} | ||
TargetBuilder(sourceSets, "jvm").block() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import org.gradle.kotlin.dsl.* | ||
import org.jetbrains.kotlin.gradle.dsl.* | ||
import org.jetbrains.kotlin.gradle.plugin.mpp.* | ||
|
||
enum class NativeTargets { | ||
Posix, | ||
Nix, | ||
Darwin | ||
} | ||
|
||
fun KotlinMultiplatformExtension.configureNative( | ||
nativeTargets: NativeTargets = NativeTargets.Posix, | ||
block: TargetBuilder.() -> Unit = {} | ||
) { | ||
val nativeMain by sourceSets.creating { | ||
dependsOn(sourceSets["commonMain"]) | ||
} | ||
val nativeTest by sourceSets.creating { | ||
dependsOn(sourceSets["commonTest"]) | ||
} | ||
|
||
when (nativeTargets) { | ||
NativeTargets.Posix -> posixTargets() | ||
NativeTargets.Nix -> nixTargets() | ||
NativeTargets.Darwin -> darwinTargets() | ||
}.forEach { | ||
sourceSets["${it.name}Main"].dependsOn(nativeMain) | ||
sourceSets["${it.name}Test"].dependsOn(nativeTest) | ||
} | ||
|
||
targets.all { | ||
//add another test task with release binary | ||
if (this is KotlinNativeTargetWithTests<*>) { | ||
binaries.test(listOf(NativeBuildType.RELEASE)) | ||
val releaseTest by testRuns.creating { | ||
setExecutionSourceFrom(binaries.getTest(NativeBuildType.RELEASE)) | ||
} | ||
} | ||
} | ||
|
||
TargetBuilder(sourceSets, "native").block() | ||
} | ||
|
||
private fun KotlinMultiplatformExtension.darwinTargets(): List<KotlinNativeTarget> { | ||
val macosTargets = listOf(macosX64(), macosArm64()) | ||
val iosTargets = listOf(iosArm32(), iosArm64(), iosX64(), iosSimulatorArm64()) | ||
val tvosTargets = listOf(tvosArm64(), tvosX64(), tvosSimulatorArm64()) | ||
val watchosTargets = listOf(watchosArm32(), watchosArm64(), watchosX86(), watchosX64(), watchosSimulatorArm64()) | ||
return macosTargets + iosTargets + tvosTargets + watchosTargets | ||
} | ||
|
||
//ktor network supports only jvm and nix targets, but not mingw | ||
private fun KotlinMultiplatformExtension.nixTargets(): List<KotlinNativeTarget> { | ||
return darwinTargets() + linuxX64() | ||
} | ||
|
||
//rsocket core and local transport supports all native targets, that are supported by ktor-io and kotlinx-coroutines | ||
private fun KotlinMultiplatformExtension.posixTargets(): List<KotlinNativeTarget> { | ||
return nixTargets() + mingwX64() | ||
} |
File renamed without changes.
Oops, something went wrong.