535 lines
17 KiB
Plaintext
Raw Normal View History

2020-05-24 09:46:35 +02:00
/*
* Copyright 2019 Ugljesa Jovanovic
*
* 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
*
* http://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.
*
*/
@file:Suppress("UnstableApiUsage")
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
2020-10-19 20:10:04 +02:00
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
2021-01-05 10:46:43 +01:00
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2020-10-19 20:10:04 +02:00
import org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask
2020-05-24 09:46:35 +02:00
plugins {
kotlin(PluginsDeps.multiplatform)
2020-10-17 11:41:38 +02:00
id(PluginsDeps.kapt)
2020-10-19 20:10:04 +02:00
id(PluginsDeps.androidApplication)
id(PluginsDeps.kotlinAndroidExtensions)
2020-10-17 17:39:53 +02:00
id(PluginsDeps.mavenPublish)
id(PluginsDeps.signing)
2020-10-17 18:08:12 +02:00
kotlin(PluginsDeps.kotlinSerializationPlugin) version Versions.kotlinSerializationPlugin
2020-10-17 17:39:53 +02:00
2020-05-24 09:46:35 +02:00
}
2020-10-17 17:39:53 +02:00
org.jetbrains.kotlin.gradle.targets.js.npm.NpmResolverPlugin.apply(project)
2020-05-24 09:46:35 +02:00
val sonatypeStaging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
val sonatypeSnapshots = "https://oss.sonatype.org/content/repositories/snapshots/"
repositories {
mavenCentral()
jcenter()
2020-10-17 11:41:38 +02:00
maven("https://dl.bintray.com/terl/lazysodium-maven")
2020-10-19 22:22:33 +02:00
maven("https://oss.sonatype.org/content/repositories/snapshots/")
2020-05-24 09:46:35 +02:00
}
group = "com.ionspin.kotlin"
2020-10-17 11:41:38 +02:00
version = "0.1.0-SNAPSHOT"
2020-05-24 09:46:35 +02:00
val ideaActive = System.getProperty("idea.active") == "true"
kotlin {
val hostOsName = getHostOsName()
2020-10-23 14:15:21 +02:00
if (ideaActive) {
when (hostOsName) {
"linux" -> linuxX64("native")
"macos" -> macosX64("native")
"windows" -> mingwX64("native")
}
}
2020-10-19 20:10:04 +02:00
android()
runningOnLinuxx86_64 {
2020-05-24 09:46:35 +02:00
jvm()
js {
2020-05-24 11:12:00 +02:00
browser {
2020-10-17 17:39:53 +02:00
webpackTask {
}
2020-05-24 11:12:00 +02:00
testTask {
useKarma {
useChrome()
}
}
}
2020-05-24 09:46:35 +02:00
nodejs {
testTask {
useMocha() {
timeout = "10s"
}
}
}
2021-01-05 10:46:43 +01:00
// binaries.executable()
2020-05-24 09:46:35 +02:00
}
2020-10-17 11:41:38 +02:00
2020-05-24 09:46:35 +02:00
linuxX64("linux") {
binaries {
executable {
}
}
}
2020-10-19 20:10:04 +02:00
2020-10-23 14:15:21 +02:00
//Disable for now as libui doesnt support arm64
// linuxArm64() {
// binaries {
// executable {
// }
// }
// }
2020-05-24 09:46:35 +02:00
}
runningOnMacos {
2020-10-20 00:22:22 +02:00
val iosX64Target = iosX64() {
2020-10-20 00:23:59 +02:00
binaries {
framework {
baseName = "LibsodiumBindings"
export(Deps.Common.libsodiumBindings)
}
}
2020-10-20 00:22:22 +02:00
}
val iosArm64Target = iosArm64() {
2020-10-20 00:23:59 +02:00
binaries {
framework {
baseName = "LibsodiumBindings"
export(Deps.Common.libsodiumBindings)
}
}
2020-10-20 00:22:22 +02:00
}
val iosArm32Target = iosArm32() {
2020-10-20 00:23:59 +02:00
binaries {
framework {
baseName = "LibsodiumBindings"
export(Deps.Common.libsodiumBindings)
}
}
2020-10-20 00:22:22 +02:00
}
2020-10-19 20:10:04 +02:00
val macosX64Target = macosX64()
val tvosX64Target = tvosX64()
val tvosArm64Target = tvosArm64()
val watchosArm64Target = watchosArm64()
val watchosArm32Target = watchosArm32()
val watchosX86Target = watchosX86()
2020-10-19 20:59:49 +02:00
configure(listOf(macosX64Target)) {
binaries.executable {}
}
2020-10-20 00:24:57 +02:00
// configure(listOf(
// iosX64Target, iosArm64Target, iosArm32Target,
// tvosX64Target, tvosArm64Target, watchosArm64Target,
// watchosArm32Target, watchosX86Target)
// ) {
// binaries.framework {
// baseName = "LibsodiumBindings"
// export(Deps.Common.libsodiumBindings)
// }
// }
2020-10-19 20:10:04 +02:00
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
2020-10-19 20:59:49 +02:00
println("Mode $mode")
2020-10-19 20:10:04 +02:00
// Create a task to build a fat framework.
tasks.create("packForXcode", FatFrameworkTask::class) {
// The fat framework must have the same base name as the initial frameworks.
2020-10-19 23:01:03 +02:00
baseName = "LibsodiumBindings"
2020-10-19 20:10:04 +02:00
// The default destination directory is '<build directory>/fat-framework'.
destinationDir = File(buildDir, "xcode-frameworks")
// Specify the frameworks to be merged.
from(
iosX64Target.binaries.getFramework(mode),
iosArm64Target.binaries.getFramework(mode),
2020-10-19 20:59:49 +02:00
iosArm32Target.binaries.getFramework(mode)
2020-10-19 20:10:04 +02:00
)
2020-10-17 11:41:38 +02:00
}
2020-05-24 09:46:35 +02:00
}
runningOnWindows {
2020-05-24 09:46:35 +02:00
mingwX64() {
binaries {
executable {
2020-05-24 09:46:35 +02:00
}
}
}
}
println(targets.names)
2020-10-19 20:10:04 +02:00
2020-05-24 09:46:35 +02:00
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin(Deps.Common.stdLib))
implementation(kotlin(Deps.Common.test))
implementation(Deps.Common.kotlinBigNum)
2020-10-17 18:08:12 +02:00
implementation(Deps.Common.serialization)
2020-10-19 22:27:38 +02:00
api(Deps.Common.libsodiumBindings)
2020-05-24 09:46:35 +02:00
}
}
val commonTest by getting {
dependencies {
implementation(kotlin(Deps.Common.test))
implementation(kotlin(Deps.Common.testAnnotation))
}
}
2020-10-19 20:10:04 +02:00
val androidMain by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}")
implementation("androidx.appcompat:appcompat:1.2.0")
implementation("androidx.core:core-ktx:1.3.2")
implementation("androidx.constraintlayout:constraintlayout:2.0.2")
implementation("com.google.android.material:material:1.3.0-alpha03")
// implementation("androidx.ui:ui-tooling:$composeDevVersion")
// implementation("androidx.ui:ui-layout:$composeDevVersion")
// implementation("androidx.ui:ui-material:$composeDevVersion")
// implementation("androidx.ui:ui-foundation:$composeDevVersion")
// implementation("androidx.ui:ui-framework:$composeDevVersion")
implementation(Deps.Android.coroutines)
implementation(Deps.Android.timber)
// implementation("androidx.compose:compose-runtime:$composeDevVersion")
}
}
val androidTest by getting {
dependencies {
implementation(kotlin(Deps.Jvm.test))
implementation(kotlin(Deps.Jvm.testJUnit))
implementation(Deps.Jvm.coroutinesTest)
implementation(kotlin(Deps.Jvm.reflection))
implementation(Deps.Jvm.coroutinesCore)
}
}
2020-10-17 11:41:38 +02:00
2020-10-23 14:15:21 +02:00
// val nativeMain by creating {
// dependsOn(commonMain)
// dependencies {
// implementation(Deps.Desktop.libui)
// }
// }
//
// val nativeTest by creating {
// dependsOn(commonTest)
// dependencies {
// }
// }
val nativeMain = if (ideaActive) {
val nativeMain by getting {
dependsOn(commonMain)
dependencies {
implementation(Deps.Desktop.libui)
}
}
nativeMain
} else {
val nativeMain by creating {
dependsOn(commonMain)
dependencies {
implementation(Deps.Desktop.libui)
}
2020-05-24 09:46:35 +02:00
}
2020-10-23 14:15:21 +02:00
nativeMain
}
2020-10-23 14:15:21 +02:00
val nativeTest = if (ideaActive) {
val nativeTest by getting {
dependsOn(commonTest)
dependencies {
implementation(Deps.Native.coroutines)
}
2020-05-24 09:46:35 +02:00
}
2020-10-23 14:15:21 +02:00
nativeTest
} else {
val nativeTest by creating {
dependsOn(commonTest)
dependencies {
implementation(Deps.Native.coroutines)
}
}
nativeTest
2020-05-24 09:46:35 +02:00
}
runningOnLinuxx86_64 {
2020-05-24 09:46:35 +02:00
val jvmMain by getting {
dependencies {
implementation(kotlin(Deps.Jvm.stdLib))
implementation(kotlin(Deps.Jvm.test))
implementation(kotlin(Deps.Jvm.testJUnit))
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin(Deps.Jvm.test))
implementation(kotlin(Deps.Jvm.testJUnit))
implementation(kotlin(Deps.Jvm.reflection))
}
}
val jsMain by getting {
dependencies {
implementation(kotlin(Deps.Js.stdLib))
2020-10-17 17:39:53 +02:00
implementation(Deps.Js.coroutines)
2020-10-17 18:08:12 +02:00
2020-10-17 17:39:53 +02:00
// React
implementation(Deps.Js.React.react)
implementation(Deps.Js.React.reactDom)
implementation(npm(Deps.Js.Npm.reactPair.first, Deps.Js.Npm.reactPair.second))
implementation(npm(Deps.Js.Npm.reactDomPair.first, Deps.Js.Npm.reactDomPair.second))
// Styled
implementation(Deps.Js.React.styled)
implementation(npm(Deps.Js.Npm.styledComponentsPair.first, Deps.Js.Npm.styledComponentsPair.second))
implementation(npm(Deps.Js.Npm.inlineStylePrefixesPair.first, Deps.Js.Npm.inlineStylePrefixesPair.second))
2020-10-17 18:08:12 +02:00
2020-05-24 09:46:35 +02:00
}
}
val jsTest by getting {
dependencies {
implementation(kotlin(Deps.Js.test))
}
}
2020-05-24 09:46:35 +02:00
val linuxMain by getting {
dependsOn(nativeMain)
}
val linuxTest by getting {
dependsOn(nativeTest)
}
2020-10-17 18:08:12 +02:00
2020-10-23 14:15:21 +02:00
// val linuxArm64Main by getting {
// dependsOn(nativeMain)
// }
// val linuxArm64Test by getting {
// dependsOn(nativeTest)
// }
2020-05-24 09:46:35 +02:00
}
runningOnMacos {
2020-05-24 09:46:35 +02:00
2020-08-09 12:24:50 +02:00
val iosX64Main by getting {
dependsOn(nativeMain)
2020-05-24 09:46:35 +02:00
}
2020-08-09 12:24:50 +02:00
val iosX64Test by getting {
dependsOn(nativeTest)
2020-05-24 09:46:35 +02:00
}
val iosArm64Main by getting {
dependsOn(nativeMain)
2020-05-24 09:46:35 +02:00
}
val iosArm64Test by getting {
dependsOn(nativeTest)
2020-05-24 09:46:35 +02:00
}
val iosArm32Main by getting {
dependsOn(nativeMain)
2020-05-24 09:46:35 +02:00
}
val iosArm32Test by getting {
dependsOn(nativeTest)
2020-05-24 09:46:35 +02:00
}
val macosX64Main by getting {
dependsOn(nativeMain)
}
val macosX64Test by getting {
dependsOn(nativeTest)
}
}
runningOnWindows {
2020-05-24 09:46:35 +02:00
val mingwX64Main by getting {
dependsOn(commonMain)
}
val mingwX64Test by getting {
dependsOn(commonTest)
}
}
all {
languageSettings.enableLanguageFeature("InlineClasses")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")
2020-05-24 09:46:35 +02:00
}
}
}
2020-10-19 20:10:04 +02:00
android {
compileSdkVersion(29)
defaultConfig {
applicationId = "com.ionspin.kotlin.crypto.sample"
minSdkVersion(21)
targetSdkVersion(29)
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}
sourceSets {
val main by getting
main.manifest.srcFile("src/androidMain/AndroidManifest.xml")
main.java.srcDirs("src/androidMain/kotlin")
main.res.srcDirs("src/androidMain/res")
}
packagingOptions {
exclude("META-INF/library_release.kotlin_module")
exclude("META-INF/kotlinx-serialization-runtime.kotlin_module")
exclude("META-INF/ktor-http.kotlin_module")
exclude("META-INF/ktor-utils.kotlin_module")
exclude("META-INF/ktor-io.kotlin_module")
exclude("META-INF/ktor-*")
}
compileOptions {
setSourceCompatibility(JavaVersion.VERSION_1_8)
setTargetCompatibility(JavaVersion.VERSION_1_8)
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}
// buildFeatures {
// // Enables Jetpack Compose for this module
// this.compose = true
// }
2020-10-19 20:10:04 +02:00
// composeOptions {
// kotlinCompilerExtensionVersion = "0.1.0-dev05"
// }
2020-10-19 20:10:04 +02:00
// Magic for compose dev08, but it doesn't work with serialization plugin because of IR. Leave here for future reference.
// project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java)
// .configureEach {
// println("Task: $this")
// if (this.name.contains("Android")) {
// println("Setting plugins: $this")
// this.kotlinOptions.freeCompilerArgs += listOf(
// "-P",
// "plugin:androidx.compose.plugins.idea:enabled=true"
// )
// this.kotlinOptions.freeCompilerArgs += "-Xplugin=${project.rootDir}/compose-compiler-0.1.0-dev08.jar"
// this.kotlinOptions.freeCompilerArgs += "-Xuse-ir"
// }
2020-10-17 11:41:38 +02:00
// }
2020-10-19 20:10:04 +02:00
// project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java)
// .forEach { compile ->
// compile.kotlinOptions.freeCompilerArgs += listOf(
// "-P",
// "plugin:androidx.compose.plugins.idea:enabled=true"
// )
// compile.kotlinOptions.freeCompilerArgs += "-Xplugin=${project.rootDir}/compose-compiler-0.1.0-dev08.jar"
// compile.kotlinOptions.freeCompilerArgs += "-Xuse-ir"
// println("Compile: $compile")
// println("Compiler free args ${compile.kotlinOptions.freeCompilerArgs}")
// }
}
2020-10-17 11:41:38 +02:00
2020-05-24 09:46:35 +02:00
tasks {
if (getHostOsName() == "linux") {
val jvmTest by getting(Test::class) {
testLogging {
events("PASSED", "FAILED", "SKIPPED")
}
}
val linuxTest by getting(KotlinNativeTest::class) {
testLogging {
events("PASSED", "FAILED", "SKIPPED")
2021-01-05 10:46:43 +01:00
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = true
showStackTraces = true
2020-05-24 09:46:35 +02:00
}
}
val jsNodeTest by getting(KotlinJsTest::class) {
testLogging {
events("PASSED", "FAILED", "SKIPPED")
showStandardStreams = true
}
}
}
if (getHostOsName() == "windows") {
val mingwX64Test by getting(KotlinNativeTest::class) {
testLogging {
events("PASSED", "FAILED", "SKIPPED")
showStandardStreams = true
}
}
}
}
2020-10-17 17:39:53 +02:00
fun org.jetbrains.kotlin.gradle.plugin.mpp.Executable.windowsResources(rcFileName: String) {
val taskName = linkTaskName.replaceFirst("link", "windres")
val inFile = compilation.defaultSourceSet.resources.sourceDirectories.singleFile.resolve(rcFileName)
val outFile = buildDir.resolve("processedResources/$taskName.res")
val windresTask = tasks.create<Exec>(taskName) {
val konanUserDir = System.getenv("KONAN_DATA_DIR") ?: "${System.getProperty("user.home")}/.konan"
val konanLlvmDir = "$konanUserDir/dependencies/msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1/bin"
inputs.file(inFile)
outputs.file(outFile)
commandLine("$konanLlvmDir/windres", inFile, "-D_${buildType.name}", "-O", "coff", "-o", outFile)
environment("PATH", "$konanLlvmDir;${System.getenv("PATH")}")
dependsOn(compilation.compileKotlinTask)
}
linkTask.dependsOn(windresTask)
linkerOpts(outFile.toString())
}
2020-05-24 09:46:35 +02:00
2020-10-19 20:59:49 +02:00
2020-05-24 09:46:35 +02:00