diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 084729b..c434ef1 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -21,5 +21,11 @@ plugins { } repositories { + mavenCentral() + maven ("https://dl.bintray.com/kotlin/kotlin-eap") jcenter() -} \ No newline at end of file +} + +dependencies { + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M1") +} diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index dc6c1aa..7484c89 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -27,7 +27,7 @@ object Versions { } -object Published { +object ReleaseInfo { val group = "com.ionspin.kotlin" val version = "0.0.5-SNAPSHOT" } diff --git a/buildSrc/src/main/kotlin/Utils.kt b/buildSrc/src/main/kotlin/Utils.kt new file mode 100644 index 0000000..4f1caea --- /dev/null +++ b/buildSrc/src/main/kotlin/Utils.kt @@ -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.createWorkaroundNativeMainSourceSet(name : String, nativeDeps : KotlinDependencyHandler.() -> Unit) : KotlinSourceSet { + return create("${name}Workaround") { + kotlin.srcDir("src/nativeMain/kotlin") + dependencies { + nativeDeps.invoke(this) + } + } + +} \ No newline at end of file diff --git a/multiplatform-crypto-api/build.gradle.kts b/multiplatform-crypto-api/build.gradle.kts index ad90709..5606ecf 100644 --- a/multiplatform-crypto-api/build.gradle.kts +++ b/multiplatform-crypto-api/build.gradle.kts @@ -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" diff --git a/multiplatform-crypto-delegated/build.gradle.kts b/multiplatform-crypto-delegated/build.gradle.kts index 9360d88..e59eab4 100644 --- a/multiplatform-crypto-delegated/build.gradle.kts +++ b/multiplatform-crypto-delegated/build.gradle.kts @@ -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 { 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) { diff --git a/multiplatform-crypto/build.gradle.kts b/multiplatform-crypto/build.gradle.kts index e8fab31..7cc57af 100644 --- a/multiplatform-crypto/build.gradle.kts +++ b/multiplatform-crypto/build.gradle.kts @@ -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"