delegated module build.gradle cleanp and macos build fix

This commit is contained in:
Ugljesa Jovanovic 2020-05-30 22:47:01 +02:00 committed by Ugljesa Jovanovic
parent 137fe3fe62
commit bb58a372e7
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
6 changed files with 144 additions and 74 deletions

View File

@ -21,5 +21,11 @@ plugins {
}
repositories {
mavenCentral()
maven ("https://dl.bintray.com/kotlin/kotlin-eap")
jcenter()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M1")
}

View File

@ -27,7 +27,7 @@ object Versions {
}
object Published {
object ReleaseInfo {
val group = "com.ionspin.kotlin"
val version = "0.0.5-SNAPSHOT"
}

View File

@ -0,0 +1,63 @@
import org.gradle.api.NamedDomainObjectContainer
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 30-May-2020
*/
fun isInIdea() = System.getProperty("idea.active") == "true"
fun isInTravis() = System.getenv("TRAVIS") == "true"
fun getHostOsName(): String {
val target = System.getProperty("os.name")
if (target == "Linux") return "linux"
if (target.startsWith("Windows")) return "windows"
if (target.startsWith("Mac")) return "macos"
return "unknown"
}
fun KotlinMultiplatformExtension.isRunningInIdea(block : KotlinMultiplatformExtension.() -> Unit) {
if (isInIdea()) {
block(this)
}
}
fun KotlinMultiplatformExtension.runningOnLinux(block : KotlinMultiplatformExtension.() -> Unit) {
if (getHostOsName() == "linux") {
block(this)
}
}
fun KotlinMultiplatformExtension.runningOnMacos(block : KotlinMultiplatformExtension.() -> Unit) {
if (getHostOsName() == "macos") {
block(this)
}
}
fun KotlinMultiplatformExtension.runningOnWindows(block : KotlinMultiplatformExtension.() -> Unit) {
if (getHostOsName() == "windows") {
block(this)
}
}
fun independentDependencyBlock(nativeDeps : KotlinDependencyHandler.() -> Unit) : KotlinDependencyHandler.() -> Unit {
return nativeDeps
}
/**
* On mac when two targets that have the same parent source set have cinterops defined, gradle creates a "common"
* target task for that source set metadata, even though it's a native source set, to work around that, we create
* an intermediary source set with the same set of dependancies
*/
fun NamedDomainObjectContainer<KotlinSourceSet>.createWorkaroundNativeMainSourceSet(name : String, nativeDeps : KotlinDependencyHandler.() -> Unit) : KotlinSourceSet {
return create("${name}Workaround") {
kotlin.srcDir("src/nativeMain/kotlin")
dependencies {
nativeDeps.invoke(this)
}
}
}

View File

@ -33,8 +33,8 @@ repositories {
jcenter()
}
group = Published.group
version = Published.version
group = ReleaseInfo.group
version = ReleaseInfo.version
val ideaActive = System.getProperty("idea.active") == "true"

View File

@ -45,22 +45,17 @@ repositories {
jcenter()
}
group = Published.group
version = Published.version
group = ReleaseInfo.group
version = ReleaseInfo.version
val ideaActive = isInIdea()
println("Idea active: $ideaActive")
val ideaActive = System.getProperty("idea.active") == "true"
fun getHostOsName(): String {
val target = System.getProperty("os.name")
if (target == "Linux") return "linux"
if (target.startsWith("Windows")) return "windows"
if (target.startsWith("Mac")) return "macos"
return "unknown"
}
kotlin {
val hostOsName = getHostOsName()
if (hostOsName == "linux") {
runningOnLinux {
jvm()
js {
browser {
@ -103,29 +98,29 @@ kotlin {
}
if (hostOsName == "macos") {
// iosX64("ios") {
// binaries {
// framework {
// optimized = true
// }
// }
// }
// iosArm64("ios64Arm") {
// binaries {
// framework {
// optimized = true
// }
// }
// }
//
// iosArm32("ios32Arm") {
// binaries {
// framework {
// optimized = true
// }
// }
// }
runningOnMacos {
iosX64("ios") {
binaries {
framework {
optimized = true
}
}
}
iosArm64("ios64Arm") {
binaries {
framework {
optimized = true
}
}
}
iosArm32("ios32Arm") {
binaries {
framework {
optimized = true
}
}
}
macosX64() {
binaries {
framework {
@ -133,8 +128,22 @@ kotlin {
}
}
}
tvos() {
binaries {
framework {
optimized = true
}
}
}
watchos() {
binaries {
framework {
optimized = true
}
}
}
}
if (hostOsName == "windows") {
runningOnWindows {
mingwX64() {
binaries {
@ -173,14 +182,17 @@ kotlin {
}
}
val nativeDependencies = independentDependencyBlock {
implementation(Deps.Native.coroutines)
}
val nativeMain by creating {
dependsOn(commonMain)
dependencies {
implementation(Deps.Native.coroutines)
nativeDependencies(this)
}
}
val nativeTest by creating {
dependsOn(commonTest)
dependencies {
@ -188,13 +200,13 @@ kotlin {
}
}
targets.withType<KotlinNativeTarget> {
println("Target $name")
compilations.getByName("main") {
defaultSourceSet.dependsOn(nativeMain)
if (this@withType.name.contains("ios").not()) {
println("Setting cinterop for $this@withType.name")
defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies))
println("Setting cinterop for $this")
val libsodiumCinterop by cinterops.creating {
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
compilerOpts.add("-I${project.rootDir}/sodiumWrapper/include/")
@ -203,13 +215,24 @@ kotlin {
"-include-binary", "${project.rootDir}/sodiumWrapper/lib/libsodium.a"
)
}
if (this@withType.name.contains("ios")) {
defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies))
println("Setting ios cinterop for $this")
val libsodiumCinterop by cinterops.creating {
defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
compilerOpts.add("-I${project.rootDir}/sodiumWrapper/libsodium-ios/include/")
}
kotlinOptions.freeCompilerArgs = listOf(
"-include-binary", "${project.rootDir}/sodiumWrapper/libsodium-ios/lib/libsodium.a"
)
}
}
compilations.getByName("test") {
if (this@withType.name.contains("ios").not()) {
println("Setting native test dep for $this@withType.name")
defaultSourceSet.dependsOn(nativeTest)
}
println("Setting native test dep for $this@withType.name")
defaultSourceSet.dependsOn(nativeTest)
}
}
@ -251,14 +274,14 @@ kotlin {
}
val linuxMain by getting {
dependsOn(nativeMain)
if (ideaActive) {
isRunningInIdea {
kotlin.srcDir("src/nativeMain/kotlin")
}
//
}
val linuxTest by getting {
dependsOn(nativeTest)
if (ideaActive) {
isRunningInIdea {
kotlin.srcDir("src/nativeTest/kotlin")
}
//
@ -287,28 +310,6 @@ kotlin {
}
if (hostOsName == "macos") {
// val iosMain by getting {
//// dependsOn(nativeMain)
// }
// val iosTest by getting {
//// dependsOn(nativeTest)
// }
//
// val ios64ArmMain by getting {
//// dependsOn(nativeMain)
// }
// val ios64ArmTest by getting {
//// dependsOn(nativeTest)
// }
//
// val ios32ArmMain by getting {
//// dependsOn(nativeMain)
// }
// val ios32ArmTest by getting {
//// dependsOn(nativeTest)
// }
val macosX64Main by getting {
dependsOn(nativeMain)
if (ideaActive) {

View File

@ -42,8 +42,8 @@ repositories {
jcenter()
}
group = Published.group
version = Published.version
group = ReleaseInfo.group
version = ReleaseInfo.version
val ideaActive = System.getProperty("idea.active") == "true"