├── .gitignore ├── .gitmodules ├── README.md ├── binaries └── build.gradle.kts ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ ├── Xtras.kt │ └── xtrasPom.kt ├── common ├── README.md ├── build.gradle.kts └── src │ ├── commonTest │ └── kotlin │ │ └── Test.kt │ ├── posix32Main │ └── kotlin │ │ └── org │ │ └── danbrough │ │ └── kotlinxtras │ │ └── misc.kt │ ├── posix64Main │ └── kotlin │ │ └── org │ │ └── danbrough │ │ └── kotlinxtras │ │ └── misc.kt │ └── posixMain │ └── kotlin │ └── org │ └── danbrough │ └── kotlinxtras │ └── misc.kt ├── core ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ └── org │ └── danbrough │ └── kotlinxtras │ └── core │ ├── CorePlugin.kt │ ├── curl.kt │ ├── iconv.kt │ ├── libssh2.kt │ ├── openssl.kt │ ├── openssl3.kt │ └── sqlite.kt ├── demos ├── curl │ ├── build.gradle.kts │ ├── cacert.pem │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle.kts │ ├── src │ │ └── posixMain │ │ │ └── kotlin │ │ │ └── demo1 │ │ │ └── Main.kt │ └── versions.properties ├── iconv │ ├── build.gradle.kts │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle.kts │ ├── src │ │ └── posixMain │ │ │ └── kotlin │ │ │ └── demo1 │ │ │ └── Main.kt │ └── versions.properties ├── libssh2 │ ├── .gitignore │ ├── build.gradle.kts │ ├── cacert.pem │ ├── gradle.properties │ ├── gradle │ │ ├── libs.versions.toml │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle.kts │ ├── src │ │ └── posixMain │ │ │ └── kotlin │ │ │ └── demo │ │ │ ├── hex │ │ │ ├── Main.kt │ │ │ └── Main2.kt │ │ │ ├── logging.kt │ │ │ └── ssh2 │ │ │ ├── Main.kt │ │ │ └── ssh2.c │ ├── ssh2Demo.kexe │ └── versions.properties ├── repos │ ├── datetime │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── gradle.properties │ │ ├── gradle │ │ │ ├── libs.versions.toml │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle.kts │ │ ├── src │ │ │ └── nativeMain │ │ │ │ └── kotlin │ │ │ │ └── demo1 │ │ │ │ └── Main.kt │ │ └── versions.properties │ ├── ktor │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle.kts │ │ ├── src │ │ │ ├── commonMain │ │ │ │ └── kotlin │ │ │ │ │ └── demo1 │ │ │ │ │ └── Main.kt │ │ │ └── nativeMain │ │ │ │ └── kotlin │ │ │ │ ├── demo1 │ │ │ │ └── Main.kt │ │ │ │ └── demo2 │ │ │ │ └── Main.kt │ │ └── versions.properties │ ├── okio │ │ ├── .gitignore │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle.kts │ │ ├── src │ │ │ ├── androidNativeX86Main │ │ │ │ └── kotlin │ │ │ │ │ └── Test.kt │ │ │ └── nativeMain │ │ │ │ └── kotlin │ │ │ │ └── okio │ │ │ │ └── samples │ │ │ │ └── Hashing.kt │ │ └── versions.properties │ ├── sqldelight │ │ ├── .gitignore │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── gradle.properties │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle.kts │ │ ├── src │ │ │ ├── commonMain │ │ │ │ ├── kotlin │ │ │ │ │ └── demo │ │ │ │ │ │ └── common.kt │ │ │ │ └── sqldelight │ │ │ │ │ └── demo │ │ │ │ │ └── db │ │ │ │ │ └── Player.sq │ │ │ └── nativeMain │ │ │ │ └── kotlin │ │ │ │ └── demo │ │ │ │ ├── Demo1.kt │ │ │ │ └── native.kt │ │ └── versions.properties │ └── sqliter │ │ ├── .gitignore │ │ ├── README.md │ │ ├── build.gradle.kts │ │ ├── gradle.properties │ │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ ├── gradlew.bat │ │ ├── settings.gradle.kts │ │ ├── src │ │ └── nativeMain │ │ │ └── kotlin │ │ │ └── demo1 │ │ │ └── Main.kt │ │ └── versions.properties ├── sqlite │ ├── .gitignore │ ├── README.md │ ├── build.gradle.kts │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle.kts │ ├── src │ │ └── nativeMain │ │ │ └── kotlin │ │ │ └── demo │ │ │ ├── Main.kt │ │ │ └── main.c │ └── versions.properties └── uuid │ ├── build.gradle.kts │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle.kts │ ├── src │ ├── c │ │ ├── test │ │ └── uuid_test.c │ └── posixMain │ │ └── kotlin │ │ └── demo │ │ └── main.kt │ └── versions.properties ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── libssh2 ├── build.gradle.kts └── src │ └── commonMain │ └── kotlin │ └── org │ └── danbrough │ └── kotlinxtras │ └── libssh2 │ └── libssh2.kt ├── mac_targets.txt ├── plugin ├── build.gradle.kts ├── gradle.properties └── src │ └── main │ └── kotlin │ └── org │ └── danbrough │ └── kotlinxtras │ ├── binaries │ ├── BinaryPlugin.kt │ ├── LibraryExtension.kt │ ├── archiveTasks.kt │ ├── buildTasks.kt │ ├── interops.kt │ ├── registerTasks.kt │ └── sourcesTasks.kt │ ├── konanDepsTasks.kt │ ├── konanTargetExtns.kt │ ├── logging.kt │ ├── projectExtns.kt │ ├── projectProperties.kt │ ├── sonatype │ ├── SonatypePlugin.kt │ ├── configurePublishing.kt │ ├── sonatypeCloseRepository.kt │ └── sonatypeOpenRepository.kt │ ├── supportedTargets.kt │ └── xtras.kt ├── repos └── README.md ├── scripts ├── clean.sh ├── publish_plugins.sh ├── refreshVersions.sh ├── sonatype_close.sh └── sonatype_open.sh ├── settings.gradle.kts ├── utils ├── README.md ├── build.gradle.kts └── src │ └── commonMain │ └── kotlin │ └── org │ └── danbrough │ └── utils │ └── io │ ├── Base64.kt │ └── Hex.kt └── versions.properties /.gitignore: -------------------------------------------------------------------------------- 1 | **/build 2 | **/.idea 3 | 4 | local.properties 5 | **/.gradle 6 | /libs 7 | /libsbak 8 | .kotlin 9 | .konan 10 | .cache 11 | .bash_history 12 | .ssh 13 | /tmp 14 | /bak 15 | /packages 16 | 17 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "repos/ktor"] 2 | path = repos/ktor 3 | url = https://github.com/danbrough/ktor.git 4 | branch = danbrough-2.1.0 5 | 6 | [submodule "repos/curl"] 7 | path = repos/curl 8 | url = https://github.com/curl/curl.git 9 | [submodule "repos/kotlinx.serialization"] 10 | path = repos/kotlinx.serialization 11 | url = https://github.com/danbrough/kotlinx.serialization.git 12 | branch = danbroid-v1.4.0 13 | [submodule "repos/kotlinx.atomicfu"] 14 | path = repos/kotlinx.atomicfu 15 | url = https://github.com/danbrough/kotlinx.atomicfu.git 16 | branch = dan-0.17.3 17 | [submodule "repos/kotlinx.coroutines"] 18 | path = repos/kotlinx.coroutines 19 | url = https://github.com/danbrough/kotlinx.coroutines.git 20 | branch = danbrough-1.6.3-mt 21 | [submodule "repos/openssl"] 22 | path = repos/openssl 23 | url = https://github.com/danbrough/openssl.git 24 | [submodule "repos/kotlinx.html"] 25 | path = repos/kotlinx.html 26 | url = https://github.com/danbrough/kotlinx.html.git 27 | [submodule "repos/sqlite"] 28 | path = repos/sqlite 29 | url = https://github.com/sqlite/sqlite.git 30 | [submodule "repos/sqldelight"] 31 | path = repos/sqldelight 32 | url = https://github.com/danbrough/sqldelight.git 33 | branch = danbrough-2.0.0-alpha03 34 | [submodule "repos/stately"] 35 | path = repos/stately 36 | url = https://github.com/danbrough/Stately.git 37 | [submodule "repos/sqliter"] 38 | path = repos/sqliter 39 | url = https://github.com/danbrough/SQLiter.git 40 | branch = remotes/origin/danbrough-1.2.1 41 | [submodule "repos/okio"] 42 | path = repos/okio 43 | url = https://github.com/danbrough/okio.git 44 | [submodule "repos/kotlinx-datetime"] 45 | path = repos/kotlinx-datetime 46 | url = https://github.com/danbrough/kotlinx-datetime.git 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KotlinXtras 2 | 3 | Common Kotlin packages with support for linux_arm32_hfp, linux_arm64 and Android native. 4 | 5 | ## Description 6 | 7 | This repo is serving two purposes at the moment. 8 | One is for tweaks of popular kotlin multiplatform packages for android native and linuxArm64, 9 | linuxArm32Hfp support. 10 | That you'll find in the [repos](./repos/) folder. 11 | 12 | The other is a complimentary plugin for cross-compiling native libraries for kotlin multiplatform. 13 | 14 | Precompiled versions will be published at `mavenCentral()` 15 | under [my repository](https://repo.maven.apache.org/maven2/org/danbrough/). 16 | They might take a while to get there so pre-releases can be found 17 | in [the sonatype staging section](https://s01.oss.sonatype.org/content/groups/staging/org/danbrough/) 18 | So you don't need to download this project and compile it, unless you want to. 19 | 20 | To use them in your projects just add: 21 | 22 | ```gradle 23 | repositories { 24 | // for the pre releases 25 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 26 | // for the final releases 27 | mavenCentral() 28 | } 29 | 30 | //and change "org.jetbrains.kotlinx" to "org.danbrough.kotlinx" 31 | dependencies { 32 | implementation("org.danbrough.kotlinx:kotlinx-coroutines-core:1.6.4") 33 | implementation("org.danbrough.kotlinx:kotlinx-serialization-core:1.5.0") 34 | // ..etc 35 | } 36 | ``` 37 | 38 | The tweaked repos will be git submodules under the [repos](./repos) folder. 39 | So you can clone those, compare with upstream, roll your own. 40 | Due to the need for absolute hard-coded paths in cinterop def files this repo will need to be 41 | checked out at /usr/local/kotlinxtras 42 | for building custom packages. 43 | You can also use the "consumer" plugin from this project to automatically download precompiled 44 | binaries to link against. 45 | See the sqlite,curl_standalone,sqldelight in the [demos](./demos) folder for example. 46 | 47 | ## The plugin. 48 | 49 | The plugin is used for cross-compiling kotlin multiplatform projects with native library support. 50 | There are demos in the [demos](./demos/) folder but it looks something like this: 51 | 52 | ```kotlin 53 | 54 | const val XTRAS_OPENSSL_EXTN_NAME = "xtrasOpenssl" 55 | 56 | open class OpenSSLBinaryExtension(project: Project) : LibraryExtension(project, "openssl") 57 | 58 | class OpenSSLPlugin : Plugin { 59 | override fun apply(project: Project) { 60 | 61 | project.registerLibraryExtension(XTRAS_OPENSSL_EXTN_NAME, OpenSSLBinaryExtension::class.java) { 62 | 63 | version = "1_1_1s" 64 | 65 | git("https://github.com/danbrough/openssl.git", "02e6fd7998830218909cbc484ca054c5916fdc59") 66 | 67 | configure { target -> 68 | outputs.file(workingDir.resolve("Makefile")) 69 | val args = mutableListOf( 70 | "./Configure", 71 | target.opensslPlatform, 72 | "no-tests", 73 | "threads", 74 | "--prefix=${prefixDir(target)}" 75 | ) 76 | if (target.family == Family.ANDROID) args += "-D__ANDROID_API__=21" 77 | else if (target.family == Family.MINGW) args += "--cross-compile-prefix=${target.hostTriplet}-" 78 | 79 | commandLine(args) 80 | } 81 | 82 | 83 | build { target -> 84 | commandLine(binaryConfiguration.makeBinary, "install_sw") 85 | } 86 | 87 | cinterops { 88 | headers = """ 89 | #staticLibraries = libcrypto.a libssl.a 90 | headers = openssl/ssl.h openssl/err.h openssl/bio.h openssl/evp.h 91 | linkerOpts.linux = -ldl -lc -lm -lssl -lcrypto 92 | linkerOpts.android = -ldl -lc -lm -lssl -lcrypto 93 | linkerOpts.macos = -ldl -lc -lm -lssl -lcrypto 94 | linkerOpts.mingw = -lm -lssl -lcrypto 95 | compilerOpts.android = -D__ANDROID_API__=21 96 | compilerOpts = -Wno-macro-redefined -Wno-deprecated-declarations -Wno-incompatible-pointer-types-discards-qualifiers 97 | #compilerOpts = -static 98 | 99 | """.trimIndent() 100 | } 101 | } 102 | } 103 | } 104 | ``` 105 | 106 | That creates a plugin that allows you to automatically download openSSL sources, cross compile them 107 | and build cinterop bindings for kotlin. 108 | You can also download precompiled binaries from maven. 109 | 110 | In the case of curl,openssl,iconv,sqlite (at present) you don't need to write these yourself as they 111 | are provided, (with precompiled binaries for linuxArm32Hfp,linuuxArm64, linuxX64, 112 | macosX64,macosArm64,androidNativeX86 .. and the rest ..) 113 | 114 | But as you can see, writing your own for projects using the "./configure, make install" logic isn't 115 | too hard. 116 | 117 | ## News 118 | 119 | ### 2023-03-17 - All the demos in the demos folder should be working now in the main branch. 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /binaries/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.danbrough.kotlinxtras.core.enableCurl 2 | import org.danbrough.kotlinxtras.core.enableIconv 3 | import org.danbrough.kotlinxtras.core.enableLibSSH2 4 | import org.danbrough.kotlinxtras.core.enableOpenssl3 5 | import org.danbrough.kotlinxtras.core.enableSqlite 6 | 7 | plugins { 8 | // `kotlin-dsl` 9 | //kotlin("multiplatform") 10 | xtras("sonatype", Xtras.version) 11 | xtras("core", Xtras.version) 12 | } 13 | 14 | 15 | enableIconv { 16 | publishBinaries = true 17 | } 18 | 19 | val openSSL = enableOpenssl3 { 20 | publishBinaries = true 21 | } 22 | 23 | enableCurl(openSSL) { 24 | publishBinaries = true 25 | } 26 | 27 | enableSqlite { 28 | publishBinaries = true 29 | } 30 | 31 | enableLibSSH2(openSSL) { 32 | publishBinaries = true 33 | } 34 | 35 | /* 36 | gradlePlugin { 37 | isAutomatedPublishing = false 38 | }*/ 39 | 40 | 41 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.gradle.api.tasks.testing.logging.TestLogEvent 2 | 3 | plugins { 4 | kotlin("multiplatform") apply false 5 | `maven-publish` 6 | id("org.jetbrains.dokka") apply false 7 | xtras("sonatype") version Xtras.version apply false 8 | } 9 | 10 | println("Using Kotlin compiler version: ${org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION}") 11 | 12 | 13 | group = Xtras.projectGroup 14 | version = Xtras.publishingVersion 15 | 16 | 17 | allprojects { 18 | 19 | repositories { 20 | 21 | maven(rootProject.layout.buildDirectory.dir("xtras/maven")) 22 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 23 | mavenCentral() 24 | } 25 | 26 | tasks.withType { 27 | testLogging { 28 | events = setOf( 29 | TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED 30 | ) 31 | exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL 32 | showStandardStreams = true 33 | showStackTraces = true 34 | } 35 | outputs.upToDateWhen { 36 | false 37 | } 38 | } 39 | } 40 | 41 | 42 | 43 | subprojects { 44 | group = Xtras.projectGroup 45 | version = Xtras.publishingVersion 46 | 47 | afterEvaluate { 48 | 49 | extensions.findByType(JavaPluginExtension::class.java)?.apply { 50 | toolchain.languageVersion.set(JavaLanguageVersion.of(Xtras.javaLangVersion)) 51 | } 52 | 53 | 54 | extensions.findByType(org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension::class.java) 55 | ?.apply { 56 | jvmToolchain { 57 | languageVersion.set(JavaLanguageVersion.of(Xtras.javaLangVersion)) 58 | } 59 | } 60 | 61 | 62 | extensions.findByType(PublishingExtension::class)?.also { 63 | publishing { 64 | publications.all { 65 | if (this !is MavenPublication) return@all 66 | xtrasPom() 67 | } 68 | } 69 | } 70 | } 71 | } 72 | 73 | 74 | 75 | 76 | afterEvaluate { 77 | tasks.findByPath(":plugin:javadocJar")?.also { 78 | tasks.findByPath(":core:dokkaHtml")?.mustRunAfter(it) 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | dependencies { 6 | compileOnly(kotlin("gradle-plugin")) 7 | } 8 | 9 | repositories { 10 | mavenCentral() 11 | } 12 | 13 | 14 | val javaLangVersion = 8 15 | 16 | java { 17 | toolchain.languageVersion.set(JavaLanguageVersion.of(javaLangVersion)) 18 | } 19 | 20 | kotlin { 21 | jvmToolchain { 22 | languageVersion.set(JavaLanguageVersion.of(javaLangVersion)) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | 2 | /*dependencyResolutionManagement { 3 | versionCatalogs { 4 | val libs by creating { 5 | from(files("../gradle/libs.versions.toml")) 6 | } 7 | } 8 | }*/ 9 | pluginManagement { 10 | 11 | repositories { 12 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 13 | gradlePluginPortal() 14 | mavenCentral() 15 | google() 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/Xtras.kt: -------------------------------------------------------------------------------- 1 | import org.gradle.plugin.use.PluginDependenciesSpec 2 | import org.gradle.plugin.use.PluginDependencySpec 3 | 4 | object Xtras { 5 | const val projectGroup = "org.danbrough.kotlinxtras" 6 | const val version = "0.0.3-beta17" 7 | const val publishingVersion = "0.0.3-beta17" 8 | const val repoName = "xtras" 9 | const val javaLangVersion = 8 10 | } 11 | 12 | fun PluginDependenciesSpec.xtras(plugin: String): PluginDependencySpec = 13 | id("${Xtras.projectGroup}.$plugin") 14 | 15 | fun PluginDependenciesSpec.xtras(plugin: String, version: String): PluginDependencySpec = 16 | id("${Xtras.projectGroup}.$plugin").version(version) 17 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/xtrasPom.kt: -------------------------------------------------------------------------------- 1 | import org.gradle.api.publish.maven.MavenPublication 2 | 3 | fun MavenPublication.xtrasPom() { 4 | pom { 5 | 6 | name.set("KotlinXtras") 7 | description.set("Common kotlin packages with linux arm and android native support") 8 | url.set("https://github.com/danbrough/kotlinxtras/") 9 | 10 | licenses { 11 | license { 12 | name.set("Apache-2.0") 13 | url.set("https://opensource.org/licenses/Apache-2.0") 14 | } 15 | } 16 | 17 | scm { 18 | connection.set("scm:git:git@github.com:danbrough/kotlinxtras.git") 19 | developerConnection.set("scm:git:git@github.com:danbrough/kotlinxtras.git") 20 | url.set("https://github.com/danbrough/kotlinxtras/") 21 | } 22 | 23 | issueManagement { 24 | system.set("GitHub") 25 | url.set("https://github.com/danbrough/kotlinxtras/issues") 26 | } 27 | 28 | developers { 29 | developer { 30 | id.set("danbrough") 31 | name.set("Dan Brough") 32 | email.set("dan@danbrough.org") 33 | organizationUrl.set("https://github.com/danbrough") 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /common/README.md: -------------------------------------------------------------------------------- 1 | # Common support project 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /common/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.danbrough.kotlinxtras.declareSupportedTargets 2 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 3 | 4 | 5 | plugins { 6 | kotlin("multiplatform") 7 | xtras("sonatype") 8 | } 9 | 10 | 11 | version = "0.0.1-beta01" 12 | 13 | kotlin { 14 | 15 | declareSupportedTargets() 16 | 17 | val posixMain by sourceSets.creating 18 | 19 | val posix32Main by sourceSets.creating { 20 | dependsOn(posixMain) 21 | } 22 | 23 | val posix64Main by sourceSets.creating { 24 | dependsOn(posixMain) 25 | } 26 | 27 | sourceSets { 28 | val commonTest by getting { 29 | dependencies { 30 | implementation(kotlin("test")) 31 | } 32 | } 33 | } 34 | 35 | targets.withType().all { 36 | compilations["main"].apply { 37 | if (konanTarget.architecture.bitness == 32) defaultSourceSet.dependsOn(posix32Main) 38 | else defaultSourceSet.dependsOn(posix64Main) 39 | } 40 | } 41 | 42 | 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /common/src/commonTest/kotlin/Test.kt: -------------------------------------------------------------------------------- 1 | import kotlin.test.Test 2 | 3 | class Test { 4 | 5 | @Test 6 | fun test() { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /common/src/posix32Main/kotlin/org/danbrough/kotlinxtras/misc.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras 2 | import platform.posix.size_t 3 | 4 | actual fun Int.toSizeT(): size_t = toUInt() 5 | actual fun Long.toSizeT(): size_t= toUInt() 6 | -------------------------------------------------------------------------------- /common/src/posix64Main/kotlin/org/danbrough/kotlinxtras/misc.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras 2 | import platform.posix.size_t 3 | 4 | actual fun Int.toSizeT(): size_t = toULong() 5 | actual fun Long.toSizeT(): size_t= toULong() 6 | -------------------------------------------------------------------------------- /common/src/posixMain/kotlin/org/danbrough/kotlinxtras/misc.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras 2 | 3 | import platform.posix.size_t 4 | 5 | expect fun Int.toSizeT(): size_t 6 | expect fun Long.toSizeT(): size_t 7 | 8 | -------------------------------------------------------------------------------- /core/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | `maven-publish` 4 | id("org.jetbrains.dokka") 5 | xtras("sonatype", Xtras.version) 6 | } 7 | 8 | dependencies { 9 | compileOnly(kotlin("gradle-plugin")) 10 | compileOnly(kotlin("gradle-plugin-api")) 11 | implementation("org.danbrough.kotlinxtras:plugin:${Xtras.version}") 12 | } 13 | 14 | gradlePlugin { 15 | plugins { 16 | create("core") { 17 | id = "$group.core" 18 | implementationClass = "$group.core.CorePlugin" 19 | displayName = "KotlinXtras core plugins" 20 | description = "Provides some core plugins" 21 | } 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /core/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | 2 | 3 | //includeBuild("../plugin") -------------------------------------------------------------------------------- /core/src/main/kotlin/org/danbrough/kotlinxtras/core/CorePlugin.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras.core 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | 6 | const val CORE_PUBLISHING_PACKAGE = "org.danbrough.kotlinxtras.core" 7 | 8 | class CorePlugin : Plugin { 9 | override fun apply(target: Project) { 10 | } 11 | } -------------------------------------------------------------------------------- /core/src/main/kotlin/org/danbrough/kotlinxtras/core/curl.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package org.danbrough.kotlinxtras.core 4 | 5 | 6 | import org.danbrough.kotlinxtras.binaries.* 7 | import org.danbrough.kotlinxtras.hostTriplet 8 | import org.danbrough.kotlinxtras.platformName 9 | import org.gradle.api.Project 10 | import org.gradle.api.tasks.Exec 11 | import org.gradle.configurationcache.extensions.capitalized 12 | import org.jetbrains.kotlin.konan.target.KonanTarget 13 | 14 | const val XTRAS_CURL_EXTN_NAME = "curl" 15 | 16 | fun Project.enableCurl( 17 | openSSL: LibraryExtension, 18 | extnName: String = XTRAS_CURL_EXTN_NAME, 19 | config: LibraryExtension.() -> Unit = {} 20 | ): LibraryExtension { 21 | 22 | return extensions.findByName(extnName) as? LibraryExtension 23 | ?: registerLibraryExtension(extnName) { 24 | publishingGroup = CORE_PUBLISHING_PACKAGE 25 | // binaries.androidNdkDir = File("/mnt/files/sdk/android/ndk/25.0.8775105/") 26 | 27 | 28 | version = "8.2.1" 29 | 30 | //git("https://github.com/curl/curl.git", "046209e561b7e9b5aab1aef7daebf29ee6e6e8c7") 31 | //git("https://github.com/curl/curl.git", "b16d1fa8ee567b52c09a0f89940b07d8491b881d") 32 | git("https://github.com/curl/curl.git", "50490c0679fcd0e50bb3a8fbf2d9244845652cf0") 33 | 34 | val autoConfTaskName: KonanTarget.() -> String = 35 | { "xtrasAutoconf${libName.capitalized()}${platformName.capitalized()}" } 36 | 37 | configureTarget { target -> 38 | 39 | project.tasks.create(target.autoConfTaskName(), Exec::class.java) { 40 | dependsOn(extractSourcesTaskName(target)) 41 | workingDir(sourcesDir(target)) 42 | outputs.file(workingDir.resolve("configure")) 43 | commandLine(binaries.autoreconfBinary, "-fi") 44 | 45 | environment( 46 | "PATH", 47 | "${binaries.androidNdkDir}/prebuilt/linux-x86_64/bin:${binaries.androidNdkDir}/toolchains/llvm/prebuilt/linux-x86_64/bin:${environment["PATH"]}" 48 | ) 49 | } 50 | } 51 | 52 | 53 | configure { target -> 54 | dependsOn(project.tasks.getByName(openSSL.extractArchiveTaskName(target))) 55 | 56 | dependsOn(target.autoConfTaskName()) 57 | 58 | 59 | 60 | outputs.file(workingDir.resolve("Makefile")) 61 | 62 | commandLine( 63 | "./configure", 64 | "--host=${target.hostTriplet}", 65 | "--with-ssl=${openSSL.libsDir(target)}", 66 | "--with-ca-path=/etc/ssl/certs:/etc/security/cacerts:/etc/ca-certificates", 67 | "--prefix=${buildDir(target)}" 68 | ) 69 | } 70 | 71 | build { 72 | commandLine(binaries.makeBinary, "install") 73 | } 74 | 75 | cinterops { 76 | headers = """ 77 | headers = curl/curl.h 78 | linkerOpts = -lz -lssl -lcrypto -lcurl 79 | #staticLibraries.linux = libcurl.a 80 | #staticLibraries.android = libcurl.a 81 | 82 | """.trimIndent() 83 | } 84 | 85 | config() 86 | } 87 | } 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /core/src/main/kotlin/org/danbrough/kotlinxtras/core/iconv.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package org.danbrough.kotlinxtras.core 4 | 5 | 6 | import org.danbrough.kotlinxtras.binaries.* 7 | import org.danbrough.kotlinxtras.hostTriplet 8 | import org.gradle.api.Project 9 | 10 | const val XTRAS_ICONV_EXTN_NAME = "iconv" 11 | const val XTRAS_ICONV_VERSION_NAME = "1.17a" 12 | const val XTRAS_ICONV_SOURCE_URL = "https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz" 13 | 14 | fun Project.enableIconv( 15 | extnName: String = XTRAS_ICONV_EXTN_NAME, 16 | versionName: String = XTRAS_ICONV_VERSION_NAME, 17 | sourceURL: String = XTRAS_ICONV_SOURCE_URL, 18 | config: LibraryExtension.() -> Unit = {} 19 | ) = 20 | extensions.findByName(extnName) as? LibraryExtension 21 | ?: project.registerLibraryExtension(extnName) { 22 | publishingGroup = CORE_PUBLISHING_PACKAGE 23 | version = versionName 24 | 25 | download(sourceURL) { 26 | stripTopDir = true 27 | } 28 | 29 | configure { target -> 30 | 31 | commandLine( 32 | "./configure", 33 | "-C", 34 | "--enable-static", 35 | "--host=${target.hostTriplet}", 36 | "--prefix=${buildDir(target)}" 37 | ) 38 | outputs.file(workingDir.resolve("Makefile")) 39 | } 40 | 41 | build { 42 | commandLine(binaries.makeBinary, "install") 43 | } 44 | 45 | cinterops { 46 | headers = """ 47 | |headers = iconv.h libcharset.h 48 | |linkerOpts = -liconv 49 | |package = libiconv 50 | |""".trimMargin() 51 | } 52 | 53 | config() 54 | } 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /core/src/main/kotlin/org/danbrough/kotlinxtras/core/libssh2.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package org.danbrough.kotlinxtras.core 4 | 5 | 6 | import org.danbrough.kotlinxtras.binaries.* 7 | import org.danbrough.kotlinxtras.hostTriplet 8 | import org.danbrough.kotlinxtras.platformName 9 | import org.gradle.api.Project 10 | import org.gradle.api.tasks.Exec 11 | import org.gradle.configurationcache.extensions.capitalized 12 | 13 | 14 | const val LIBSSH2_EXTN_NAME = "libssh2" 15 | 16 | //const val LIBSSH2_VERSION = "3.1.2-danbrough" 17 | //const val LIBSSH2_GIT_COMMIT = "5accd111b0d4689a978f2bbccd976583f493efab" 18 | const val LIBSSH2_VERSION = "1.11.0" 19 | const val LIBSSH2_GIT_COMMIT = "1c3f1b7da588f2652260285529ec3c1f1125eb4e" 20 | const val LIBSSH2_GIT_URL = "https://github.com/libssh2/libssh2.git" 21 | // 22 | //const val LIBSSH2_VERSION = "3.0.8" 23 | //const val LIBSSH2_GIT_COMMIT = "e4e4c3b72620cf8ef35c275271415bfc675ffaa3" 24 | 25 | fun Project.enableLibSSH2( 26 | openSSL: LibraryExtension, 27 | extnName: String = LIBSSH2_EXTN_NAME, 28 | versionName: String = LIBSSH2_VERSION, 29 | commit: String = LIBSSH2_GIT_COMMIT, 30 | gitURL: String = LIBSSH2_GIT_URL, 31 | config: LibraryExtension.() -> Unit = {} 32 | ): LibraryExtension = 33 | extensions.findByName(extnName) as? LibraryExtension ?: registerLibraryExtension(extnName) { 34 | publishingGroup = CORE_PUBLISHING_PACKAGE 35 | 36 | version = versionName 37 | 38 | git(gitURL, commit) 39 | 40 | 41 | val autoConfTaskName: org.jetbrains.kotlin.konan.target.KonanTarget.() -> String = 42 | { "xtrasAutoconf${libName.capitalized()}${platformName.capitalized()}" } 43 | 44 | 45 | configureTarget { target -> 46 | 47 | project.tasks.create(target.autoConfTaskName(), Exec::class.java) { 48 | dependsOn(extractSourcesTaskName(target)) 49 | workingDir(sourcesDir(target)) 50 | outputs.file(workingDir.resolve("configure")) 51 | commandLine(binaries.autoreconfBinary, "-fi") 52 | } 53 | } 54 | 55 | configure(override = true) { target -> 56 | dependsOn(project.tasks.getByName(openSSL.extractArchiveTaskName(target))) 57 | 58 | dependsOn(target.autoConfTaskName()) 59 | 60 | 61 | 62 | outputs.file(workingDir.resolve("Makefile")) 63 | 64 | commandLine( 65 | "./configure", 66 | "--with-crypto=openssl", "--with-libssl-prefix=${openSSL.libsDir(target)}", 67 | "--with-libz", 68 | //--with-libz-prefix[=DIR] search for libz in DIR/include and DIR/lib 69 | "--without-libz-prefix", 70 | "--host=${target.hostTriplet}", 71 | "--prefix=${buildDir(target)}" 72 | ) 73 | } 74 | 75 | build { 76 | commandLine(binaries.makeBinary, "install") 77 | } 78 | 79 | cinterops { 80 | headers = """ 81 | headers =libssh2.h 82 | linkerOpts = -lz -lssl -lcrypto -lssh2 83 | #staticLibraries.linux = libcurl.a 84 | #staticLibraries.android = libcurl.a 85 | 86 | """.trimIndent() 87 | } 88 | 89 | config() 90 | } 91 | 92 | -------------------------------------------------------------------------------- /core/src/main/kotlin/org/danbrough/kotlinxtras/core/openssl.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package org.danbrough.kotlinxtras.core 4 | 5 | 6 | import org.danbrough.kotlinxtras.binaries.* 7 | import org.danbrough.kotlinxtras.hostTriplet 8 | import org.gradle.api.Project 9 | import org.jetbrains.kotlin.konan.target.Family 10 | import org.jetbrains.kotlin.konan.target.KonanTarget 11 | 12 | const val OPENSSL_EXTN_NAME = "openssl" 13 | 14 | const val OPENSSL_VERSION = "1_1_1t" 15 | const val OPENSSL_GIT_COMMIT = "6bdac15c72dca585d29e5d28988e9a7c5ec38edb" 16 | const val OPENSSL_GIT_URL = "https://github.com/danbrough/openssl.git" 17 | 18 | fun Project.enableOpenssl( 19 | extnName: String = OPENSSL_EXTN_NAME, 20 | versionName: String = OPENSSL_VERSION, 21 | commit: String = OPENSSL_GIT_COMMIT, 22 | gitURL: String = OPENSSL_GIT_URL, 23 | config: LibraryExtension.() -> Unit = {} 24 | ): LibraryExtension = 25 | extensions.findByName(extnName) as? LibraryExtension ?: registerLibraryExtension(extnName) { 26 | 27 | publishingGroup = CORE_PUBLISHING_PACKAGE 28 | 29 | version = versionName 30 | 31 | git(gitURL, commit) 32 | 33 | configure { target -> 34 | outputs.file(workingDir.resolve("Makefile")) 35 | val args = mutableListOf( 36 | "./Configure", target.opensslPlatform, "no-tests", "threads", "--prefix=${buildDir(target)}" 37 | ) 38 | if (target.family == Family.ANDROID) args += "-D__ANDROID_API__=21" 39 | else if (target.family == Family.MINGW) args += "--cross-compile-prefix=${target.hostTriplet}-" 40 | 41 | commandLine(args) 42 | } 43 | 44 | 45 | build { 46 | commandLine(binaries.makeBinary, "install_sw") 47 | } 48 | 49 | cinterops { 50 | headers = """ 51 | #staticLibraries = libcrypto.a libssl.a 52 | headers = openssl/ssl.h openssl/err.h openssl/bio.h openssl/evp.h 53 | linkerOpts.linux = -ldl -lc -lm -lssl -lcrypto 54 | linkerOpts.android = -ldl -lc -lm -lssl -lcrypto 55 | linkerOpts.macos = -ldl -lc -lm -lssl -lcrypto 56 | linkerOpts.mingw = -lm -lssl -lcrypto 57 | compilerOpts.android = -D__ANDROID_API__=21 58 | compilerOpts = -Wno-macro-redefined -Wno-deprecated-declarations -Wno-incompatible-pointer-types-discards-qualifiers 59 | #compilerOpts = -static 60 | 61 | """.trimIndent() 62 | } 63 | 64 | config() 65 | } 66 | 67 | 68 | val KonanTarget.opensslPlatform: String 69 | get() = when (this) { 70 | KonanTarget.LINUX_X64 -> "linux-x86_64" 71 | KonanTarget.LINUX_ARM64 -> "linux-aarch64" 72 | KonanTarget.LINUX_ARM32_HFP -> "linux-armv4" 73 | KonanTarget.LINUX_MIPS32 -> TODO() 74 | KonanTarget.LINUX_MIPSEL32 -> TODO() 75 | KonanTarget.ANDROID_ARM32 -> "android-arm" 76 | KonanTarget.ANDROID_ARM64 -> "android-arm64" 77 | KonanTarget.ANDROID_X86 -> "android-x86" 78 | KonanTarget.ANDROID_X64 -> "android-x86_64" 79 | KonanTarget.MINGW_X64 -> "mingw64" 80 | KonanTarget.MINGW_X86 -> "mingw" 81 | 82 | KonanTarget.MACOS_X64 -> "darwin64-x86_64-cc" 83 | KonanTarget.MACOS_ARM64 -> "darwin64-arm64-cc" 84 | KonanTarget.IOS_ARM32 -> "ios-cross" 85 | KonanTarget.IOS_ARM64 -> "ios64-cross" //ios-cross ios-xcrun 86 | KonanTarget.IOS_SIMULATOR_ARM64 -> "iossimulator-xcrun" 87 | KonanTarget.IOS_X64 -> "ios64-cross" 88 | 89 | else -> throw Error("$this not supported") 90 | } 91 | 92 | -------------------------------------------------------------------------------- /core/src/main/kotlin/org/danbrough/kotlinxtras/core/openssl3.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package org.danbrough.kotlinxtras.core 4 | 5 | 6 | import org.danbrough.kotlinxtras.binaries.* 7 | import org.danbrough.kotlinxtras.hostTriplet 8 | import org.gradle.api.Project 9 | import org.jetbrains.kotlin.konan.target.Family 10 | import java.io.File 11 | 12 | const val OPENSSL3_EXTN_NAME = "openssl3" 13 | 14 | //const val OPENSSL3_VERSION = "3.1.2-danbrough" 15 | //const val OPENSSL3_GIT_COMMIT = "5accd111b0d4689a978f2bbccd976583f493efab" 16 | const val OPENSSL3_VERSION = "3.1.2" 17 | const val OPENSSL3_GIT_COMMIT = "17a2c5111864d8e016c5f2d29c40a3746b559e9d" 18 | // 19 | //const val OPENSSL3_VERSION = "3.0.8" 20 | //const val OPENSSL3_GIT_COMMIT = "e4e4c3b72620cf8ef35c275271415bfc675ffaa3" 21 | 22 | fun Project.enableOpenssl3( 23 | extnName: String = OPENSSL3_EXTN_NAME, 24 | versionName: String = OPENSSL3_VERSION, 25 | commit: String = OPENSSL3_GIT_COMMIT, 26 | gitURL: String = OPENSSL_GIT_URL, 27 | config: LibraryExtension.() -> Unit = {} 28 | ): LibraryExtension = 29 | extensions.findByName(extnName) as? LibraryExtension ?: registerLibraryExtension(extnName) { 30 | 31 | 32 | publishingGroup = CORE_PUBLISHING_PACKAGE 33 | 34 | version = versionName 35 | 36 | git(gitURL, commit) 37 | 38 | configure { target -> 39 | binaries.androidNdkDir = File("/mnt/files/sdk/android/ndk/25.0.8775105/") 40 | 41 | outputs.file(workingDir.resolve("Makefile")) 42 | val args = mutableListOf( 43 | "./Configure", target.opensslPlatform, "no-tests", "threads", "--prefix=${buildDir(target)}" 44 | ) 45 | if (target.family == Family.ANDROID) args += "-D__ANDROID_API__=21" 46 | else if (target.family == Family.MINGW) args += "--cross-compile-prefix=${target.hostTriplet}-" 47 | environment("CFLAGS", " -Wno-macro-redefined ") 48 | 49 | environment( 50 | "PATH", 51 | "${binaries.androidNdkDir}/prebuilt/linux-x86_64/bin:${binaries.androidNdkDir}/toolchains/llvm/prebuilt/linux-x86_64/bin:${environment["PATH"]}" 52 | ) 53 | commandLine(args) 54 | } 55 | 56 | 57 | 58 | build { target -> 59 | environment( 60 | "PATH", 61 | "${binaries.androidNdkDir}/prebuilt/linux-x86_64/bin:${binaries.androidNdkDir}/toolchains/llvm/prebuilt/linux-x86_64/bin:${environment["PATH"]}" 62 | ) 63 | 64 | commandLine(binaries.makeBinary, "install_sw") 65 | doLast { 66 | val buildDir = buildDir(target) 67 | if (buildDir.resolve("lib64").exists()) { 68 | buildDir.resolve("lib64").renameTo(buildDir.resolve("lib")) 69 | } 70 | } 71 | } 72 | 73 | cinterops { 74 | headers = """ 75 | #staticLibraries = libcrypto.a libssl.a 76 | headers = openssl/ssl.h openssl/err.h openssl/bio.h openssl/evp.h 77 | linkerOpts.linux = -ldl -lc -lm -lssl -lcrypto 78 | linkerOpts.android = -ldl -lc -lm -lssl -lcrypto 79 | linkerOpts.macos = -ldl -lc -lm -lssl -lcrypto 80 | linkerOpts.mingw = -lm -lssl -lcrypto 81 | compilerOpts.android = -D__ANDROID_API__=21 82 | compilerOpts = -Wno-macro-redefined -Wno-deprecated-declarations -Wno-incompatible-pointer-types-discards-qualifiers 83 | #compilerOpts = -static 84 | 85 | """.trimIndent() 86 | } 87 | 88 | config() 89 | } 90 | 91 | -------------------------------------------------------------------------------- /core/src/main/kotlin/org/danbrough/kotlinxtras/core/sqlite.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package org.danbrough.kotlinxtras.core 4 | 5 | 6 | import org.danbrough.kotlinxtras.binaries.* 7 | import org.danbrough.kotlinxtras.hostTriplet 8 | import org.gradle.api.Project 9 | 10 | const val XTRAS_SQLITE_EXTN_NAME = "sqlite" 11 | 12 | //const val XTRAS_SQLITE_VERSION_NAME = "3.41.2" 13 | //const val XTRAS_SQLITE_SOURCE_URL = "https://www.sqlite.org/2023/sqlite-autoconf-3410200.tar.gz" 14 | const val XTRAS_SQLITE_VERSION_NAME = "3.42.0" 15 | const val XTRAS_SQLITE_SOURCE_URL = "https://www.sqlite.org/2023/sqlite-autoconf-3420000.tar.gz" 16 | //const val XTRAS_SQLITE_COMMIT = "e671c4fbc057f8b1505655126eaf90640149ced6" 17 | 18 | /* 19 | fun Project.enableSqlite( 20 | extnName: String = XTRAS_SQLITE_EXTN_NAME, versionName: String = XTRAS_SQLITE_VERSION_NAME, 21 | 22 | gitURL: String = "https://github.com/sqlite/sqlite.git", 23 | commit: String = XTRAS_SQLITE_COMMIT, 24 | config: LibraryExtension .() -> Unit = {} 25 | ): LibraryExtension = 26 | extensions.findByName(extnName) as? LibraryExtension ?: registerLibraryExtension(extnName) { 27 | publishingGroup = CORE_PUBLISHING_PACKAGE 28 | version = versionName 29 | 30 | git(gitURL, commit) 31 | 32 | configure { target -> 33 | 34 | commandLine( 35 | "./configure", 36 | "--host=${target.hostTriplet}", 37 | "--disable-readline", 38 | "--prefix=${buildDir(target)}", 39 | ) 40 | outputs.file(workingDir.resolve("Makefile")) 41 | } 42 | 43 | build { 44 | commandLine(binaries.makeBinary, "install") 45 | } 46 | 47 | cinterops { 48 | headers = """ 49 | headers = sqlite3.h sqlite3ext.h 50 | linkerOpts = -ldl -lsqlite3 51 | linkerOpts.mingw = -ldl -lsqlite3 -lpthread 52 | headers = sqlite3.h 53 | headerFilter = sqlite3*.h 54 | compilerOpts = -fPIC 55 | 56 | """.trimIndent() 57 | } 58 | 59 | config() 60 | } 61 | */ 62 | 63 | 64 | fun Project.enableSqlite( 65 | extnName: String = XTRAS_SQLITE_EXTN_NAME, versionName: String = XTRAS_SQLITE_VERSION_NAME, 66 | sourceURL: String = XTRAS_SQLITE_SOURCE_URL, 67 | config: LibraryExtension .() -> Unit = {} 68 | ): LibraryExtension = 69 | extensions.findByName(extnName) as? LibraryExtension ?: registerLibraryExtension(extnName) { 70 | publishingGroup = CORE_PUBLISHING_PACKAGE 71 | version = versionName 72 | 73 | download(sourceURL) { 74 | stripTopDir = true 75 | tarExtractOptions = "xfz" 76 | } 77 | 78 | configure { target -> 79 | 80 | commandLine( 81 | "./configure", 82 | "--host=${target.hostTriplet}", 83 | "--disable-readline", 84 | "--prefix=${buildDir(target)}", 85 | ) 86 | outputs.file(workingDir.resolve("Makefile")) 87 | } 88 | 89 | build { 90 | commandLine(binaries.makeBinary, "install") 91 | } 92 | 93 | cinterops { 94 | headers = """ 95 | headers = sqlite3.h sqlite3ext.h 96 | linkerOpts = -ldl -lsqlite3 97 | linkerOpts.mingw = -ldl -lsqlite3 -lpthread 98 | headers = sqlite3.h 99 | headerFilter = sqlite3*.h 100 | compilerOpts = -fPIC 101 | 102 | """.trimIndent() 103 | } 104 | 105 | config() 106 | } 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /demos/curl/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.danbrough.kotlinxtras.core.enableCurl 2 | import org.danbrough.kotlinxtras.core.enableOpenssl3 3 | 4 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 5 | import org.jetbrains.kotlin.konan.target.HostManager 6 | 7 | plugins { 8 | kotlin("multiplatform") 9 | id("org.danbrough.kotlinxtras.core") 10 | } 11 | 12 | repositories { 13 | maven("/usr/local/kotlinxtras/build/xtras/maven") 14 | maven("https://s01.oss.sonatype.org/content/groups/staging") 15 | mavenCentral() 16 | } 17 | 18 | val openSSL = enableOpenssl3() 19 | 20 | enableCurl(openSSL) { 21 | cinterops { 22 | interopsPackage = "libcurl" 23 | } 24 | } 25 | 26 | kotlin { 27 | 28 | linuxX64() 29 | @Suppress("DEPRECATION") 30 | linuxArm32Hfp() 31 | linuxArm64() 32 | 33 | if (HostManager.hostIsMac) { 34 | macosX64() 35 | macosArm64() 36 | } 37 | 38 | androidNativeX86() 39 | 40 | val commonMain by sourceSets.getting { 41 | dependencies { 42 | implementation("org.danbrough:klog:_") 43 | implementation("org.danbrough.kotlinxtras:common:_") 44 | } 45 | } 46 | 47 | val posixMain by sourceSets.creating { 48 | dependsOn(commonMain) 49 | } 50 | 51 | targets.withType { 52 | 53 | compilations["main"].apply { 54 | defaultSourceSet.dependsOn(posixMain) 55 | } 56 | 57 | 58 | binaries { 59 | executable("curlDemo") { 60 | entryPoint = "demo1.main" 61 | runTask?.environment("CA_CERT_FILE", file("cacert.pem")) 62 | findProperty("args")?.also { 63 | runTask?.args(it.toString()) 64 | } 65 | } 66 | } 67 | } 68 | } 69 | 70 | 71 | 72 | tasks.create("run") { 73 | dependsOn("runCurlDemoDebugExecutable${if (HostManager.hostIsMac) "MacosX64" else "LinuxX64"}") 74 | } 75 | -------------------------------------------------------------------------------- /demos/curl/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.mpp.stability.nowarn=true 2 | org.gradle.daemon=true 3 | org.gradle.jvmargs=-XX\:MaxMetaspaceSize\=1G -Xmx2048m -Xss32m 4 | android.useAndroidX=true 5 | android.enableJetifier=true 6 | kotlin.code.style=official 7 | kotlin.mpp.enableCInteropCommonization=true 8 | android.disableAutomaticComponentCreation=true 9 | kotlin.native.binary.memoryModel=experimental 10 | 11 | 12 | org.gradle.caching=true 13 | org.gradle.unsafe.configuration-cache=false 14 | 15 | #xtras.dir.maven=/usr/local/kotlinxtras/build/xtras/maven 16 | 17 | kotlin.native.cacheKind.linuxX64=none 18 | #comment out to defer to only gradle logging 19 | xtras.log.stdout=true 20 | -------------------------------------------------------------------------------- /demos/curl/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/demos/curl/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/curl/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /demos/curl/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /demos/curl/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | 3 | repositories { 4 | maven("/usr/local/kotlinxtras/build/xtras/maven") 5 | maven("https://s01.oss.sonatype.org/content/groups/staging") 6 | mavenCentral() 7 | 8 | gradlePluginPortal() 9 | 10 | google() 11 | } 12 | 13 | 14 | } 15 | 16 | plugins { 17 | id("de.fayard.refreshVersions") version "0.51.0" 18 | } 19 | 20 | 21 | rootProject.name = "curl_demo" 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /demos/curl/src/posixMain/kotlin/demo1/Main.kt: -------------------------------------------------------------------------------- 1 | package demo1 2 | 3 | import klog.KLogWriters 4 | import klog.KMessageFormatters 5 | import klog.Level 6 | import klog.colored 7 | import kotlinx.cinterop.ExperimentalForeignApi 8 | import kotlinx.cinterop.memScoped 9 | import kotlinx.cinterop.toKString 10 | import libcurl.* 11 | 12 | val log = klog.klog("demo1") { 13 | writer = KLogWriters.stdOut 14 | messageFormatter = KMessageFormatters.verbose.colored 15 | level = Level.TRACE 16 | } 17 | 18 | 19 | @OptIn(ExperimentalForeignApi::class) 20 | fun main(args: Array) { 21 | log.info("running main ..") 22 | 23 | val url = if (args.isEmpty()) "https://example.com" else args[0] 24 | 25 | 26 | log.debug("connecting to $url ..") 27 | 28 | memScoped { 29 | 30 | val curl = curl_easy_init() 31 | if (curl != null) { 32 | curl_easy_setopt(curl, CURLOPT_URL, url) 33 | curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L) 34 | 35 | //to specify a cacert.pem file (needed on android native) 36 | platform.posix.getenv("CA_CERT_FILE")?.also { 37 | curl_easy_setopt(curl, CURLOPT_CAINFO, it) 38 | }?: log.warn("Set environment CA_CERT_FILE to location of cacert.pem if there are ssl verification errors") 39 | 40 | 41 | val res = curl_easy_perform(curl) 42 | if (res != CURLE_OK) { 43 | log.error("curl_easy_perform() failed ${curl_easy_strerror(res)?.toKString()}\n") 44 | } 45 | curl_easy_cleanup(curl) 46 | } 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /demos/curl/versions.properties: -------------------------------------------------------------------------------- 1 | #### Dependencies and Plugin versions with their available updates. 2 | #### Generated by `./gradlew refreshVersions` version 0.51.0 3 | #### 4 | #### Don't manually edit or split the comments that start with four hashtags (####), 5 | #### they will be overwritten by refreshVersions. 6 | #### 7 | #### suppress inspection "SpellCheckingInspection" for whole file 8 | #### suppress inspection "UnusedProperty" for whole file 9 | 10 | plugin.org.danbrough.kotlinxtras.core=0.0.3-beta15 11 | 12 | version.kotlin=1.9.0 13 | 14 | version.org.danbrough.kotlinxtras..common=0.0.1-beta01 15 | 16 | version.org.danbrough..klog=0.0.2-beta02 17 | -------------------------------------------------------------------------------- /demos/iconv/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.danbrough.kotlinxtras.core.enableIconv 2 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 3 | import org.jetbrains.kotlin.konan.target.HostManager 4 | 5 | plugins { 6 | kotlin("multiplatform") 7 | id("org.danbrough.kotlinxtras.core") 8 | 9 | } 10 | 11 | 12 | enableIconv { 13 | cinterops { 14 | 15 | } 16 | } 17 | repositories { 18 | maven("/usr/local/kotlinxtras/build/xtras/maven") 19 | maven("https://s01.oss.sonatype.org/content/groups/staging") 20 | mavenCentral() 21 | } 22 | 23 | 24 | kotlin { 25 | 26 | linuxX64() 27 | linuxArm32Hfp() 28 | linuxArm64() 29 | androidNativeX86() 30 | macosX64() 31 | macosArm64() 32 | 33 | val commonMain by sourceSets.getting { 34 | dependencies { 35 | implementation("org.danbrough:klog:_") 36 | implementation("org.danbrough.kotlinxtras:common:_") 37 | } 38 | } 39 | 40 | 41 | val posixMain by sourceSets.creating 42 | 43 | targets.withType { 44 | 45 | compilations["main"].apply { 46 | defaultSourceSet.dependsOn(posixMain) 47 | } 48 | 49 | binaries { 50 | executable("iconvDemo") { 51 | entryPoint = "demo1.main" 52 | 53 | } 54 | } 55 | } 56 | } 57 | 58 | tasks.create("run") { 59 | dependsOn("runIconvDemoDebugExecutable${if (HostManager.hostIsMac) "MacosX64" else "LinuxX64"}") 60 | } 61 | 62 | -------------------------------------------------------------------------------- /demos/iconv/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.mpp.stability.nowarn=true 2 | org.gradle.daemon=true 3 | org.gradle.jvmargs=-XX\:MaxMetaspaceSize\=1G -Xmx2048m -Xss32m 4 | android.useAndroidX=true 5 | android.enableJetifier=true 6 | kotlin.code.style=official 7 | kotlin.mpp.enableCInteropCommonization=true 8 | android.disableAutomaticComponentCreation=true 9 | kotlin.native.binary.memoryModel=experimental 10 | 11 | 12 | #org.gradle.caching=true 13 | #org.gradle.unsafe.configuration-cache=true 14 | 15 | 16 | #xtras.dir=/usr/local/kotlinxtras/build/xtras 17 | #xtras.dir.libs=/usr/local/kotlinxtras/libs 18 | 19 | -------------------------------------------------------------------------------- /demos/iconv/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/demos/iconv/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/iconv/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-rc-3-all.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /demos/iconv/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /demos/iconv/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | //for local builds 4 | maven("/usr/local/kotlinxtras/build/xtras/maven") 5 | //for unreleased staging builds 6 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 7 | //for release builds 8 | mavenCentral() 9 | 10 | gradlePluginPortal() 11 | 12 | google() 13 | } 14 | 15 | 16 | } 17 | 18 | plugins { 19 | id("de.fayard.refreshVersions") version "0.51.0" 20 | } 21 | 22 | 23 | rootProject.name = "iconv_demo" 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /demos/iconv/src/posixMain/kotlin/demo1/Main.kt: -------------------------------------------------------------------------------- 1 | package demo1 2 | 3 | import klog.KLogWriters 4 | import klog.KMessageFormatters 5 | import klog.Level 6 | import klog.colored 7 | import kotlinx.cinterop.* 8 | import libiconv.iconv 9 | import libiconv.iconv_close 10 | import libiconv.iconv_open 11 | import org.danbrough.kotlinxtras.toSizeT 12 | import platform.posix.* 13 | 14 | 15 | @OptIn(UnsafeNumber::class) 16 | val s:size_t = 0u 17 | 18 | val log = klog.klog("demo1"){ 19 | level = Level.TRACE 20 | messageFormatter = KMessageFormatters.verbose.colored 21 | writer = KLogWriters.stdOut 22 | } 23 | 24 | fun main(){ 25 | 26 | memScoped { 27 | 28 | 29 | log.info("calling iconv_open ..") 30 | 31 | val conv = iconv_open!!("UTF-8".cstr.ptr,"GBK".cstr.ptr) 32 | 33 | if (conv.toLong() == -1L){ 34 | val err = posix_errno() 35 | log.error("failed: $err : ${strerror(err)?.toKString()}") 36 | return@memScoped 37 | } 38 | 39 | val input = intArrayOf(0xB5,0xE7,0xCA,0xD3,0xBB,0xFA).map{it.toByte()}.toByteArray() 40 | 41 | val output =ByteArray(128){ 42 | 0.toByte() 43 | } 44 | 45 | val inputSize = alloc().also { 46 | it.value = input.size.toSizeT() 47 | } 48 | 49 | 50 | 51 | val outputSize = alloc().also { 52 | it.value = output.size.toSizeT() 53 | } 54 | 55 | input.usePinned {inputPinned-> 56 | output.usePinned {outputPinned-> 57 | 58 | val inbuf = alloc>().also { 59 | it.value = inputPinned.addressOf(0) 60 | } 61 | 62 | val outbuf = alloc>().also { 63 | it.value = outputPinned.addressOf(0) 64 | } 65 | 66 | if (iconv!!(conv,inbuf.ptr,inputSize.ptr,outbuf.ptr,outputSize.ptr).toLong() == -1L){ 67 | val err = posix_errno() 68 | log.error("iconv failed: $err : ${strerror(err)?.toKString()}") 69 | return@memScoped 70 | } 71 | 72 | log.trace("output remaining: ${outputSize.value}") 73 | } 74 | 75 | 76 | val outputString = output.decodeToString(0,output.size - outputSize.value.toInt()) 77 | val expected = "电视机" 78 | 79 | if (outputString != expected){ 80 | log.error("Invalid output: $outputString Expecting: $expected") 81 | log.debug("${outputString.encodeToByteArray().joinToString(",")} != ${expected.encodeToByteArray().joinToString(",")}") 82 | } 83 | 84 | log.debug("output: ${output.decodeToString()}") 85 | 86 | if (iconv_close!!(conv).toLong() == -1L){ 87 | val err = posix_errno() 88 | log.error("close failed: $err : ${strerror(err)?.toKString()}") 89 | } 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /demos/iconv/versions.properties: -------------------------------------------------------------------------------- 1 | #### Dependencies and Plugin versions with their available updates. 2 | #### Generated by `./gradlew refreshVersions` version 0.51.0 3 | #### 4 | #### Don't manually edit or split the comments that start with four hashtags (####), 5 | #### they will be overwritten by refreshVersions. 6 | #### 7 | #### suppress inspection "SpellCheckingInspection" for whole file 8 | #### suppress inspection "UnusedProperty" for whole file 9 | 10 | plugin.org.danbrough.kotlinxtras.core=0.0.3-beta16 11 | 12 | version.kotlin=1.8.20 13 | 14 | version.org.danbrough..klog=0.0.2-beta02 15 | 16 | ## unused 17 | version.org.danbrough.kotlinx..kotlinx-coroutines-core=1.6.4 18 | 19 | version.org.danbrough.kotlinxtras..common=0.0.1-beta01 20 | -------------------------------------------------------------------------------- /demos/libssh2/.gitignore: -------------------------------------------------------------------------------- 1 | tmp/ 2 | -------------------------------------------------------------------------------- /demos/libssh2/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.danbrough.kotlinxtras.core.enableCurl 2 | import org.danbrough.kotlinxtras.core.enableLibSSH2 3 | import org.danbrough.kotlinxtras.core.enableOpenssl3 4 | 5 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 6 | import org.jetbrains.kotlin.konan.target.HostManager 7 | 8 | plugins { 9 | alias(libs.plugins.kotlinMultiplatform) 10 | alias(libs.plugins.kotlinXtras) 11 | } 12 | 13 | 14 | repositories { 15 | maven("/usr/local/kotlinxtras/build/xtras/maven") 16 | maven("https://s01.oss.sonatype.org/content/groups/staging") 17 | mavenCentral() 18 | } 19 | 20 | val openSSL = enableOpenssl3() 21 | 22 | enableLibSSH2(openSSL) { 23 | 24 | cinterops { 25 | interopsPackage = "libssh2" 26 | 27 | headersSource = """ 28 | void print_test(char** msg){ 29 | printf("print_test(): <%s>\n",*msg); 30 | } 31 | void ptr_test(char** msg){ 32 | *msg = "Message from C!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; 33 | 34 | /**msg = malloc(256); 35 | memset(*msg,0,256); 36 | strncpy(*msg,"Hello World and stuff",44);*/ 37 | } 38 | 39 | void ptr_free(char** msg){ 40 | printf("doing a free\n"); 41 | free(*msg); 42 | } 43 | """.trimIndent() 44 | } 45 | } 46 | 47 | 48 | 49 | kotlin { 50 | 51 | linuxX64() 52 | linuxArm64() 53 | 54 | if (HostManager.hostIsMac) { 55 | macosX64() 56 | macosArm64() 57 | } 58 | 59 | //androidNativeX86() 60 | 61 | val commonMain by sourceSets.getting { 62 | dependencies { 63 | implementation(libs.klog) 64 | implementation(libs.org.danbrough.kotlinxtras.common) 65 | implementation(libs.org.danbrough.kotlinxtras.utils) 66 | 67 | //implementation(libs.io.ktor.ktorutils) 68 | } 69 | } 70 | 71 | val posixMain by sourceSets.creating { 72 | dependsOn(commonMain) 73 | } 74 | 75 | targets.withType { 76 | 77 | compilations["main"].apply { 78 | defaultSourceSet.dependsOn(posixMain) 79 | } 80 | 81 | binaries { 82 | executable("ssh2Demo") { 83 | entryPoint = "demo.ssh2.main" 84 | findProperty("args")?.also { 85 | runTask?.args(it.toString().split(',')) 86 | } 87 | } 88 | 89 | executable("hexDemo") { 90 | entryPoint = "demo.hex.main" 91 | findProperty("args")?.also { 92 | runTask?.args(it.toString()) 93 | } 94 | } 95 | 96 | } 97 | } 98 | } 99 | 100 | 101 | 102 | tasks.create("runCurl") { 103 | dependsOn("runCurlDemoDebugExecutable${if (HostManager.hostIsMac) "MacosX64" else "LinuxX64"}") 104 | } 105 | -------------------------------------------------------------------------------- /demos/libssh2/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.mpp.stability.nowarn=true 2 | org.gradle.daemon=true 3 | org.gradle.jvmargs=-XX\:MaxMetaspaceSize\=1G -Xmx2048m -Xss32m 4 | android.useAndroidX=true 5 | android.enableJetifier=true 6 | kotlin.code.style=official 7 | kotlin.mpp.enableCInteropCommonization=true 8 | android.disableAutomaticComponentCreation=true 9 | kotlin.native.binary.memoryModel=experimental 10 | 11 | 12 | org.gradle.caching=true 13 | org.gradle.unsafe.configuration-cache=false 14 | 15 | #xtras.dir.maven=/usr/local/kotlinxtras/build/xtras/maven 16 | 17 | kotlin.native.cacheKind.linuxX64=none 18 | #comment out to defer to only gradle logging 19 | xtras.log.stdout=true 20 | -------------------------------------------------------------------------------- /demos/libssh2/gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | ## Generated by $ ./gradlew refreshVersionsCatalog 2 | 3 | [plugins] 4 | 5 | kotlinXtras = { id = "org.danbrough.kotlinxtras.core", version.ref = "kotlinXtras" } 6 | kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } 7 | 8 | [versions] 9 | 10 | kotlin = "1.9.0" 11 | kotlinXtras = "0.0.3-beta17" 12 | ktor = "2.3.3" 13 | 14 | [libraries] 15 | 16 | klog = "org.danbrough:klog:0.0.2-beta03" 17 | 18 | org-danbrough-kotlinxtras-common = "org.danbrough.kotlinxtras:common:0.0.1-beta01" 19 | org-danbrough-kotlinxtras-utils = "org.danbrough.kotlinxtras:utils:0.0.1-beta01" 20 | io-ktor-ktorutils = { group = "io.ktor", name = "ktor-utils", version.ref = "ktor" } 21 | 22 | kotlin-scripting-compiler-embeddable = { group = "org.jetbrains.kotlin", name = "kotlin-scripting-compiler-embeddable", version.ref = "kotlin" } 23 | -------------------------------------------------------------------------------- /demos/libssh2/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/demos/libssh2/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/libssh2/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /demos/libssh2/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /demos/libssh2/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | @file:Suppress("UnstableApiUsage") 2 | 3 | pluginManagement { 4 | 5 | repositories { 6 | maven("/usr/local/kotlinxtras/build/xtras/maven") 7 | 8 | 9 | maven("https://s01.oss.sonatype.org/content/groups/staging") 10 | mavenCentral() 11 | 12 | gradlePluginPortal() 13 | 14 | google() 15 | } 16 | 17 | 18 | } 19 | 20 | 21 | plugins { 22 | id("de.fayard.refreshVersions") version "0.51.0" 23 | } 24 | 25 | 26 | rootProject.name = "libssh2_demo" 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /demos/libssh2/src/posixMain/kotlin/demo/hex/Main.kt: -------------------------------------------------------------------------------- 1 | package demo.hex 2 | 3 | import demo.log 4 | import kotlinx.cinterop.ByteVar 5 | import kotlinx.cinterop.CPointerVar 6 | import kotlinx.cinterop.ExperimentalForeignApi 7 | import kotlinx.cinterop.cValue 8 | import kotlinx.cinterop.cstr 9 | import kotlinx.cinterop.get 10 | import kotlinx.cinterop.memScoped 11 | import kotlinx.cinterop.set 12 | import kotlinx.cinterop.toKString 13 | 14 | @OptIn(ExperimentalForeignApi::class) 15 | fun main() { 16 | log.debug("main()") 17 | memScoped { 18 | 19 | val msg = "Hello World!" 20 | val p = cValue>().ptr 21 | p[0] = msg.cstr.ptr 22 | 23 | println("m: ${p[0]?.toKString()}") 24 | libssh2.print_test(p) 25 | libssh2.ptr_test(p) 26 | libssh2.print_test(p) 27 | //libssh2.ptr_free(p) 28 | 29 | 30 | } 31 | } -------------------------------------------------------------------------------- /demos/libssh2/src/posixMain/kotlin/demo/hex/Main2.kt: -------------------------------------------------------------------------------- 1 | package demo.hex 2 | 3 | import demo.log 4 | import kotlinx.cinterop.ByteVar 5 | import kotlinx.cinterop.CPointerVar 6 | import kotlinx.cinterop.ExperimentalForeignApi 7 | import kotlinx.cinterop.cValue 8 | import kotlinx.cinterop.get 9 | import kotlinx.cinterop.memScoped 10 | import kotlinx.cinterop.toKString 11 | import libssh2.ptr_test 12 | import org.danbrough.utils.io.fromBase64 13 | import org.danbrough.utils.io.fromHex 14 | import org.danbrough.utils.io.toBase64 15 | import org.danbrough.utils.io.toHex 16 | 17 | 18 | fun base64Test(bytes: ByteArray) { 19 | val b64 = bytes.toBase64() 20 | log.debug("b64: $b64") 21 | val bytes2 = b64.fromBase64() 22 | log.debug("same: ${bytes.contentEquals(bytes2)}") 23 | } 24 | 25 | 26 | fun hexTest(bytes: ByteArray) { 27 | bytes.toHex().also { hexString -> 28 | log.debug("HEX: $hexString") 29 | hexString.fromHex().also { 30 | if (!it.contentEquals(bytes)) error("Content not equal") 31 | } 32 | } 33 | } 34 | 35 | 36 | @OptIn(ExperimentalForeignApi::class) 37 | fun main2(args: Array) { 38 | log.info("hexDemo..") 39 | /* 40 | hexTest(byteArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 255.toByte())) 41 | hexTest(Random.nextBytes(128)) 42 | 43 | val msg = "Cabbaqes and Kings!" 44 | base64Test(msg.encodeToByteArray()) 45 | base64Test(Random.nextBytes(1024))*/ 46 | //CValuesRef> 47 | 48 | memScoped { 49 | //val p = cValue>() 50 | val p = cValue>() 51 | ptr_test(p.ptr) 52 | println("kotlin message:<${p.ptr[0]?.toKString()}>") 53 | } 54 | 55 | 56 | } -------------------------------------------------------------------------------- /demos/libssh2/src/posixMain/kotlin/demo/logging.kt: -------------------------------------------------------------------------------- 1 | package demo 2 | 3 | import klog.KLogWriters 4 | import klog.KMessageFormatters 5 | import klog.Level 6 | import klog.colored 7 | 8 | val log = klog.klog("demo") { 9 | writer = KLogWriters.stdOut 10 | messageFormatter = KMessageFormatters.verbose.colored 11 | level = Level.TRACE 12 | } 13 | -------------------------------------------------------------------------------- /demos/libssh2/ssh2Demo.kexe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/demos/libssh2/ssh2Demo.kexe -------------------------------------------------------------------------------- /demos/libssh2/versions.properties: -------------------------------------------------------------------------------- 1 | #### Dependencies and Plugin versions with their available updates. 2 | #### Generated by `./gradlew refreshVersions` version 0.51.0 3 | #### 4 | #### Don't manually edit or split the comments that start with four hashtags (####), 5 | #### they will be overwritten by refreshVersions. 6 | #### 7 | #### suppress inspection "SpellCheckingInspection" for whole file 8 | #### suppress inspection "UnusedProperty" for whole file 9 | -------------------------------------------------------------------------------- /demos/repos/datetime/README.md: -------------------------------------------------------------------------------- 1 | # Curl demo 2 | 3 | This demo uses the org.danbrough.kotlinxtras:curl library to compile a curl demo. 4 | It expects precompiled curl and openssl at /usr/local/kotlinxtras/libs/curl,openssl but might 5 | work with your system versions. 6 | See the (curl standalone)[../curl_standalone/] for this demo that downloads precompiled binaries to link against. 7 | 8 | The cacert.pem file is from: http://curl.haxx.se/ca/cacert.pem 9 | 10 | You need to specify it in the environment variable "CA_CERT_FILE" the path to this. 11 | If it complains that libcrypt.so.1 is missing then you will need libxcrypt-compat. 12 | Run the demo with: 13 | ```bash 14 | ./gradlew runDemo1DebugExecutableMacosX64 (loads example.com) 15 | # or 16 | ./gradlew runDemo1DebugExecutableMacosX64 -Purl=https://python.org 17 | # or 18 | ./gradlew runDemo1DebugExecutableMacosArm64 -Purl=https://python.org 19 | ./gradlew runDemo1DebugExecutableLinuxX64 -Purl=https://python.org 20 | 21 | # or link the binary to run somewhere else: 22 | ./gradlew linkDemo1DebugExecutableLinuxArm32Hfp 23 | ./gradlew linkDemo1DebugExecutableAndroidArm32 24 | 25 | ``` 26 | 27 | -------------------------------------------------------------------------------- /demos/repos/datetime/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 2 | 3 | plugins { 4 | kotlin("multiplatform") 5 | } 6 | 7 | 8 | repositories { 9 | mavenLocal() 10 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 11 | mavenCentral() 12 | } 13 | 14 | 15 | kotlin { 16 | 17 | linuxX64() 18 | linuxArm64() 19 | linuxArm32Hfp() 20 | androidNativeX86() 21 | androidNativeX64() 22 | androidNativeArm32() 23 | androidNativeArm64() 24 | macosArm64() 25 | macosX64() 26 | 27 | val commonMain by sourceSets.getting { 28 | dependencies { 29 | implementation(libs.klog) 30 | implementation(libs.kotlinx.datetime) 31 | } 32 | } 33 | 34 | val nativeMain by sourceSets.creating { 35 | dependsOn(commonMain) 36 | } 37 | 38 | targets.withType().all { 39 | 40 | compilations["main"].apply { 41 | defaultSourceSet.dependsOn(nativeMain) 42 | // cinterops.create("demo"){ 43 | // defFile(file("src/demo.def")) 44 | // } 45 | } 46 | 47 | binaries { 48 | executable("datetimeDemo") { 49 | entryPoint = "demo1.main" 50 | } 51 | } 52 | } 53 | 54 | 55 | } 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /demos/repos/datetime/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.mpp.stability.nowarn=true 2 | org.gradle.daemon=true 3 | org.gradle.jvmargs=-XX\:MaxMetaspaceSize\=1G -Xmx2048m -Xss32m 4 | android.useAndroidX=true 5 | android.enableJetifier=true 6 | kotlin.code.style=official 7 | kotlin.mpp.enableCInteropCommonization=true 8 | android.disableAutomaticComponentCreation=true 9 | kotlin.native.binary.memoryModel=experimental 10 | kotlin.native.ignoreDisabledTargets=false 11 | 12 | # These properties can be overriden in local.properties. 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /demos/repos/datetime/gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | ## Generated by $ ./gradlew refreshVersionsCatalog 2 | 3 | [plugins] 4 | 5 | org-jetbrains-kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version = "1.7.21" } 6 | 7 | [versions] 8 | 9 | kotlin = "1.7.21" 10 | xtras = "0.0.2-beta01" 11 | 12 | [libraries] 13 | 14 | klog = "org.danbrough:klog:0.0.2-beta01" 15 | ## ⬆ :0.0.2-beta02" 16 | 17 | kotlin-scripting-compiler-embeddable = { group = "org.jetbrains.kotlin", name = "kotlin-scripting-compiler-embeddable", version.ref = "kotlin" } 18 | 19 | kotlinx-datetime = "org.danbrough.kotlinx:kotlinx-datetime:0.4.0c" 20 | ## ⬆ :0.4.0d" 21 | ## ⬆ :0.4.0" 22 | -------------------------------------------------------------------------------- /demos/repos/datetime/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/demos/repos/datetime/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/repos/datetime/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /demos/repos/datetime/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /demos/repos/datetime/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | 3 | repositories { 4 | gradlePluginPortal() 5 | mavenCentral() 6 | google() 7 | } 8 | } 9 | 10 | 11 | plugins { 12 | id("de.fayard.refreshVersions") version "0.51.0" 13 | } 14 | 15 | 16 | 17 | rootProject.name = "datetime" 18 | 19 | -------------------------------------------------------------------------------- /demos/repos/datetime/src/nativeMain/kotlin/demo1/Main.kt: -------------------------------------------------------------------------------- 1 | package demo1 2 | 3 | import klog.KLogWriters 4 | import klog.KMessageFormatters 5 | import klog.Level 6 | import klog.colored 7 | import kotlinx.datetime.Clock 8 | 9 | 10 | val log = klog.klog("demo1") { 11 | writer = KLogWriters.stdOut 12 | messageFormatter = KMessageFormatters.verbose.colored 13 | level = Level.TRACE 14 | } 15 | 16 | 17 | fun main(args: Array) { 18 | log.info("running main ..") 19 | 20 | val currentMoment = Clock.System.now() 21 | log.debug("currentMoment: $currentMoment") 22 | 23 | //wow .. exciting. 24 | //shows that it works though .. (or doesn't) 25 | //feel free to make this demo more interesting 26 | // dan. 27 | 28 | 29 | } -------------------------------------------------------------------------------- /demos/repos/datetime/versions.properties: -------------------------------------------------------------------------------- 1 | #### Dependencies and Plugin versions with their available updates. 2 | #### Generated by `./gradlew refreshVersions` version 0.51.0 3 | #### 4 | #### Don't manually edit or split the comments that start with four hashtags (####), 5 | #### they will be overwritten by refreshVersions. 6 | #### 7 | #### suppress inspection "SpellCheckingInspection" for whole file 8 | #### suppress inspection "UnusedProperty" for whole file 9 | 10 | version.kotlin=1.8.10 11 | -------------------------------------------------------------------------------- /demos/repos/ktor/README.md: -------------------------------------------------------------------------------- 1 | # Ktor demo 2 | 3 | To compile run the client demo: `./gradlew linkDemo1DebugExecutableLinuxArm32Hfp` (or 4 | linkDemo1DebugExecutableLinuxArm64 etc ..) 5 | in this directory. 6 | 7 | There is also `./gradlew linkDemo2DebugExecutableLinuxArm32Hfp` which is a server demo. 8 | 9 | To test on linuxX64 run `./gradlew runDemo1DebugExecutableLinuxX64` 10 | or `./gradlew runDemo2DebugExecutableLinuxX64` 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /demos/repos/ktor/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.danbrough.kotlinxtras.core.enableCurl 2 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 3 | 4 | 5 | plugins { 6 | kotlin("multiplatform") 7 | id("org.danbrough.kotlinxtras.core") 8 | } 9 | 10 | 11 | enableCurl { 12 | 13 | } 14 | 15 | repositories { 16 | maven("/usr/local/kotlinxtras/build/xtras/maven") 17 | maven("https://s01.oss.sonatype.org/content/groups/staging") 18 | mavenCentral() 19 | } 20 | 21 | 22 | kotlin { 23 | 24 | linuxX64() 25 | linuxArm64() 26 | linuxArm32Hfp() 27 | macosX64() 28 | 29 | 30 | /** //uncomment if you want android support 31 | androidNativeX86() 32 | androidNativeX64() 33 | androidNativeArm32() 34 | androidNativeArm64() 35 | 36 | **/ 37 | 38 | //add your other apple targets 39 | 40 | 41 | val commonMain by sourceSets.getting { 42 | dependencies { 43 | implementation("org.danbrough:klog:_") 44 | implementation("org.danbrough.ktor:ktor-client-curl:_") 45 | 46 | implementation("org.danbrough.kotlinx:kotlinx-coroutines-core:_") 47 | implementation("org.danbrough.ktor:ktor-server-cio:_") 48 | implementation("org.danbrough.kotlinx:kotlinx-datetime:_") 49 | 50 | } 51 | } 52 | 53 | 54 | val nativeMain by sourceSets.creating { 55 | dependsOn(commonMain) 56 | } 57 | 58 | targets.withType().all { 59 | 60 | compilations["main"].apply { 61 | defaultSourceSet.dependsOn(nativeMain) 62 | } 63 | 64 | binaries { 65 | executable("demo1") { 66 | entryPoint = "demo1.main" 67 | } 68 | executable("demo2") { 69 | entryPoint = "demo2.main" 70 | } 71 | } 72 | } 73 | } 74 | 75 | 76 | -------------------------------------------------------------------------------- /demos/repos/ktor/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.mpp.stability.nowarn=true 2 | org.gradle.daemon=true 3 | org.gradle.jvmargs=-XX\:MaxMetaspaceSize\=1G -Xmx2048m -Xss32m 4 | android.useAndroidX=true 5 | android.enableJetifier=true 6 | kotlin.code.style=official 7 | kotlin.mpp.enableCInteropCommonization=true 8 | android.disableAutomaticComponentCreation=true 9 | kotlin.native.binary.memoryModel=experimental 10 | kotlin.native.ignoreDisabledTargets=false 11 | 12 | # These properties can be overriden in local.properties. 13 | 14 | go.binary=/usr/bin/go 15 | 16 | # replace org.jetbrains .. etc in maven publishing with $project.group 17 | project.group=org.danbrough 18 | 19 | build.path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/opt/local/bin 20 | 21 | 22 | -------------------------------------------------------------------------------- /demos/repos/ktor/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/demos/repos/ktor/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/repos/ktor/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /demos/repos/ktor/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /demos/repos/ktor/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | 3 | repositories { 4 | maven("/usr/local/kotlinxtras/build/xtras/maven") 5 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 6 | gradlePluginPortal() 7 | mavenCentral() 8 | } 9 | } 10 | 11 | 12 | plugins { 13 | id("de.fayard.refreshVersions") version "0.51.0" 14 | } 15 | 16 | 17 | 18 | rootProject.name = "ktor_demo" 19 | 20 | -------------------------------------------------------------------------------- /demos/repos/ktor/src/commonMain/kotlin/demo1/Main.kt: -------------------------------------------------------------------------------- 1 | package demo1 2 | 3 | -------------------------------------------------------------------------------- /demos/repos/ktor/src/nativeMain/kotlin/demo1/Main.kt: -------------------------------------------------------------------------------- 1 | package demo1 2 | 3 | import io.ktor.client.* 4 | import io.ktor.client.engine.* 5 | import io.ktor.client.engine.curl.* 6 | import io.ktor.client.request.* 7 | import io.ktor.client.statement.* 8 | import klog.KLogWriters 9 | import klog.KMessageFormatters 10 | import klog.Level 11 | import klog.colored 12 | import kotlinx.coroutines.runBlocking 13 | 14 | 15 | private val log = klog.klog("demo1") { 16 | level = Level.TRACE 17 | writer = KLogWriters.stdOut 18 | messageFormatter = KMessageFormatters.verbose.colored 19 | } 20 | 21 | suspend fun runClient(engine: HttpClientEngine,url:String) { 22 | val client = HttpClient(engine) 23 | try { 24 | val response = client.get(url) 25 | log.debug(response.bodyAsText()) 26 | } finally { 27 | // To prevent IllegalStateException https://youtrack.jetbrains.com/issue/KTOR-1071 28 | client.close() 29 | engine.close() 30 | } 31 | } 32 | 33 | fun main(args: Array) { 34 | val url = if (args.size == 0) "https://example.com" else args[0] 35 | log.debug("running demo1: url: $url") 36 | 37 | runBlocking { 38 | Platform.isMemoryLeakCheckerActive = false 39 | 40 | runClient(Curl.create(),url) 41 | } 42 | } -------------------------------------------------------------------------------- /demos/repos/ktor/src/nativeMain/kotlin/demo2/Main.kt: -------------------------------------------------------------------------------- 1 | package demo2 2 | 3 | import io.ktor.client.* 4 | import io.ktor.client.engine.* 5 | import io.ktor.client.engine.curl.* 6 | import io.ktor.client.request.* 7 | import io.ktor.client.statement.* 8 | import io.ktor.server.application.* 9 | import io.ktor.server.cio.* 10 | import io.ktor.server.engine.* 11 | import io.ktor.server.response.* 12 | import io.ktor.server.routing.* 13 | import klog.KLogWriters 14 | import klog.KMessageFormatters 15 | import klog.Level 16 | import klog.colored 17 | import kotlinx.coroutines.runBlocking 18 | import kotlinx.datetime.* 19 | 20 | 21 | fun main(args: Array) { 22 | val log = klog.klog("demo2") { 23 | level = Level.TRACE 24 | writer = KLogWriters.stdOut 25 | messageFormatter = KMessageFormatters.verbose.colored 26 | } 27 | 28 | 29 | embeddedServer(CIO, port = 8080) { 30 | routing { 31 | get("/") { 32 | log.trace("processing request: ${call.request}") 33 | call.respondText("Hello world at ${Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())}\n") 34 | } 35 | } 36 | }.start(wait = true) 37 | } -------------------------------------------------------------------------------- /demos/repos/ktor/versions.properties: -------------------------------------------------------------------------------- 1 | #### Dependencies and Plugin versions with their available updates. 2 | #### Generated by `./gradlew refreshVersions` version 0.51.0 3 | #### 4 | #### Don't manually edit or split the comments that start with four hashtags (####), 5 | #### they will be overwritten by refreshVersions. 6 | #### 7 | #### suppress inspection "SpellCheckingInspection" for whole file 8 | #### suppress inspection "UnusedProperty" for whole file 9 | 10 | plugin.org.danbrough.kotlinxtras.core=0.0.3-beta14 11 | 12 | 13 | 14 | version.kotlin=1.8.10 15 | ## # available=1.8.20-Beta 16 | ## # available=1.8.20-RC 17 | 18 | version.org.danbrough.ktor..ktor-server-cio=2.2.4 19 | 20 | version.org.danbrough.ktor..ktor-client-curl=2.2.4 21 | 22 | 23 | version.org.danbrough.kotlinx..kotlinx-datetime=0.4.0d 24 | ## # available=0.4.0 25 | 26 | version.org.danbrough.kotlinx..kotlinx-coroutines-core=1.6.4 27 | 28 | 29 | version.org.danbrough..klog=0.0.2-beta02 30 | -------------------------------------------------------------------------------- /demos/repos/okio/.gitignore: -------------------------------------------------------------------------------- 1 | c_demo 2 | -------------------------------------------------------------------------------- /demos/repos/okio/README.md: -------------------------------------------------------------------------------- 1 | # Okio demo 2 | 3 | To compile run `./gradlew linkDemo1DebugExecutableLinuxArm32Hfp` (or 4 | linkDemo1DebugExecutableLinuxArm64) 5 | in this directory. 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /demos/repos/okio/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 2 | 3 | 4 | plugins { 5 | kotlin("multiplatform") 6 | // id("org.danbrough.kotlinxtras.consumer") 7 | } 8 | 9 | 10 | 11 | repositories { 12 | mavenLocal() 13 | //maven("/usr/local/kotlinxtras/build/m2") 14 | maven("https://s01.oss.sonatype.org/content/groups/staging") 15 | mavenCentral() 16 | } 17 | 18 | 19 | 20 | kotlin { 21 | 22 | 23 | linuxX64() 24 | linuxArm64() 25 | linuxArm32Hfp() 26 | androidNativeX86() 27 | 28 | if (org.jetbrains.kotlin.konan.target.HostManager.Companion.hostIsMac) { 29 | macosX64() 30 | macosArm64() 31 | } 32 | 33 | /** //uncomment if you want android support 34 | androidNativeX86() 35 | androidNativeX64() 36 | androidNativeArm32() 37 | androidNativeArm64() 38 | 39 | **/ 40 | 41 | //add your other apple targets 42 | 43 | 44 | val commonMain by sourceSets.getting { 45 | dependencies { 46 | implementation("org.danbrough:klog:_") 47 | implementation("org.danbrough.okio:okio:_") 48 | implementation("org.danbrough.okio:okio-fakefilesystem:_") 49 | 50 | } 51 | } 52 | 53 | val nativeMain by sourceSets.creating { 54 | dependsOn(commonMain) 55 | } 56 | 57 | 58 | targets.withType().all { 59 | 60 | compilations["main"].apply { 61 | defaultSourceSet.dependsOn(nativeMain) 62 | } 63 | 64 | binaries { 65 | executable("hashing") { 66 | entryPoint = "okio.samples.main" 67 | runTask?.workingDir = project.projectDir 68 | } 69 | } 70 | 71 | } 72 | } 73 | 74 | -------------------------------------------------------------------------------- /demos/repos/okio/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.mpp.stability.nowarn=true 2 | org.gradle.daemon=true 3 | org.gradle.jvmargs=-XX\:MaxMetaspaceSize\=1G -Xmx2048m -Xss32m 4 | android.useAndroidX=true 5 | android.enableJetifier=true 6 | kotlin.code.style=official 7 | kotlin.mpp.enableCInteropCommonization=true 8 | android.disableAutomaticComponentCreation=true 9 | kotlin.native.binary.memoryModel=experimental 10 | kotlin.native.ignoreDisabledTargets=false 11 | 12 | # These properties can be overriden in local.properties. 13 | 14 | go.binary=/usr/bin/go 15 | 16 | # replace org.jetbrains .. etc in maven publishing with $project.group 17 | project.group=org.danbrough 18 | 19 | build.path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/opt/local/bin 20 | 21 | 22 | -------------------------------------------------------------------------------- /demos/repos/okio/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/demos/repos/okio/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/repos/okio/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /demos/repos/okio/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /demos/repos/okio/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | 3 | repositories { 4 | maven("/usr/local/kotlinxtras/build/m2") 5 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 6 | gradlePluginPortal() 7 | mavenCentral() 8 | } 9 | } 10 | 11 | 12 | plugins { 13 | id("de.fayard.refreshVersions") version "0.51.0" 14 | } 15 | 16 | 17 | 18 | rootProject.name = "okio_demo" 19 | 20 | -------------------------------------------------------------------------------- /demos/repos/okio/src/androidNativeX86Main/kotlin/Test.kt: -------------------------------------------------------------------------------- 1 | import platform.posix.closedir 2 | import platform.posix.fopen 3 | 4 | fun test(){ 5 | //fopen("") 6 | 7 | } -------------------------------------------------------------------------------- /demos/repos/okio/src/nativeMain/kotlin/okio/samples/Hashing.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Square, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package okio.samples 17 | 18 | import okio.Buffer 19 | import okio.ByteString 20 | import okio.ByteString.Companion.decodeHex 21 | import okio.HashingSink.Companion.sha256 22 | import okio.HashingSource.Companion.sha256 23 | import okio.Path 24 | import okio.Path.Companion.toPath 25 | import okio.blackholeSink 26 | import okio.buffer 27 | import okio.fakefilesystem.FakeFileSystem 28 | import okio.use 29 | 30 | class KotlinHashing { 31 | private val fileSystem = FakeFileSystem() 32 | 33 | fun run() { 34 | val path = "testFile.txt".toPath() 35 | val testContent = "Hello World" 36 | 37 | fileSystem.sink(path,true).use {sink-> 38 | testContent.encodeToByteArray().also { bytes-> 39 | Buffer().write(bytes).also { 40 | sink.write(it,it.size) 41 | } 42 | } 43 | } 44 | 45 | fileSystem.source(path).buffer().use { 46 | println("TEST CONTENT: ${it.readUtf8Line()}") 47 | } 48 | 49 | println("ByteString") 50 | val byteString = readByteString(path) 51 | println(" md5: " + byteString.md5().hex()) 52 | println(" sha1: " + byteString.sha1().hex()) 53 | println(" sha256: " + byteString.sha256().hex()) 54 | println(" sha512: " + byteString.sha512().hex()) 55 | println() 56 | 57 | println("Buffer") 58 | val buffer = readBuffer(path) 59 | println(" md5: " + buffer.md5().hex()) 60 | println(" sha1: " + buffer.sha1().hex()) 61 | println(" sha256: " + buffer.sha256().hex()) 62 | println(" sha512: " + buffer.sha512().hex()) 63 | println() 64 | 65 | println("HashingSource") 66 | sha256(fileSystem.source(path)).use { hashingSource -> 67 | hashingSource.buffer().use { source -> 68 | source.readAll(blackholeSink()) 69 | println(" sha256: " + hashingSource.hash.hex()) 70 | } 71 | } 72 | println() 73 | 74 | println("HashingSink") 75 | sha256(blackholeSink()).use { hashingSink -> 76 | hashingSink.buffer().use { sink -> 77 | fileSystem.source(path).use { source -> 78 | sink.writeAll(source) 79 | sink.close() // Emit anything buffered. 80 | println(" sha256: " + hashingSink.hash.hex()) 81 | } 82 | } 83 | } 84 | println() 85 | 86 | println("HMAC") 87 | val secret = "7065616e7574627574746572".decodeHex() 88 | println("hmacSha256: " + byteString.hmacSha256(secret).hex()) 89 | println() 90 | } 91 | 92 | private fun readByteString(path: Path): ByteString =fileSystem.read(path) { readByteString() } 93 | 94 | 95 | private fun readBuffer(path: Path): Buffer { 96 | return fileSystem.read(path) { 97 | val result = Buffer() 98 | readAll(result) 99 | result 100 | } 101 | } 102 | } 103 | 104 | fun main() { 105 | KotlinHashing().run() 106 | } 107 | -------------------------------------------------------------------------------- /demos/repos/okio/versions.properties: -------------------------------------------------------------------------------- 1 | #### Dependencies and Plugin versions with their available updates. 2 | #### Generated by `./gradlew refreshVersions` version 0.51.0 3 | #### 4 | #### Don't manually edit or split the comments that start with four hashtags (####), 5 | #### they will be overwritten by refreshVersions. 6 | #### 7 | #### suppress inspection "SpellCheckingInspection" for whole file 8 | #### suppress inspection "UnusedProperty" for whole file 9 | version.kotlin=1.8.10 10 | ## # available=1.8.20-Beta 11 | ## # available=1.8.20-RC 12 | version.org.danbrough.okio..okio-fakefilesystem=3.3.0-alpha01 13 | version.org.danbrough.okio..okio=3.3.0-alpha01 14 | version.org.danbrough..klog=0.0.2-beta02 15 | -------------------------------------------------------------------------------- /demos/repos/sqldelight/.gitignore: -------------------------------------------------------------------------------- 1 | *.db 2 | *.db-wal 3 | *.db-shm 4 | -------------------------------------------------------------------------------- /demos/repos/sqldelight/README.md: -------------------------------------------------------------------------------- 1 | # SqlDelight demo 2 | 3 | Not working 4 | 5 | -------------------------------------------------------------------------------- /demos/repos/sqldelight/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 2 | import org.danbrough.kotlinxtras.core.enableSqlite 3 | 4 | plugins { 5 | kotlin("multiplatform") 6 | id("org.danbrough.kotlinxtras.core") 7 | id("org.danbrough.sqldelight") 8 | } 9 | 10 | 11 | enableSqlite {} 12 | 13 | 14 | 15 | repositories { 16 | maven("/usr/local/kotlinxtras/build/m2") 17 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 18 | maven("https://www.jetbrains.com/intellij-repository/releases") 19 | maven("https://cache-redirector.jetbrains.com/intellij-dependencies") 20 | 21 | google() 22 | mavenCentral() 23 | } 24 | 25 | sqldelight { 26 | database("Database") { 27 | packageName = "demo" 28 | } 29 | } 30 | 31 | kotlin { 32 | 33 | linuxX64() 34 | linuxArm64() 35 | linuxArm32Hfp() 36 | androidNativeX86() 37 | 38 | val commonMain by sourceSets.getting { 39 | dependencies { 40 | implementation("org.danbrough.kotlinxtras:sqlite:_") 41 | implementation("org.danbrough.sqldelight:primitive-adapters:_") 42 | implementation("org.danbrough.sqldelight:runtime:_") 43 | } 44 | } 45 | 46 | 47 | val nativeMain by sourceSets.creating { 48 | dependencies { 49 | dependsOn(commonMain) 50 | implementation("org.danbrough.sqldelight:native-driver:_") 51 | } 52 | } 53 | 54 | 55 | targets.withType(KotlinNativeTarget::class) { 56 | compilations["main"].apply { 57 | defaultSourceSet.dependsOn(nativeMain) 58 | } 59 | 60 | binaries { 61 | executable("demo1") { 62 | entryPoint("demo.main") 63 | } 64 | } 65 | } 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /demos/repos/sqldelight/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.mpp.stability.nowarn=true 2 | org.gradle.daemon=true 3 | org.gradle.jvmargs=-XX\:MaxMetaspaceSize\=1G -Xmx2048m -Xss32m 4 | android.useAndroidX=true 5 | android.enableJetifier=true 6 | kotlin.code.style=official 7 | kotlin.mpp.enableCInteropCommonization=true 8 | android.disableAutomaticComponentCreation=true 9 | kotlin.native.binary.memoryModel=experimental 10 | kotlin.native.ignoreDisabledTargets=false 11 | 12 | # These properties can be overriden in local.properties. 13 | 14 | go.binary=/usr/bin/go 15 | 16 | # replace org.jetbrains .. etc in maven publishing with $project.group 17 | project.group=org.danbrough 18 | 19 | build.path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/opt/local/bin 20 | 21 | 22 | # to prevent weird linking errors 23 | kotlin.native.cacheKind=none -------------------------------------------------------------------------------- /demos/repos/sqldelight/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/demos/repos/sqldelight/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/repos/sqldelight/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /demos/repos/sqldelight/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /demos/repos/sqldelight/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | 3 | repositories { 4 | maven("/usr/local/kotlinxtras/build/m2") 5 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 6 | maven("https://www.jetbrains.com/intellij-repository/releases") 7 | maven("https://cache-redirector.jetbrains.com/intellij-dependencies") 8 | gradlePluginPortal() 9 | mavenCentral() 10 | google() 11 | } 12 | } 13 | 14 | 15 | plugins { 16 | id("de.fayard.refreshVersions") version "0.51.0" 17 | 18 | } 19 | 20 | 21 | 22 | rootProject.name = "sqldelight_demo" 23 | 24 | -------------------------------------------------------------------------------- /demos/repos/sqldelight/src/commonMain/kotlin/demo/common.kt: -------------------------------------------------------------------------------- 1 | package demo 2 | 3 | import app.cash.sqldelight.db.SqlDriver 4 | 5 | expect class DriverFactory { 6 | fun createDriver(): SqlDriver 7 | } 8 | 9 | fun createDatabase(driverFactory:DriverFactory): Database { 10 | val driver = driverFactory.createDriver() 11 | return Database(driver) 12 | } 13 | -------------------------------------------------------------------------------- /demos/repos/sqldelight/src/commonMain/sqldelight/demo/db/Player.sq: -------------------------------------------------------------------------------- 1 | CREATE TABLE hockeyPlayer ( 2 | player_number INTEGER NOT NULL, 3 | full_name TEXT NOT NULL 4 | ); 5 | 6 | CREATE INDEX hockeyPlayer_full_name ON hockeyPlayer(full_name); 7 | 8 | INSERT INTO hockeyPlayer (player_number, full_name) 9 | VALUES (15, 'Ryan Getzlaf'); 10 | INSERT INTO hockeyPlayer (player_number, full_name) 11 | VALUES (16, 'Dhyan Chand'); 12 | 13 | selectAll: 14 | SELECT * 15 | FROM hockeyPlayer; 16 | 17 | insert: 18 | INSERT INTO hockeyPlayer(player_number, full_name) 19 | VALUES (?, ?); 20 | 21 | insertFullPlayerObject: 22 | INSERT INTO hockeyPlayer(player_number, full_name) 23 | VALUES ?; -------------------------------------------------------------------------------- /demos/repos/sqldelight/src/nativeMain/kotlin/demo/Demo1.kt: -------------------------------------------------------------------------------- 1 | package demo 2 | 3 | import demo.db.HockeyPlayer 4 | import klog.* 5 | import kotlin.test.Test 6 | 7 | val log by lazy { 8 | klog("demo") { 9 | level = Level.TRACE 10 | messageFormatter = KMessageFormatters.verbose.colored 11 | writer = KLogWriters.stdOut 12 | } 13 | } 14 | 15 | 16 | fun main() { 17 | log.info("main()") 18 | val db = createDatabase(DriverFactory()) 19 | log.debug("got db: $db") 20 | 21 | val playerQueries = db.playerQueries 22 | 23 | println(playerQueries.selectAll().executeAsList()) 24 | // Prints [HockeyPlayer(15, "Ryan Getzlaf")] 25 | 26 | playerQueries.insert(player_number = 10, full_name = "Corey Perry") 27 | println(playerQueries.selectAll().executeAsList()) 28 | // Prints [HockeyPlayer(15, "Ryan Getzlaf"), HockeyPlayer(10, "Corey Perry")] 29 | 30 | val player = HockeyPlayer(10, "Ronald McDonald") 31 | playerQueries.insertFullPlayerObject(player) 32 | 33 | } 34 | -------------------------------------------------------------------------------- /demos/repos/sqldelight/src/nativeMain/kotlin/demo/native.kt: -------------------------------------------------------------------------------- 1 | package demo 2 | 3 | import app.cash.sqldelight.db.SqlDriver 4 | import app.cash.sqldelight.driver.native.NativeSqliteDriver 5 | import app.cash.sqldelight.driver.native.wrapConnection 6 | import co.touchlab.sqliter.DatabaseConfiguration 7 | 8 | 9 | actual class DriverFactory { 10 | actual fun createDriver(): SqlDriver { 11 | val schema = Database.Schema 12 | 13 | return NativeSqliteDriver( 14 | DatabaseConfiguration( 15 | name = "hockey.db", 16 | version = schema.version, 17 | extendedConfig = DatabaseConfiguration.Extended(basePath = "./"), 18 | create = { connection -> 19 | wrapConnection(connection) { schema.create(it) } 20 | }, 21 | upgrade = { connection, oldVersion, newVersion -> 22 | wrapConnection(connection) { schema.migrate(it, oldVersion, newVersion) } 23 | }, 24 | ) 25 | ) 26 | } 27 | } -------------------------------------------------------------------------------- /demos/repos/sqldelight/versions.properties: -------------------------------------------------------------------------------- 1 | #### Dependencies and Plugin versions with their available updates. 2 | #### Generated by `./gradlew refreshVersions` version 0.51.0 3 | #### 4 | #### Don't manually edit or split the comments that start with four hashtags (####), 5 | #### they will be overwritten by refreshVersions. 6 | #### 7 | #### suppress inspection "SpellCheckingInspection" for whole file 8 | #### suppress inspection "UnusedProperty" for whole file 9 | #### plugin.org.danbrough.kotlinxtras.consumer=0.0.2 10 | plugin.org.danbrough.kotlinxtras.core=0.0.3-beta14 11 | plugin.org.danbrough.sqldelight=2.0.0-alpha04 12 | version.kotlin=1.8.10 13 | ## # available=1.8.20-Beta 14 | ## # available=1.8.20-RC 15 | ## unused 16 | version.org.danbrough.sqldelight..sqlite-3-18-dialect=2.0.0-alpha04 17 | version.org.danbrough.sqldelight..runtime=2.0.0-alpha04 18 | version.org.danbrough.sqldelight..primitive-adapters=2.0.0-alpha04 19 | version.org.danbrough.sqldelight..native-driver=2.0.0-alpha04 20 | version.org.danbrough.kotlinxtras..sqlite=3.39.4a 21 | ## # available=3.39.4 22 | -------------------------------------------------------------------------------- /demos/repos/sqliter/.gitignore: -------------------------------------------------------------------------------- 1 | sqliterDemo.db 2 | -------------------------------------------------------------------------------- /demos/repos/sqliter/README.md: -------------------------------------------------------------------------------- 1 | # Sqliter demo 2 | 3 | Not working 4 | -------------------------------------------------------------------------------- /demos/repos/sqliter/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.danbrough.kotlinxtras.core.enableSqlite 2 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 3 | 4 | plugins { 5 | kotlin("multiplatform") 6 | id("org.danbrough.kotlinxtras.core") 7 | } 8 | 9 | repositories { 10 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 11 | mavenCentral() 12 | } 13 | 14 | enableSqlite() 15 | 16 | 17 | kotlin { 18 | 19 | linuxX64() 20 | linuxArm64() 21 | linuxArm32Hfp() 22 | androidNativeX86() 23 | androidNativeX64() 24 | androidNativeArm32() 25 | androidNativeArm64() 26 | macosArm64() 27 | macosX64() 28 | 29 | val commonMain by sourceSets.getting { 30 | dependencies { 31 | implementation("org.danbrough:klog:_") 32 | implementation("org.danbrough.kotlinx:kotlinx-coroutines-core:_") 33 | implementation("org.danbrough.sqldelight:native-driver:_") 34 | } 35 | } 36 | 37 | val nativeMain by sourceSets.creating { 38 | dependsOn(commonMain) 39 | } 40 | 41 | targets.withType().all { 42 | 43 | compilations["main"].apply { 44 | defaultSourceSet.dependsOn(nativeMain) 45 | } 46 | 47 | 48 | binaries { 49 | 50 | executable("demo1") { 51 | entryPoint = "demo1.main" 52 | } 53 | } 54 | } 55 | 56 | 57 | } 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /demos/repos/sqliter/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.mpp.stability.nowarn=true 2 | org.gradle.daemon=true 3 | org.gradle.jvmargs=-XX\:MaxMetaspaceSize\=1G -Xmx2048m -Xss32m 4 | android.useAndroidX=true 5 | android.enableJetifier=true 6 | kotlin.code.style=official 7 | kotlin.mpp.enableCInteropCommonization=true 8 | android.disableAutomaticComponentCreation=true 9 | kotlin.native.binary.memoryModel=experimental 10 | kotlin.native.ignoreDisabledTargets=false 11 | 12 | # These properties can be overriden in local.properties. 13 | 14 | go.binary=/usr/bin/go 15 | 16 | # replace org.jetbrains .. etc in maven publishing with $project.group 17 | project.group=org.danbrough 18 | 19 | build.path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/opt/local/bin 20 | 21 | 22 | -------------------------------------------------------------------------------- /demos/repos/sqliter/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/demos/repos/sqliter/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/repos/sqliter/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /demos/repos/sqliter/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /demos/repos/sqliter/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | 3 | repositories { 4 | maven("../../build/m2") 5 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 6 | gradlePluginPortal() 7 | mavenCentral() 8 | google() 9 | } 10 | } 11 | 12 | 13 | plugins { 14 | id("de.fayard.refreshVersions") version "0.50.2" 15 | //// # available:"0.51.0-SNAPSHOT" 16 | //// # available:"0.51.0" 17 | } 18 | 19 | 20 | 21 | rootProject.name = "sqliter_demo" 22 | 23 | -------------------------------------------------------------------------------- /demos/repos/sqliter/src/nativeMain/kotlin/demo1/Main.kt: -------------------------------------------------------------------------------- 1 | package demo1 2 | 3 | import co.touchlab.sqliter.DatabaseConfiguration 4 | import co.touchlab.sqliter.createDatabaseManager 5 | import co.touchlab.sqliter.withConnection 6 | import co.touchlab.sqliter.withStatement 7 | import klog.KLogWriters 8 | import klog.KMessageFormatters 9 | import klog.Level 10 | import klog.colored 11 | import kotlinx.cinterop.toKString 12 | import platform.posix.realpath 13 | 14 | 15 | val log = klog.klog("demo1") { 16 | writer = KLogWriters.stdOut 17 | messageFormatter = KMessageFormatters.verbose.colored 18 | level = Level.TRACE 19 | } 20 | 21 | private const val SQL_CREATE = 22 | """ 23 | CREATE TABLE IF NOT EXISTS log( 24 | id INTEGER PRIMARY KEY AUTOINCREMENT, 25 | `time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 26 | message VARCHAR 27 | ) 28 | """ 29 | 30 | fun main(args: Array) { 31 | log.info("running main ..") 32 | 33 | 34 | 35 | val basePath = realpath(".",null)?.toKString() ?: throw Error("Failed to get current directory path") 36 | 37 | 38 | val config = DatabaseConfiguration( 39 | name = "sqliterDemo.db", 40 | version = 1, 41 | extendedConfig = DatabaseConfiguration.Extended(basePath = basePath), 42 | create = { db -> 43 | db.withStatement(SQL_CREATE) { 44 | execute() 45 | log.trace("SQL_CREATE executed") 46 | } 47 | }, 48 | upgrade = { _, _, _ -> 49 | // updateCalled.increment() 50 | // println("updateCalled $updateCalled") 51 | } 52 | ) 53 | 54 | val dbManager = createDatabaseManager(config) 55 | log.debug("created dbManager: $dbManager") 56 | 57 | 58 | dbManager.withConnection { 59 | //it.withStatement("SELECT * FROM log") 60 | if (args.isNotEmpty()) { 61 | it.withStatement("INSERT INTO log(message) VALUES(?)"){ 62 | bindString(1,args[0]) 63 | executeInsert() 64 | } 65 | } else { 66 | it.withStatement("INSERT INTO log(message) VALUES('Log message from ' || CURRENT_TIMESTAMP)"){ 67 | executeInsert() 68 | } 69 | } 70 | 71 | 72 | it.withStatement("SELECT * FROM log") { 73 | val cursor = query() 74 | while (cursor.next()) { 75 | log.trace("${cursor.getLong(0)}:${cursor.getString(1)}\t${cursor.getString(2)}") 76 | } 77 | } 78 | } 79 | 80 | 81 | 82 | } -------------------------------------------------------------------------------- /demos/repos/sqliter/versions.properties: -------------------------------------------------------------------------------- 1 | #### Dependencies and Plugin versions with their available updates. 2 | #### Generated by `./gradlew refreshVersions` version 0.50.2 3 | #### 4 | #### Don't manually edit or split the comments that start with four hashtags (####), 5 | #### they will be overwritten by refreshVersions. 6 | #### 7 | #### suppress inspection "SpellCheckingInspection" for whole file 8 | #### suppress inspection "UnusedProperty" for whole file 9 | 10 | version.kotlin=1.8.10 11 | ## # available=1.8.20-Beta 12 | ## # available=1.8.20-RC 13 | 14 | 15 | 16 | version.org.danbrough.sqldelight..native-driver=2.0.0-alpha04 17 | 18 | 19 | version.org.danbrough.kotlinx..kotlinx-coroutines-core=1.6.4 20 | 21 | plugin.org.danbrough.kotlinxtras.core=0.0.3-beta14 22 | 23 | version.org.danbrough..klog=0.0.2-beta02 24 | -------------------------------------------------------------------------------- /demos/sqlite/.gitignore: -------------------------------------------------------------------------------- 1 | test.db 2 | -------------------------------------------------------------------------------- /demos/sqlite/README.md: -------------------------------------------------------------------------------- 1 | # Sqlite demo 2 | 3 | ```bash 4 | 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /demos/sqlite/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.danbrough.kotlinxtras.core.enableSqlite 2 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 3 | 4 | plugins { 5 | kotlin("multiplatform") 6 | id("org.danbrough.kotlinxtras.core") 7 | } 8 | 9 | enableSqlite { 10 | 11 | } 12 | 13 | 14 | repositories { 15 | //for local builds 16 | maven("/usr/local/kotlinxtras/build/xtras/maven") 17 | //for unreleased staging builds 18 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 19 | //for release builds 20 | mavenCentral() 21 | } 22 | 23 | 24 | kotlin { 25 | 26 | if (org.jetbrains.kotlin.konan.target.HostManager.Companion.hostIsMac) { 27 | macosArm64() 28 | macosX64() 29 | } else { 30 | linuxX64() 31 | linuxArm64() 32 | linuxArm32Hfp() 33 | androidNativeX86() 34 | } 35 | 36 | val commonMain by sourceSets.getting { 37 | dependencies { 38 | implementation("org.danbrough:klog:_") 39 | implementation("org.danbrough.kotlinx:kotlinx-coroutines-core:_") 40 | } 41 | } 42 | 43 | val nativeMain by sourceSets.creating { 44 | dependsOn(commonMain) 45 | } 46 | 47 | targets.withType().all { 48 | 49 | compilations["main"].apply { 50 | defaultSourceSet.dependsOn(nativeMain) 51 | } 52 | 53 | binaries { 54 | executable("sqliteDemo") { 55 | entryPoint = "demo.main" 56 | runTask?.apply { 57 | properties["message"]?.also { 58 | args(it.toString()) 59 | } 60 | } 61 | } 62 | } 63 | } 64 | } 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /demos/sqlite/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.mpp.stability.nowarn=true 2 | org.gradle.daemon=true 3 | org.gradle.jvmargs=-XX\:MaxMetaspaceSize\=1G -Xmx2048m -Xss32m 4 | android.useAndroidX=true 5 | android.enableJetifier=true 6 | kotlin.code.style=official 7 | kotlin.mpp.enableCInteropCommonization=true 8 | android.disableAutomaticComponentCreation=true 9 | kotlin.native.binary.memoryModel=experimental 10 | kotlin.native.ignoreDisabledTargets=false 11 | 12 | # These properties can be overriden in local.properties. 13 | 14 | go.binary=/usr/bin/go 15 | 16 | # replace org.jetbrains .. etc in maven publishing with $project.group 17 | project.group=org.danbrough 18 | 19 | build.path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/opt/local/bin 20 | 21 | 22 | -------------------------------------------------------------------------------- /demos/sqlite/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/demos/sqlite/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/sqlite/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /demos/sqlite/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /demos/sqlite/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | 3 | repositories { 4 | //for local builds 5 | maven("/usr/local/kotlinxtras/build/xtras/maven") 6 | //for unreleased staging builds 7 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 8 | //for release builds 9 | 10 | gradlePluginPortal() 11 | mavenCentral() 12 | google() 13 | } 14 | } 15 | 16 | 17 | plugins { 18 | id("de.fayard.refreshVersions") version "0.51.0" 19 | } 20 | 21 | rootProject.name = "sqlite_demo" 22 | 23 | -------------------------------------------------------------------------------- /demos/sqlite/src/nativeMain/kotlin/demo/Main.kt: -------------------------------------------------------------------------------- 1 | @file:OptIn(ExperimentalForeignApi::class) 2 | 3 | package demo 4 | 5 | import klog.KLogWriters 6 | import klog.KMessageFormatters 7 | import klog.Level 8 | import klog.colored 9 | import kotlinx.cinterop.* 10 | import cnames.structs.sqlite3 11 | import cnames.structs.sqlite3_stmt 12 | import org.danbrough.kotlinxtras.core.sqlite.* 13 | 14 | val log = klog.klog("demo1") { 15 | writer = KLogWriters.stdOut 16 | messageFormatter = KMessageFormatters.verbose.colored 17 | level = Level.TRACE 18 | } 19 | 20 | private const val SQL_CREATE = 21 | """ 22 | CREATE TABLE IF NOT EXISTS log( 23 | id INTEGER PRIMARY KEY AUTOINCREMENT, 24 | `time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 25 | message VARCHAR 26 | ) 27 | """ 28 | 29 | private fun checkReturnValue( 30 | db: CPointerVar, 31 | rc: Int, 32 | defaultMessage: String = "Unknown error" 33 | ): String? = if (rc != SQLITE_OK) { 34 | sqlite3_errmsg(db.value)?.toKString() ?: defaultMessage 35 | } else 36 | null 37 | 38 | 39 | fun MemScope.processStatement( 40 | db: CPointerVar, 41 | sql: String, 42 | processStmt: (CPointerVar) -> Unit = {} 43 | ) { 44 | val stmtPtr = alloc>() 45 | log.debug("processStatement(): $sql") 46 | runCatching { 47 | checkReturnValue( 48 | db, 49 | sqlite3_prepare_v2(db.value, sql, -1, stmtPtr.ptr, null), 50 | "Prepare failed." 51 | )?.also { 52 | log.error("prepare failed: $it") 53 | return@runCatching 54 | } 55 | log.trace("statement prepared") 56 | 57 | 58 | while (sqlite3_step(stmtPtr.value) != SQLITE_DONE) { 59 | processStmt(stmtPtr) 60 | } 61 | 62 | }.exceptionOrNull().also { 63 | checkReturnValue(db, sqlite3_finalize(stmtPtr.value), "Finalize failed") 64 | if (it != null) throw it 65 | } 66 | } 67 | 68 | fun main(args: Array) { 69 | log.info("running main ..") 70 | 71 | val logMessage = 72 | if (args.isNotEmpty()) "\"${args[0]}\"" else "'log message at ' || CURRENT_TIMESTAMP" 73 | 74 | 75 | memScoped { 76 | 77 | val dbPtr = alloc>() 78 | runCatching { 79 | val sqlFlags = SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE 80 | checkReturnValue( 81 | dbPtr, 82 | sqlite3_open_v2("test.db", dbPtr.ptr, sqlFlags, null), 83 | "Error in open" 84 | )?.also { 85 | log.error("open failed. error:$it") 86 | sqlite3_close(dbPtr.value) 87 | throw Error(it) 88 | } 89 | 90 | processStatement(dbPtr, "SELECT SQLITE_VERSION()") { 91 | log.info( 92 | "SQLITE VERSION: ${ 93 | sqlite3_column_text(it.value, 0)?.reinterpret()?.toKString() 94 | }" 95 | ) 96 | } 97 | 98 | processStatement(dbPtr, SQL_CREATE) 99 | 100 | processStatement(dbPtr, "INSERT INTO log(message) values ($logMessage)") 101 | 102 | processStatement(dbPtr, "SELECT * FROM log") { 103 | val id = sqlite3_column_int64(it.value, 0) 104 | val date = sqlite3_column_text(it.value, 1)?.reinterpret()?.toKString() 105 | val msg = sqlite3_column_text(it.value, 2)?.reinterpret()?.toKString() 106 | log.info("$id:$date:\t$msg") 107 | } 108 | 109 | 110 | /* val stmt = memScoped { 111 | val stmtPtr = alloc>() 112 | val rc = sqlite3_prepare_v2(dbPtr.value, SQL_CREATE, -1, stmtPtr.ptr, null) 113 | if (rc != SQLITE_OK) { 114 | val msg = sqlite3_errmsg(dbPtr.value)?.toKString() ?: "error in prepare " 115 | log.error("prepare failed. error:$msg") 116 | sqlite3_close(dbPtr.value) 117 | throw Error(msg) 118 | } 119 | stmtPtr.value!! 120 | } 121 | 122 | log.debug("prepared statement") 123 | when (val rc = sqlite3_step(stmt)) { 124 | SQLITE_ROW -> log.trace("SQLITE_ROW") 125 | SQLITE_DONE -> log.trace("SQLITE_DONE") 126 | else -> log.trace("got rc: $rc") 127 | } 128 | 129 | if (sqlite3_finalize(stmt) != SQLITE_OK) { 130 | val msg = sqlite3_errmsg(dbPtr.value)?.toKString() ?: "error in finalize" 131 | log.error("finalize failed. error:$msg") 132 | }*/ 133 | 134 | }.exceptionOrNull().also { 135 | 136 | log.info("done .. closing db.") 137 | checkReturnValue(dbPtr, sqlite3_close(dbPtr.value))?.also { 138 | log.warn("failed close db: $it") 139 | } 140 | if (it != null) log.error(it.message, it) 141 | } 142 | } 143 | } -------------------------------------------------------------------------------- /demos/sqlite/src/nativeMain/kotlin/demo/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | 6 | sqlite3 *db; 7 | sqlite3_stmt *res; 8 | 9 | int rc = sqlite3_open(":memory:", &db); 10 | 11 | if (rc != SQLITE_OK) { 12 | 13 | fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db)); 14 | sqlite3_close(db); 15 | 16 | return 1; 17 | } 18 | 19 | rc = sqlite3_prepare_v2(db, "SELECT SQLITE_VERSION()", -1, &res, 0); 20 | 21 | if (rc != SQLITE_OK) { 22 | 23 | fprintf(stderr, "Failed to fetch data: %s\n", sqlite3_errmsg(db)); 24 | sqlite3_close(db); 25 | 26 | return 1; 27 | } 28 | 29 | rc = sqlite3_step(res); 30 | 31 | if (rc == SQLITE_ROW) { 32 | printf("%s\n", sqlite3_column_text(res, 0)); 33 | } 34 | 35 | sqlite3_finalize(res); 36 | sqlite3_close(db); 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /demos/sqlite/versions.properties: -------------------------------------------------------------------------------- 1 | #### Dependencies and Plugin versions with their available updates. 2 | #### Generated by `./gradlew refreshVersions` version 0.51.0 3 | #### 4 | #### Don't manually edit or split the comments that start with four hashtags (####), 5 | #### they will be overwritten by refreshVersions. 6 | #### 7 | #### suppress inspection "SpellCheckingInspection" for whole file 8 | #### suppress inspection "UnusedProperty" for whole file 9 | 10 | plugin.org.danbrough.kotlinxtras.core=0.0.3-beta17 11 | 12 | version.kotlin=1.9.0 13 | 14 | 15 | 16 | version.org.danbrough..klog=0.0.2-beta02 17 | ## # available=0.0.2-beta03 18 | 19 | 20 | version.org.danbrough.kotlinx..kotlinx-coroutines-core=1.6.4 21 | -------------------------------------------------------------------------------- /demos/uuid/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.danbrough.kotlinxtras.binaries.git 2 | import org.danbrough.kotlinxtras.binaries.registerLibraryExtension 3 | import org.danbrough.kotlinxtras.declareHostTarget 4 | import org.danbrough.kotlinxtras.hostTriplet 5 | import org.danbrough.kotlinxtras.platformName 6 | import org.danbrough.kotlinxtras.xtrasMavenDir 7 | import org.gradle.configurationcache.extensions.capitalized 8 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 9 | import org.jetbrains.kotlin.konan.target.HostManager 10 | import org.jetbrains.kotlin.konan.target.KonanTarget 11 | 12 | plugins { 13 | kotlin("multiplatform") 14 | id("org.danbrough.kotlinxtras.binaries") 15 | } 16 | 17 | repositories { 18 | maven("https://s01.oss.sonatype.org/content/groups/staging") 19 | maven(xtrasMavenDir) 20 | mavenCentral() 21 | } 22 | 23 | group = "demo.uuid" 24 | 25 | registerLibraryExtension("uuid") { 26 | version = "2.38.1" 27 | 28 | publishingGroup = "demo.uuid" 29 | 30 | deferToPrebuiltPackages = false 31 | 32 | git( 33 | "https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git", 34 | "54a4d5c3ec33f2f743309ec883b9854818a25e31" 35 | ) 36 | 37 | cinterops { 38 | headers = """ 39 | headers = uuid/uuid.h 40 | #for dynamic linking 41 | #linkerOpts = -luuid 42 | #or use this for static linking 43 | staticLibraries = libuuid.a 44 | """.trimIndent() 45 | } 46 | 47 | val autoGenTaskName: KonanTarget.() -> String = 48 | { "xtrasAutogen${libName.capitalized()}${platformName.capitalized()}" } 49 | 50 | configureTarget { target -> 51 | 52 | project.tasks.create(target.autoGenTaskName(), Exec::class.java) { 53 | dependsOn(extractSourcesTaskName(target)) 54 | workingDir(sourcesDir(target)) 55 | 56 | outputs.file(workingDir.resolve("configure")) 57 | commandLine("./autogen.sh") 58 | } 59 | } 60 | 61 | configure { target -> 62 | dependsOn(target.autoGenTaskName()) 63 | outputs.file(workingDir.resolve("Makefile")) 64 | 65 | commandLine( 66 | "./configure", 67 | "--host=${target.hostTriplet}", 68 | "--enable-libuuid", 69 | //"--enable-uuidgen", 70 | "--disable-all-programs", 71 | "--prefix=${buildDir(target)}" 72 | ) 73 | } 74 | 75 | build { 76 | commandLine(binaries.makeBinary, "install") 77 | } 78 | 79 | } 80 | 81 | 82 | 83 | kotlin { 84 | 85 | 86 | declareHostTarget() 87 | 88 | 89 | val commonMain by sourceSets.getting { 90 | dependencies { 91 | implementation("org.danbrough:klog:_") 92 | } 93 | } 94 | 95 | val posixMain by sourceSets.creating { 96 | dependsOn(commonMain) 97 | } 98 | 99 | targets.withType { 100 | 101 | compilations["main"].apply { 102 | defaultSourceSet.dependsOn(posixMain) 103 | } 104 | 105 | binaries { 106 | executable("uuidDemo") { 107 | entryPoint = "demo.main" 108 | } 109 | } 110 | } 111 | } 112 | 113 | 114 | tasks.create("run") { 115 | dependsOn("runUuidDemoDebugExecutable${HostManager.host.platformName.capitalized()}") 116 | } 117 | 118 | -------------------------------------------------------------------------------- /demos/uuid/gradle.properties: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.gradle.daemon=true 4 | org.gradle.jvmargs=-XX\:MaxMetaspaceSize\=1G -Xmx2048m -Xss32m 5 | org.gradle.caching=true 6 | org.gradle.unsafe.configuration-cache=false 7 | 8 | android.useAndroidX=true 9 | android.enableJetifier=true 10 | kotlin.code.style=official 11 | kotlin.mpp.enableCInteropCommonization=true 12 | 13 | android.disableAutomaticComponentCreation=true 14 | kotlin.native.binary.memoryModel=experimental 15 | kotlin.native.ignoreDisabledTargets=false 16 | kotlin.mpp.stability.nowarn=true 17 | 18 | 19 | sonatypeUrlBase=https://s01.oss.sonatype.org 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /demos/uuid/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/demos/uuid/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demos/uuid/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-rc-2-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /demos/uuid/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /demos/uuid/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | 2 | 3 | pluginManagement { 4 | 5 | repositories { 6 | maven(file("../../build/xtras/maven")) 7 | maven(file("./build/xtras/maven")) 8 | maven("https://s01.oss.sonatype.org/content/groups/staging/") 9 | gradlePluginPortal() 10 | mavenCentral() 11 | google() 12 | } 13 | } 14 | 15 | plugins { 16 | id("de.fayard.refreshVersions") version "0.51.0" 17 | } 18 | 19 | 20 | rootProject.name = "uuid_demo" -------------------------------------------------------------------------------- /demos/uuid/src/c/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/demos/uuid/src/c/test -------------------------------------------------------------------------------- /demos/uuid/src/c/uuid_test.c: -------------------------------------------------------------------------------- 1 | // 2 | // libuuid sample program 3 | // 4 | // library install for debian 5 | // $ sudo apt-get install uuid-dev 6 | // 7 | // compile 8 | // $ gcc uuid_test.c -luuid -o uuid_test 9 | // 10 | #include 11 | #include 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | // typedef unsigned char uuid_t[16]; 16 | uuid_t uuid; 17 | 18 | // generate 19 | uuid_generate_time_safe(uuid); 20 | 21 | // unparse (to string) 22 | char uuid_str[37]; // ex. "1b4e28ba-2fa1-11d2-883f-0016d3cca427" + "\0" 23 | uuid_unparse_lower(uuid, uuid_str); 24 | printf("generate uuid=%s\n", uuid_str); 25 | 26 | // parse (from string) 27 | uuid_t uuid2; 28 | uuid_parse(uuid_str, uuid2); 29 | 30 | // compare (rv == 0) 31 | int rv; 32 | rv = uuid_compare(uuid, uuid2); 33 | printf("uuid_compare() result=%d\n", rv); 34 | 35 | // compare (rv == 1) 36 | uuid_t uuid3; 37 | uuid_parse("1b4e28ba-2fa1-11d2-883f-0016d3cca427", uuid3); 38 | rv = uuid_compare(uuid, uuid3); 39 | printf("uuid_compare() result=%d\n", rv); 40 | 41 | // is null? (rv == 0) 42 | rv = uuid_is_null(uuid); 43 | printf("uuid_null() result=%d\n", rv); 44 | 45 | // is null? (rv == 1) 46 | uuid_clear(uuid); 47 | rv = uuid_is_null(uuid); 48 | printf("uuid_null() result=%d\n", rv); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /demos/uuid/src/posixMain/kotlin/demo/main.kt: -------------------------------------------------------------------------------- 1 | package demo 2 | 3 | import demo.uuid.uuid.uuid_generate_random 4 | import demo.uuid.uuid.uuid_generate_time 5 | import demo.uuid.uuid.uuid_t 6 | import demo.uuid.uuid.uuid_unparse_lower 7 | import klog.KLogWriters 8 | import klog.KMessageFormatters 9 | import klog.Level 10 | import klog.colored 11 | import klog.klog 12 | import kotlinx.cinterop.ByteVar 13 | import kotlinx.cinterop.UByteVar 14 | import kotlinx.cinterop.allocArray 15 | import kotlinx.cinterop.memScoped 16 | import kotlinx.cinterop.toKString 17 | 18 | 19 | val log = klog("DEMO") { 20 | level = Level.TRACE 21 | writer = KLogWriters.stdOut 22 | messageFormatter = KMessageFormatters.verbose.colored 23 | } 24 | 25 | 26 | fun main() { 27 | log.info("running main ...") 28 | 29 | 30 | 31 | memScoped { 32 | 33 | val uuid:uuid_t = allocArray(16) 34 | val uuidStr = allocArray(37) 35 | 36 | uuid_generate_random(uuid) 37 | 38 | /* 39 | char uuid_str[37]; // ex. "1b4e28ba-2fa1-11d2-883f-0016d3cca427" + "\0" 40 | uuid_unparse_lower(uuid, uuid_str); 41 | printf("generate uuid=%s\n", uuid_str); 42 | */ 43 | 44 | 45 | uuid_unparse_lower(uuid,uuidStr) 46 | log.debug("uuid_generate_random:\t${uuidStr.toKString()}") 47 | 48 | uuid_generate_time(uuid) 49 | uuid_unparse_lower(uuid,uuidStr) 50 | log.debug("uuid_generate_time:\t${uuidStr.toKString()}") 51 | } 52 | } -------------------------------------------------------------------------------- /demos/uuid/versions.properties: -------------------------------------------------------------------------------- 1 | #### Dependencies and Plugin versions with their available updates. 2 | #### Generated by `./gradlew refreshVersions` version 0.51.0 3 | #### 4 | #### Don't manually edit or split the comments that start with four hashtags (####), 5 | #### they will be overwritten by refreshVersions. 6 | #### 7 | #### suppress inspection "SpellCheckingInspection" for whole file 8 | #### suppress inspection "UnusedProperty" for whole file 9 | 10 | plugin.org.danbrough.kotlinxtras.binaries=0.0.3-beta16 11 | 12 | 13 | 14 | version.kotlin=1.8.20 15 | 16 | ## unused 17 | version.org.danbrough.kotlinxtras..common=0.0.1-beta02 18 | 19 | version.org.danbrough..klog=0.0.2-beta02 20 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | #kotlin.mpp.stability.nowarn=true 2 | org.gradle.daemon=true 3 | org.gradle.jvmargs=-XX\:MaxMetaspaceSize\=1G -Xmx2048m -Xss32m 4 | org.gradle.caching=true 5 | org.gradle.unsafe.configuration-cache=false 6 | android.useAndroidX=true 7 | android.enableJetifier=true 8 | android.disableAutomaticComponentCreation=true 9 | kotlin.code.style=official 10 | kotlin.mpp.enableCInteropCommonization=true 11 | kotlin.native.binary.memoryModel=experimental 12 | kotlin.native.ignoreDisabledTargets=true 13 | kotlin.mpp.stability.nowarn=true 14 | #sonatypeUsername=... 15 | #sonatypeSnapshot=false 16 | #go.binary=/usr/bin/go 17 | #build.path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/opt/local/bin 18 | sonatypeUrlBase=https://s01.oss.sonatype.org 19 | xtras.dir.libs=/usr/local/kotlinxtras/libs 20 | xtras.dir.packages=/usr/local/kotlinxtras/packages 21 | #to include only the plugin and plugins projects 22 | #pluginsOnly=true (command-line -PpluginsOnly=true) 23 | #to include everything except the plugin and plugins projects 24 | #pluginsOnly=false 25 | # otherwise everything is included 26 | #Print xtras log statements to stdout as well as the gradle log 27 | xtras.log.stdout=true 28 | sonatypeRepoId=orgdanbrough-1491 29 | bootstrap=false 30 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danbrough/kotlinxtras/fa98b17ad4282d0cb9e097598134bcb497e64e0e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-rc-3-all.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /libssh2/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.danbrough.kotlinxtras.core.enableLibSSH2 2 | import org.danbrough.kotlinxtras.core.enableOpenssl3 3 | import org.danbrough.kotlinxtras.declareSupportedTargets 4 | 5 | plugins { 6 | // `kotlin-dsl` 7 | //kotlin("multiplatform") 8 | kotlin("multiplatform") 9 | 10 | xtras("sonatype", Xtras.version) 11 | xtras("core", Xtras.version) 12 | } 13 | version = "0.0.1-beta01" 14 | 15 | 16 | 17 | enableLibSSH2(enableOpenssl3()) { 18 | deferToPrebuiltPackages = true 19 | 20 | cinterops { 21 | interopsPackage = "$group.${project.name}" 22 | } 23 | } 24 | 25 | kotlin { 26 | 27 | declareSupportedTargets() 28 | 29 | 30 | sourceSets { 31 | val commonTest by getting { 32 | dependencies { 33 | implementation(kotlin("test")) 34 | } 35 | } 36 | } 37 | 38 | 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /libssh2/src/commonMain/kotlin/org/danbrough/kotlinxtras/libssh2/libssh2.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras.libssh2 2 | 3 | fun test() {} 4 | -------------------------------------------------------------------------------- /mac_targets.txt: -------------------------------------------------------------------------------- 1 | publishCurlMacosArm64PublicationToSonaTypeRepository 2 | publishCurlMacosX64PublicationToSonaTypeRepository 3 | publishIconvMacosArm64PublicationToSonaTypeRepository 4 | publishIconvMacosX64PublicationToSonaTypeRepository 5 | publishOpensslMacosArm64PublicationToSonaTypeRepository 6 | publishOpensslMacosX64PublicationToSonaTypeRepository 7 | publishSqliteMacosArm64PublicationToSonaTypeRepository 8 | publishSqliteMacosX64PublicationToSonaTypeRepository 9 | -------------------------------------------------------------------------------- /plugin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | `maven-publish` 4 | id("org.jetbrains.dokka") 5 | xtras("sonatype") 6 | } 7 | 8 | 9 | dependencies { 10 | compileOnly(kotlin("gradle-plugin")) 11 | compileOnly(kotlin("gradle-plugin-api")) 12 | compileOnly("org.jetbrains.dokka:dokka-gradle-plugin:_") 13 | } 14 | 15 | 16 | 17 | gradlePlugin { 18 | 19 | plugins { 20 | 21 | create("binariesPlugin") { 22 | id = "${group}.binaries" 23 | implementationClass = "$group.binaries.BinaryPlugin" 24 | displayName = "Xtras Binaries Plugin" 25 | description = "Provides native library support to Kotlin applications" 26 | } 27 | 28 | create("sonatypePlugin") { 29 | id = "$group.sonatype" 30 | implementationClass = "$group.sonatype.SonatypePlugin" 31 | displayName = "Sonatype plugin" 32 | description = "Sonatype publishing support" 33 | } 34 | 35 | 36 | } 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /plugin/gradle.properties: -------------------------------------------------------------------------------- 1 | sonatypeSnapshot=false 2 | sonatypeUrlBase=https://s01.oss.sonatype.org 3 | 4 | 5 | 6 | xtras.log.stdout=true 7 | 8 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/binaries/archiveTasks.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras.binaries 2 | 3 | import org.danbrough.kotlinxtras.XTRAS_TASK_GROUP 4 | import org.danbrough.kotlinxtras.capitalize 5 | import org.danbrough.kotlinxtras.log 6 | import org.danbrough.kotlinxtras.platformName 7 | import org.danbrough.kotlinxtras.xtrasPackagesDir 8 | import org.gradle.api.Task 9 | import org.gradle.api.artifacts.repositories.MavenArtifactRepository 10 | import org.gradle.api.tasks.TaskProvider 11 | import org.gradle.configurationcache.extensions.capitalized 12 | import org.gradle.kotlin.dsl.dependencies 13 | import org.jetbrains.kotlin.konan.target.KonanTarget 14 | import java.io.File 15 | 16 | 17 | private fun LibraryExtension.cleanupTaskName(target: KonanTarget) = 18 | "xtrasCleanUp${libName.capitalize()}${target.platformName.capitalize()}" 19 | 20 | private fun LibraryExtension.registerCleanBuildTask(target: KonanTarget) = 21 | project.tasks.register(cleanupTaskName(target)) { 22 | val buildDir = buildDir(target) 23 | val sourcesDir = sourcesDir(target) 24 | actions.add { 25 | 26 | if (buildDir.exists()) { 27 | project.log("${cleanupTaskName(target)} deleting $buildDir") 28 | buildDir.deleteRecursively() 29 | } 30 | 31 | if (sourceConfig?.deleteSourcesOnClean == true && sourcesDir.exists()) { 32 | project.log("${cleanupTaskName(target)} deleting $sourcesDir") 33 | sourcesDir.deleteRecursively() 34 | } 35 | } 36 | } 37 | 38 | 39 | internal fun LibraryExtension.registerProvideArchiveTask(target: KonanTarget): TaskProvider = 40 | project.tasks.register(provideArchiveTaskName(target)) { 41 | group = XTRAS_TASK_GROUP 42 | description = 43 | "Ensures that the binary archive for $libName:${target.platformName} exists in the ${project.xtrasPackagesDir} folder" 44 | 45 | val archiveFile = archiveFile(target) 46 | val provideArchiveTaskName = 47 | if (deferToPrebuiltPackages) downloadArchiveTaskName(target) else createArchiveTaskName(target) 48 | 49 | dependsOn(provideArchiveTaskName) 50 | 51 | doFirst { 52 | project.log("$name: deferToPrebuiltPackages:$deferToPrebuiltPackages") 53 | } 54 | /* 55 | onlyIf { 56 | !archiveFile.exists() 57 | }*/ 58 | 59 | outputs.file(archiveFile) 60 | } 61 | 62 | 63 | internal fun LibraryExtension.registerExtractLibsTask(target: KonanTarget): TaskProvider = 64 | project.tasks.register(extractArchiveTaskName(target)) { 65 | group = XTRAS_TASK_GROUP 66 | description = "Unpacks $libName:${target.platformName} into the ${libsDir(target)} directory" 67 | dependsOn(provideArchiveTaskName(target)) 68 | val archiveFile = archiveFile(target) 69 | inputs.file(archiveFile) 70 | 71 | outputs.dir(libsDir(target)) 72 | actions.add { 73 | project.exec { 74 | workingDir(libsDir(target)) 75 | project.log("extracting: $archiveFile to $workingDir") 76 | commandLine("tar", "xvpfz", archiveFile.absolutePath) 77 | } 78 | } 79 | } 80 | 81 | fun LibraryExtension.registerCreateArchiveTask(target: KonanTarget): TaskProvider { 82 | registerCleanBuildTask(target) 83 | 84 | return project.tasks.register(createArchiveTaskName(target)) { 85 | group = XTRAS_TASK_GROUP 86 | description = "Outputs binary archive for $libName:${target.platformName}" 87 | dependsOn(buildSourcesTaskName(target)) 88 | inputs.dir(buildDir(target)) 89 | val archiveFile = archiveFile(target) 90 | outputs.file(archiveFile) 91 | 92 | actions.add { 93 | project.exec { 94 | workingDir(buildDir(target)) 95 | commandLine( 96 | "tar", 97 | "cvpfz", 98 | archiveFile.absolutePath, 99 | "--exclude=**share", 100 | "--exclude=**pkgconfig", 101 | "./" 102 | ) 103 | } 104 | } 105 | 106 | finalizedBy( 107 | "publish${libName.capitalized()}${target.platformName.capitalized()}PublicationToXtrasRepository", 108 | // cleanupTaskName(target) 109 | ) 110 | } 111 | } 112 | 113 | fun LibraryExtension.resolveBinariesFromMaven(target: KonanTarget): File? { 114 | 115 | 116 | val mavenID = "$publishingGroup:$libName${target.platformName.capitalized()}:$version" 117 | project.log("LibraryExtension.resolveBinariesFromMaven():$target $mavenID") 118 | 119 | val binariesConfiguration = 120 | project.configurations.create("configuration${libName.capitalized()}Binaries${target.platformName.capitalized()}") { 121 | isVisible = false 122 | isTransitive = false 123 | isCanBeConsumed = false 124 | isCanBeResolved = true 125 | } 126 | 127 | project.repositories.all { 128 | if (this is MavenArtifactRepository) { 129 | project.log("LibraryExtension.resolveBinariesFromMaven():$target REPO: ${this.name}:${this.url}") 130 | } 131 | } 132 | project.dependencies { 133 | binariesConfiguration(mavenID) 134 | } 135 | 136 | runCatching { 137 | return binariesConfiguration.resolve().first().also { 138 | project.log("LibraryExtension.resolveBinariesFromMaven():$target found ${it.absolutePath}") 139 | } 140 | }.exceptionOrNull()?.let { 141 | project.log("LibraryExtension.resolveBinariesFromMaven():$target Failed for $mavenID: ${it.message}") 142 | if (deferToPrebuiltPackages) { 143 | project.log("Do you need to set deferToPrebuiltPackages = false on the LibraryExtension?") 144 | } 145 | } 146 | return null 147 | } 148 | 149 | 150 | internal fun LibraryExtension.registerDownloadArchiveTask(target: KonanTarget): TaskProvider = 151 | project.tasks.register(downloadArchiveTaskName(target)) { 152 | group = XTRAS_TASK_GROUP 153 | 154 | val archiveFile = archiveFile(target) 155 | outputs.file(archiveFile) 156 | onlyIf { 157 | !archiveFile.exists() 158 | } 159 | 160 | actions.add { 161 | 162 | resolveBinariesFromMaven(target)?.also { 163 | project.log("$name: resolved ${it.absolutePath} copying to $archiveFile") 164 | it.copyTo(archiveFile, overwrite = true) 165 | } 166 | } 167 | } 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/binaries/buildTasks.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras.binaries 2 | 3 | import org.danbrough.kotlinxtras.XTRAS_TASK_GROUP 4 | import org.danbrough.kotlinxtras.konanDepsTaskName 5 | import org.danbrough.kotlinxtras.log 6 | import org.gradle.api.tasks.Exec 7 | import org.jetbrains.kotlin.konan.target.KonanTarget 8 | 9 | 10 | private fun LibraryExtension.registerConfigureSourcesTask(target: KonanTarget) = 11 | project.tasks.register(configureSourcesTaskName(target), Exec::class.java) { 12 | dependsOn(target.konanDepsTaskName) 13 | dependsOn(extractSourcesTaskName(target)) 14 | environment(buildEnvironment(target)) 15 | group = XTRAS_TASK_GROUP 16 | workingDir(sourcesDir(target)) 17 | doFirst { 18 | project.log("running $name with: ${commandLine.joinToString(" ")}") 19 | } 20 | configureTasks.forEach { 21 | it(target) 22 | } 23 | } 24 | 25 | 26 | fun LibraryExtension.registerBuildTasks(target: KonanTarget) { 27 | if (configureTasks.isNotEmpty()) { 28 | registerConfigureSourcesTask(target) 29 | } 30 | 31 | project.tasks.register(buildSourcesTaskName(target), Exec::class.java) { 32 | 33 | group = XTRAS_TASK_GROUP 34 | environment(buildEnvironment(target)) 35 | dependsOn(target.konanDepsTaskName) 36 | 37 | doFirst { 38 | project.log("running $name environment: $environment") 39 | } 40 | 41 | 42 | val srcDir = sourcesDir(target) 43 | workingDir(srcDir) 44 | 45 | outputs.dir(buildDir(target)) 46 | 47 | 48 | 49 | project.tasks.findByName(extractSourcesTaskName(target))?.also { 50 | dependsOn(it) 51 | } 52 | 53 | if (configureTasks.isNotEmpty()) { 54 | dependsOn(configureSourcesTaskName(target)) 55 | } 56 | 57 | 58 | buildTasks.forEach { 59 | it(target) 60 | } 61 | } 62 | } 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/binaries/interops.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras.binaries 2 | 3 | import org.danbrough.kotlinxtras.SHARED_LIBRARY_PATH_NAME 4 | import org.danbrough.kotlinxtras.XTRAS_TASK_GROUP 5 | import org.danbrough.kotlinxtras.log 6 | import org.danbrough.kotlinxtras.xtrasCInteropsDir 7 | import org.gradle.configurationcache.extensions.capitalized 8 | import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension 9 | import org.jetbrains.kotlin.gradle.plugin.mpp.Executable 10 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 11 | import org.jetbrains.kotlin.gradle.tasks.CInteropProcess 12 | import org.jetbrains.kotlin.konan.target.KonanTarget 13 | import java.io.File 14 | import java.io.PrintWriter 15 | 16 | typealias CInteropsTargetWriter = LibraryExtension.(KonanTarget, PrintWriter) -> Unit 17 | 18 | data class CInteropsConfig( 19 | //name of the interops task 20 | var name: String, 21 | 22 | //package for the interops 23 | var interopsPackage: String? = null, 24 | 25 | //path to the generated (or preexisting) def file 26 | //if pre-existing then [interopsPackage], [headers] and [headersFile] should not be set 27 | var defFile: File? = null, 28 | 29 | //to be added to the start of the generated interops file 30 | //no file will be generated if this and [headers] remain null 31 | var headerFile: File? = null, 32 | 33 | /** 34 | * Specify the interops headers instead of the [headerFile] 35 | */ 36 | var headers: String? = null, 37 | 38 | /** 39 | * Extra header source code for the headersFile [headerFile] 40 | */ 41 | var headersSource: String? = null, 42 | 43 | //writes output to the defs file for a konanTarget 44 | var writeTarget: CInteropsTargetWriter = defaultCInteropsTargetWriter, 45 | 46 | //customize the default config 47 | var configure: (CInteropsConfig.() -> Unit)? = null 48 | ) 49 | 50 | val defaultCInteropsTargetWriter: CInteropsTargetWriter = { konanTarget, output -> 51 | val libsDir = libsDir(konanTarget).absolutePath 52 | output.println( 53 | """ 54 | |compilerOpts.${konanTarget.name} = -I$libsDir/include 55 | |linkerOpts.${konanTarget.name} = -L$libsDir/lib 56 | |libraryPaths.${konanTarget.name} = $libsDir/lib 57 | |""".trimMargin() 58 | ) 59 | } 60 | 61 | fun LibraryExtension.registerGenerateInteropsTask() { 62 | 63 | project.log("registerGenerateInteropsTask() for $this") 64 | 65 | 66 | val config = CInteropsConfig( 67 | "xtras${libName.capitalized()}", 68 | "$publishingGroup.$libName", 69 | null 70 | ) 71 | 72 | cinteropsConfigTasks.forEach { 73 | it.invoke(config) 74 | } 75 | 76 | val generateConfig = config.defFile == null 77 | if (generateConfig) 78 | config.defFile = project.xtrasCInteropsDir.resolve("xtras_${libName}.def") 79 | 80 | project.extensions.findByType(KotlinMultiplatformExtension::class.java)?.apply { 81 | 82 | 83 | targets.withType(KotlinNativeTarget::class.java).all { 84 | compilations.getByName("main").apply { 85 | cinterops.create(config.name) { 86 | defFile(config.defFile!!) 87 | } 88 | } 89 | 90 | binaries.withType(Executable::class.java).filter { it.runTask != null }.forEach { 91 | val env = it.runTask!!.environment 92 | if (env.containsKey(SHARED_LIBRARY_PATH_NAME)) 93 | env[SHARED_LIBRARY_PATH_NAME] = 94 | env[SHARED_LIBRARY_PATH_NAME]!!.toString() + File.pathSeparatorChar + libsDir( 95 | konanTarget 96 | ).resolve("lib") 97 | else 98 | env[SHARED_LIBRARY_PATH_NAME] = libsDir(konanTarget).resolve("lib") 99 | project.logger.info("Setting $SHARED_LIBRARY_PATH_NAME for $konanTarget to ${env[SHARED_LIBRARY_PATH_NAME]}") 100 | } 101 | } 102 | } 103 | 104 | project.tasks.withType(CInteropProcess::class.java).all { 105 | dependsOn(generateCInteropsTaskName()) 106 | } 107 | 108 | if (generateConfig) 109 | project.tasks.register(generateCInteropsTaskName()) { 110 | group = XTRAS_TASK_GROUP 111 | 112 | if (config.headerFile != null && config.headers != null) 113 | throw Error("Only one of headersFile or headers should be specified for the cinterops config") 114 | 115 | config.headers?.also { headers -> 116 | inputs.property("headers", headers) 117 | } ?: config.headerFile?.also { inputs.file(it) } 118 | 119 | inputs.property("targets", supportedBuildTargets) 120 | 121 | outputs.file(config.defFile!!) 122 | 123 | //dependsOn(provideAllBinariesTaskName()) 124 | 125 | actions.add { 126 | 127 | config.defFile!!.printWriter().use { output -> 128 | //write the package 129 | output.println("package = ${config.interopsPackage}") 130 | //write the headers 131 | (config.headers ?: config.headerFile?.readText())?.also { 132 | output.println(it) 133 | } 134 | 135 | supportedTargets.forEach { konanTarget -> 136 | config.writeTarget(this@registerGenerateInteropsTask, konanTarget, output) 137 | } 138 | 139 | if (config.headersSource != null) { 140 | output.println("---") 141 | output.println(config.headersSource) 142 | } 143 | } 144 | } 145 | 146 | 147 | 148 | doLast { 149 | println("generated ${config.defFile}") 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/binaries/registerTasks.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras.binaries 2 | 3 | import org.danbrough.kotlinxtras.SHARED_LIBRARY_PATH_NAME 4 | import org.danbrough.kotlinxtras.XTRAS_REPO_NAME 5 | import org.danbrough.kotlinxtras.capitalize 6 | import org.danbrough.kotlinxtras.log 7 | import org.danbrough.kotlinxtras.platformName 8 | import org.danbrough.kotlinxtras.registerKonanDepsTasks 9 | import org.danbrough.kotlinxtras.xtrasMavenDir 10 | import org.danbrough.kotlinxtras.xtrasSupportedTargets 11 | import org.gradle.api.publish.PublishingExtension 12 | import org.gradle.api.publish.maven.MavenPublication 13 | import org.gradle.kotlin.dsl.findByType 14 | import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension 15 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 16 | import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest 17 | import org.jetbrains.kotlin.gradle.tasks.CInteropProcess 18 | import org.jetbrains.kotlin.konan.target.HostManager 19 | import java.io.File 20 | 21 | internal fun LibraryExtension.registerXtrasTasks() { 22 | val srcConfig = sourceConfig 23 | project.log("LibraryExtension.registerXtrasTasks for $libName") 24 | 25 | if (supportedTargets.isEmpty()) { 26 | supportedTargets = 27 | project.extensions.findByType(KotlinMultiplatformExtension::class.java)?.targets?.withType( 28 | KotlinNativeTarget::class.java 29 | )?.map { it.konanTarget } ?: xtrasSupportedTargets 30 | } 31 | 32 | if (supportedBuildTargets.isEmpty()) supportedBuildTargets = 33 | if (HostManager.hostIsMac) supportedTargets.filter { it.family.isAppleFamily } else supportedTargets 34 | 35 | 36 | val publishing = project.extensions.findByType(PublishingExtension::class.java) ?: let { 37 | project.log("LibraryExtension.registerXtrasTask() applying maven-publish.") 38 | project.pluginManager.apply("org.gradle.maven-publish") 39 | project.extensions.getByType(PublishingExtension::class.java) 40 | } 41 | 42 | project.repositories.findByName(XTRAS_REPO_NAME) ?: project.repositories.maven { 43 | name = XTRAS_REPO_NAME 44 | url = project.xtrasMavenDir.toURI() 45 | } 46 | 47 | publishing.repositories.findByName(XTRAS_REPO_NAME) ?: publishing.repositories.maven { 48 | name = XTRAS_REPO_NAME 49 | url = project.xtrasMavenDir.toURI() 50 | } 51 | 52 | registerGenerateInteropsTask() 53 | 54 | project.extensions.findByType(KotlinMultiplatformExtension::class)?.apply { 55 | project.tasks.withType(CInteropProcess::class.java) { 56 | dependsOn(extractArchiveTaskName(konanTarget)) 57 | } 58 | } 59 | 60 | project.tasks.withType(KotlinNativeTest::class.java).all { 61 | 62 | val konanTarget = HostManager.host 63 | val libPath = environment[SHARED_LIBRARY_PATH_NAME] 64 | val newLibPath = (libPath?.let { "$it${File.pathSeparator}" } 65 | ?: "") + project.binariesExtension.libraryExtensions.map { 66 | it.libsDir(konanTarget).resolve("lib") 67 | }.joinToString(File.pathSeparator) 68 | // println("$ldLibKey = $newLibPath") 69 | environment(SHARED_LIBRARY_PATH_NAME, newLibPath) 70 | } 71 | 72 | val buildEnabled = buildTasks.isNotEmpty() 73 | 74 | 75 | if (buildEnabled) { 76 | when (srcConfig) { 77 | is ArchiveSourceConfig -> { 78 | registerArchiveDownloadTask() 79 | } 80 | 81 | is GitSourceConfig -> { 82 | registerGitDownloadTask(srcConfig) 83 | } 84 | } 85 | } 86 | 87 | 88 | supportedTargets.forEach { target -> 89 | project.registerKonanDepsTasks(target) 90 | 91 | configureTargetTask?.invoke(target) 92 | 93 | registerDownloadArchiveTask(target) 94 | registerCreateArchiveTask(target) 95 | registerExtractLibsTask(target) 96 | val archiveTask = registerProvideArchiveTask(target) 97 | 98 | if (publishBinaries && (HostManager.hostIsMac == target.family.isAppleFamily)) publishing.publications.create( 99 | "$libName${target.platformName.capitalize()}", MavenPublication::class.java 100 | ) { 101 | artifactId = "${libName}${target.platformName.capitalize()}" 102 | version = this@registerXtrasTasks.version 103 | artifact(archiveTask) 104 | groupId = this@registerXtrasTasks.publishingGroup 105 | } 106 | 107 | /* if (!buildEnabled || HostManager.hostIsMac != target.family.isAppleFamily) { 108 | project.log("buildSupport disabled for $libName:${target.platformName}") 109 | return@forEach 110 | }*/ 111 | 112 | project.log("configuring buildSupport for $libName:${target.platformName}") 113 | registerBuildTasks(target) 114 | 115 | 116 | when (srcConfig) { 117 | is ArchiveSourceConfig -> { 118 | registerArchiveExtractTask(srcConfig, target) 119 | } 120 | 121 | is GitSourceConfig -> { 122 | registerGitExtractTask(srcConfig, target) 123 | } 124 | 125 | is DirectorySourceConfig -> { 126 | registerDirectorySourcesTask(srcConfig, target) 127 | } 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/konanDepsTasks.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.api.tasks.GradleBuild 5 | import org.gradle.configurationcache.extensions.capitalized 6 | import org.jetbrains.kotlin.konan.target.KonanTarget 7 | 8 | 9 | val KonanTarget.konanDepsTaskName: String 10 | get() = "xtrasKonanDeps${platformName.capitalized()}" 11 | 12 | 13 | internal fun Project.registerKonanDepsTasks(target: KonanTarget) { 14 | 15 | if (project.tasks.findByName(target.konanDepsTaskName) != null) return 16 | 17 | val depsProjectDir = 18 | rootProject.layout.buildDirectory.dir(".konandeps/xtraKonanDeps${target.platformName.capitalize()}") 19 | .get() 20 | val projectTaskName = "xtrasKonanDepsProject${target.platformName.capitalized()}" 21 | 22 | project.tasks.register(projectTaskName) { 23 | 24 | outputs.dir(depsProjectDir) 25 | doFirst { 26 | depsProjectDir.asFile.mkdirs() 27 | depsProjectDir.dir("gradle.properties").asFile.writeText( 28 | """ 29 | kotlin.native.ignoreDisabledTargets=true 30 | org.gradle.parallel=false 31 | org.gradle.unsafe.configuration-cache=false 32 | 33 | """.trimIndent() 34 | ) 35 | 36 | 37 | depsProjectDir.file("settings.gradle.kts").asFile.also { 38 | if (!it.exists()) it.createNewFile() 39 | } 40 | 41 | depsProjectDir.file("build.gradle.kts").asFile.writeText( 42 | """ 43 | plugins { 44 | kotlin("multiplatform") version "${KotlinVersion.CURRENT}" 45 | } 46 | 47 | kotlin { 48 | ${target.platformName}() 49 | } 50 | 51 | repositories { 52 | mavenCentral() 53 | } 54 | 55 | """.trimIndent() 56 | ) 57 | 58 | 59 | depsProjectDir.dir("src/commonMain/kotlin").asFile.apply { 60 | mkdirs() 61 | resolve("test.kt").writeText( 62 | """ 63 | fun test(){ 64 | println("some code to compile") 65 | } 66 | """.trimIndent() 67 | ) 68 | } 69 | } 70 | } 71 | 72 | project.tasks.register( 73 | target.konanDepsTaskName, GradleBuild::class.java 74 | ) { 75 | dependsOn(projectTaskName) 76 | dir = depsProjectDir.asFile 77 | tasks = listOf("compileKotlin${target.platformName.capitalized()}") 78 | doFirst { 79 | project.log("$name: running compileKotlin${target.platformName.capitalized()}") 80 | } 81 | } 82 | 83 | } 84 | 85 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/konanTargetExtns.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras 2 | 3 | import org.gradle.configurationcache.extensions.capitalized 4 | import org.jetbrains.kotlin.konan.target.Architecture 5 | import org.jetbrains.kotlin.konan.target.Family 6 | import org.jetbrains.kotlin.konan.target.HostManager 7 | import org.jetbrains.kotlin.konan.target.KonanTarget 8 | 9 | 10 | val KonanTarget.platformName: String 11 | get() { 12 | if (family == Family.ANDROID) { 13 | return when (this) { 14 | KonanTarget.ANDROID_X64 -> "androidNativeX64" 15 | KonanTarget.ANDROID_X86 -> "androidNativeX86" 16 | KonanTarget.ANDROID_ARM64 -> "androidNativeArm64" 17 | KonanTarget.ANDROID_ARM32 -> "androidNativeArm32" 18 | else -> throw Error("Unhandled android target $this") 19 | } 20 | } 21 | return name.split("_").joinToString("") { it.capitalized() }.decapitalize() 22 | } 23 | 24 | val KonanTarget.hostTriplet: String 25 | get() = when (this) { 26 | KonanTarget.LINUX_ARM64 -> "aarch64-unknown-linux-gnu" 27 | KonanTarget.LINUX_X64 -> "x86_64-unknown-linux-gnu" 28 | KonanTarget.LINUX_ARM32_HFP -> "arm-linux-gnueabihf" 29 | KonanTarget.ANDROID_ARM32 -> "armv7a-linux-androideabi" 30 | KonanTarget.ANDROID_ARM64 -> "aarch64-linux-android" 31 | KonanTarget.ANDROID_X64 -> "x86_64-linux-android" 32 | KonanTarget.ANDROID_X86 -> "i686-linux-android" 33 | KonanTarget.MACOS_X64 -> "x86_64-apple-darwin" 34 | 35 | KonanTarget.MACOS_ARM64 -> "aarch64-apple-darwin" 36 | KonanTarget.MINGW_X64 -> "x86_64-w64-mingw32" 37 | KonanTarget.MINGW_X86 -> "x86-w64-mingw32" 38 | KonanTarget.IOS_ARM32 -> "arm32-apple-darwin" 39 | KonanTarget.IOS_ARM64 -> "aarch64-ios-darwin" 40 | KonanTarget.IOS_SIMULATOR_ARM64 -> "aarch64-iossimulator-darwin" 41 | KonanTarget.IOS_X64 -> "x86_64-ios-darwin" 42 | 43 | 44 | KonanTarget.TVOS_ARM64 -> "aarch64-tvos-darwin" 45 | KonanTarget.TVOS_SIMULATOR_ARM64 -> "aarch64-tvossimulator-darwin" 46 | KonanTarget.TVOS_X64 -> "x86_64-tvos-darwin" 47 | KonanTarget.WASM32 -> TODO() 48 | KonanTarget.WATCHOS_ARM32 -> "arm32-watchos-darwin" 49 | KonanTarget.WATCHOS_ARM64 -> "aarch64-watchos-darwin" 50 | KonanTarget.WATCHOS_SIMULATOR_ARM64 -> "aarch64-watchossimulator-darwin" 51 | KonanTarget.WATCHOS_X64 -> "x86_64-watchos-darwin" 52 | KonanTarget.WATCHOS_X86 -> "x86-watchos-darwin" 53 | else -> TODO("Add KonanTarget.hostTriplet for $this") 54 | 55 | } 56 | 57 | 58 | val KonanTarget.androidLibDir: String? 59 | get() = when (this) { 60 | KonanTarget.ANDROID_ARM32 -> "armeabi-v7a" 61 | KonanTarget.ANDROID_ARM64 -> "arm64-v8a" 62 | KonanTarget.ANDROID_X64 -> "x86_64" 63 | KonanTarget.ANDROID_X86 -> "x86" 64 | else -> null 65 | } 66 | 67 | val KonanTarget.sharedLibExtn: String 68 | get() = when { 69 | family.isAppleFamily -> "dylib" 70 | family == Family.MINGW -> "dll" 71 | else -> "so" 72 | } 73 | 74 | val SHARED_LIBRARY_PATH_NAME = if (HostManager.hostIsMac) "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH" 75 | 76 | 77 | val KonanTarget.goOS: String? 78 | get() = when (family) { 79 | Family.OSX -> "darwin" 80 | Family.IOS, Family.TVOS, Family.WATCHOS -> "ios" 81 | Family.LINUX -> "linux" 82 | Family.MINGW -> "windows" 83 | Family.ANDROID -> "android" 84 | Family.WASM -> null 85 | Family.ZEPHYR -> null 86 | } 87 | 88 | val KonanTarget.goArch: String 89 | get() = when (architecture) { 90 | Architecture.ARM64 -> "arm64" 91 | Architecture.X64 -> "amd64" 92 | Architecture.X86 -> "386" 93 | Architecture.ARM32 -> "arm" 94 | Architecture.MIPS32 -> "mips" //TODO: confirm this 95 | Architecture.MIPSEL32 -> "mipsle" //TODO: confirm this 96 | Architecture.WASM32 -> "wasm" 97 | } 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/logging.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras 2 | 3 | import org.gradle.api.Project 4 | import org.gradle.api.logging.LogLevel 5 | 6 | const val loggingProperty = "xtras.log.stdout" 7 | 8 | 9 | fun Project.log(msg: String, level: LogLevel = LogLevel.INFO) { 10 | logger.log(level, msg) 11 | 12 | 13 | if (hasProperty(loggingProperty) && property(loggingProperty) == "true") { 14 | println("$level: $msg") 15 | } 16 | } -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/projectExtns.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras 2 | 3 | import org.danbrough.kotlinxtras.binaries.binariesExtension 4 | import org.gradle.api.Project 5 | import org.jetbrains.kotlin.gradle.dsl.kotlinExtension 6 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 7 | import org.jetbrains.kotlin.gradle.plugin.mpp.SharedLibrary 8 | import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.targets 9 | import org.jetbrains.kotlin.konan.target.HostManager 10 | import org.jetbrains.kotlin.konan.target.KonanTarget 11 | import java.io.File 12 | 13 | fun Project.sharedLibraryPath( 14 | target: KonanTarget = HostManager.host, 15 | debuggable: Boolean = true 16 | ): String { 17 | 18 | val libPath = 19 | binariesExtension.libraryExtensions.map { 20 | it.libsDir(target).resolve("lib") 21 | }.toMutableList() 22 | 23 | libPath += kotlinExtension.targets.filterIsInstance() 24 | .firstOrNull { it.konanTarget == target } 25 | ?.binaries?.withType(SharedLibrary::class.java) 26 | ?.filter { it.debuggable == debuggable } 27 | ?.map { 28 | it.outputDirectory 29 | } 30 | ?: emptyList() 31 | 32 | return libPath.joinToString(File.pathSeparator) 33 | } -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/projectProperties.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras 2 | 3 | import org.gradle.api.Project 4 | import java.io.File 5 | import java.net.URI 6 | 7 | inline fun Project.projectProperty( 8 | name: String 9 | ): T = projectProperty(name,null,false) 10 | 11 | inline fun Project.projectProperty( 12 | name: String,defaultValue: T 13 | ): T = projectProperty(name,defaultValue,true) 14 | 15 | inline fun Project.projectProperty( 16 | name: String, 17 | defaultValue: T? = null, 18 | hasDefault: Boolean 19 | ): T { 20 | val value = if (properties.containsKey(name)) 21 | properties[name].toString() 22 | else { 23 | if (hasDefault) return defaultValue as T 24 | else throw Error("Project property $name not declared. Add it to gradle.properties or specify it with \"-P\" on the command line") 25 | } 26 | 27 | return when (T::class) { 28 | String::class -> value 29 | Int::class -> value.toInt() 30 | Float::class -> value.toFloat() 31 | Double::class -> value.toDouble() 32 | Long::class -> value.toLong() 33 | Boolean::class -> value.toBoolean() 34 | File::class -> File(value) 35 | URI::class -> URI.create(value) 36 | else -> throw Error("Invalid property type: ${T::class}") 37 | } as T 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/sonatype/SonatypePlugin.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras.sonatype 2 | 3 | 4 | import org.danbrough.kotlinxtras.xtrasMavenDir 5 | import org.gradle.api.Plugin 6 | import org.gradle.api.Project 7 | import org.gradle.api.publish.PublishingExtension 8 | import java.io.File 9 | 10 | class SonatypePlugin : Plugin { 11 | override fun apply(project: Project) { 12 | val extn = project.extensions.create("sonatype", SonatypeExtension::class.java, project) 13 | 14 | val publishingPluginId = "org.gradle.maven-publish" 15 | project.plugins.findPlugin(publishingPluginId) 16 | ?: project.pluginManager.apply(publishingPluginId) 17 | 18 | project.afterEvaluate { 19 | createOpenRepoTask(extn) 20 | createCloseRepoTask(extn) 21 | configurePublishing(extn) 22 | } 23 | } 24 | } 25 | 26 | 27 | open class SonatypeExtension(val project: Project) { 28 | companion object { 29 | const val SONATYPE_TASK_GROUP = "sonatype" 30 | const val REPOSITORY_ID = "sonatypeRepoId" 31 | const val PROFILE_ID = "sonatypeProfileId" 32 | const val DESCRIPTION = "sonatypeDescription" 33 | const val USERNAME = "sonatypeUsername" 34 | const val PASSWORD = "sonatypePassword" 35 | const val PUBLISH_DOCS = "publishDocs" 36 | const val SIGN_PUBLICATIONS = "signPublications" 37 | } 38 | 39 | internal var configurePublishing: PublishingExtension.(project: Project) -> Unit = {} 40 | 41 | fun configurePublishing(configure: PublishingExtension.(project: Project) -> Unit) { 42 | configurePublishing = configure 43 | } 44 | 45 | var sonatypeUrlBase: String = "https://s01.oss.sonatype.org" 46 | var sonatypeProfileId: String? = null 47 | var sonatypeRepoId: String? = null 48 | var sonatypeUsername: String? = null 49 | var sonatypePassword: String? = null 50 | var publishDocs: Boolean = false 51 | var signPublications: Boolean = false 52 | 53 | var localRepoEnabled: Boolean = true 54 | var localRepoName: String = "xtras" 55 | var localRepoLocation: File = project.xtrasMavenDir 56 | 57 | var sonatypeSnapshot: Boolean = false 58 | 59 | //lateinit var publishingURL:String 60 | /* 61 | val publishingURL: String 62 | get() = (if (sonatypeSnapshot) 63 | "$sonatypeUrlBase/content/repositories/snapshots/" 64 | else if (sonatypeRepoId.isNotBlank()) 65 | "$sonatypeUrlBase/service/local/staging/deployByRepositoryId/$sonatypeRepoId" 66 | else 67 | "$sonatypeUrlBase/service/local/staging/deploy/maven2/").also { 68 | println("SonatypeExtension::publishingURL $it repoID is: $sonatypeRepoId") 69 | } 70 | */ 71 | 72 | override fun toString() = 73 | "SonatypeExtension[urlBase=$sonatypeUrlBase,stagingProfileId=$sonatypeProfileId,sonatypeUsername=$sonatypeUsername]" 74 | } 75 | 76 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/sonatype/configurePublishing.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras.sonatype 2 | 3 | 4 | import org.danbrough.kotlinxtras.capitalize 5 | import org.danbrough.kotlinxtras.projectProperty 6 | import org.danbrough.kotlinxtras.xtrasDocsDir 7 | import org.gradle.api.Project 8 | import org.gradle.api.publish.PublishingExtension 9 | import org.gradle.api.publish.maven.MavenPublication 10 | import org.gradle.api.publish.maven.tasks.PublishToMavenRepository 11 | import org.gradle.api.tasks.bundling.Jar 12 | import org.gradle.kotlin.dsl.apply 13 | import org.gradle.kotlin.dsl.findByType 14 | import org.gradle.kotlin.dsl.getByType 15 | import org.gradle.kotlin.dsl.getValue 16 | import org.gradle.kotlin.dsl.named 17 | import org.gradle.kotlin.dsl.provideDelegate 18 | import org.gradle.kotlin.dsl.registering 19 | import org.gradle.plugins.signing.Sign 20 | import org.gradle.plugins.signing.SigningExtension 21 | import org.gradle.plugins.signing.SigningPlugin 22 | import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension 23 | import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension 24 | import java.net.URI 25 | 26 | 27 | internal fun Project.configurePublishing(extn: SonatypeExtension) { 28 | 29 | extensions.findByType()?.apply { 30 | logger.info("Project.configurePublishing - ${project.group}:${project.name}:${project.version}") 31 | 32 | extn.sonatypeRepoId = project.projectProperty(SonatypeExtension.REPOSITORY_ID, null) 33 | extn.sonatypeProfileId = project.projectProperty(SonatypeExtension.PROFILE_ID) 34 | extn.sonatypeUsername = project.projectProperty(SonatypeExtension.USERNAME) 35 | extn.sonatypePassword = project.projectProperty(SonatypeExtension.PASSWORD) 36 | extn.publishDocs = project.projectProperty(SonatypeExtension.PUBLISH_DOCS, false) 37 | extn.signPublications = project.projectProperty(SonatypeExtension.SIGN_PUBLICATIONS, false) 38 | 39 | extn.configurePublishing(this, this@configurePublishing) 40 | 41 | val publishingURL = if (extn.sonatypeSnapshot) 42 | "${extn.sonatypeUrlBase}/content/repositories/snapshots/" 43 | else if (!extn.sonatypeRepoId.isNullOrBlank()) 44 | "${extn.sonatypeUrlBase}/service/local/staging/deployByRepositoryId/${extn.sonatypeRepoId}" 45 | else 46 | "${extn.sonatypeUrlBase}/service/local/staging/deploy/maven2/" 47 | 48 | 49 | logger.info("SonatypeExtension::publishingURL $publishingURL repoID is: ${extn.sonatypeRepoId}") 50 | 51 | 52 | if (extn.publishDocs) { 53 | if (plugins.hasPlugin("org.jetbrains.dokka")) { 54 | tasks.named("dokkaHtml").configure { 55 | outputDirectory.set(project.xtrasDocsDir) 56 | } 57 | 58 | val javadocJar by tasks.registering(Jar::class) { 59 | archiveClassifier.set("javadoc") 60 | from(tasks.named("dokkaHtml")) 61 | } 62 | 63 | publications.all { 64 | if (this is MavenPublication) 65 | artifact(javadocJar) 66 | } 67 | } 68 | } 69 | 70 | val kotlinMPP = project.extensions.findByType() 71 | if (kotlinMPP == null) { 72 | //create a default sources jar from the main sources 73 | project.extensions.findByType()?.apply { 74 | sourceSets.findByName("main")?.kotlin?.also { srcDir -> 75 | val sourcesJarTask = tasks.register("sourcesJar${name.capitalize()}", Jar::class.java) { 76 | archiveClassifier.set("sources") 77 | from(srcDir) 78 | } 79 | 80 | publications.all { 81 | if (this is MavenPublication) 82 | artifact(sourcesJarTask) 83 | } 84 | } 85 | } 86 | } 87 | 88 | if (extn.signPublications) { 89 | apply() 90 | extensions.getByType().apply { 91 | publications.all { 92 | sign(this) 93 | } 94 | } 95 | } 96 | 97 | val signTasks = tasks.withType(Sign::class.java).map { it.name } 98 | if (signTasks.isNotEmpty()) { 99 | tasks.withType(PublishToMavenRepository::class.java) { 100 | dependsOn(signTasks) 101 | } 102 | } 103 | 104 | 105 | repositories { 106 | maven { 107 | name = "SonaType" 108 | url = URI(publishingURL) 109 | credentials { 110 | username = extn.sonatypeUsername 111 | password = extn.sonatypePassword 112 | } 113 | } 114 | 115 | if (extn.localRepoEnabled) { 116 | maven { 117 | name = extn.localRepoName 118 | url = extn.localRepoLocation.toURI() 119 | } 120 | } 121 | } 122 | 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/sonatype/sonatypeCloseRepository.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras.sonatype 2 | 3 | import org.danbrough.kotlinxtras.sonatype.SonatypeExtension.Companion.SONATYPE_TASK_GROUP 4 | import org.gradle.api.Project 5 | import java.io.PrintWriter 6 | import java.net.HttpURLConnection 7 | import java.net.URL 8 | import java.nio.charset.Charset 9 | import java.util.Base64 10 | 11 | internal fun sonatypeCloseRepository( 12 | stagingProfileId: String?, 13 | repoId:String?, 14 | description: String?, 15 | username: String?, 16 | password: String?, 17 | urlBase: String 18 | ) { 19 | println("sonatypeOpenRepository()") 20 | val url = "$urlBase/service/local/staging/profiles/$stagingProfileId/finish" 21 | URL(url).openConnection().apply { 22 | this as HttpURLConnection 23 | requestMethod = "POST" 24 | doOutput = true 25 | addRequestProperty("Content-Type", "application/xml") 26 | addRequestProperty( 27 | "Authorization", 28 | "Basic: ${ 29 | Base64.getEncoder() 30 | .encodeToString("$username:$password".toByteArray(Charset.defaultCharset())) 31 | }" 32 | ) 33 | PrintWriter(outputStream).use { output -> 34 | output.write( 35 | """ 36 | 37 | 38 | $repoId 39 | $description 40 | 41 | """.trimIndent() 42 | ) 43 | } 44 | 45 | println("RESPONSE: $responseCode : $responseMessage") 46 | if (responseCode != HttpURLConnection.HTTP_CREATED) 47 | throw Error("Response code: $responseCode $responseMessage") 48 | 49 | } 50 | } 51 | 52 | internal fun Project.createCloseRepoTask(extn:SonatypeExtension){ 53 | project.tasks.create("sonatypeCloseRepository") { 54 | description = 55 | "Closes the sonatype repository as specified by the ${SonatypeExtension.REPOSITORY_ID} gradle property" 56 | group = SONATYPE_TASK_GROUP 57 | doLast { 58 | if (extn.sonatypeProfileId.isNullOrBlank()) throw Error("sonatype.${SonatypeExtension.PROFILE_ID} not set") 59 | val description = 60 | project.properties[SonatypeExtension.DESCRIPTION]?.toString() ?: "" 61 | 62 | sonatypeCloseRepository( 63 | extn.sonatypeProfileId, 64 | extn.sonatypeRepoId, 65 | description, 66 | extn.sonatypeUsername, 67 | extn.sonatypePassword, 68 | extn.sonatypeUrlBase 69 | ) 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/sonatype/sonatypeOpenRepository.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras.sonatype 2 | 3 | import org.danbrough.kotlinxtras.sonatype.SonatypeExtension.Companion.SONATYPE_TASK_GROUP 4 | import org.gradle.api.Project 5 | import org.w3c.dom.Element 6 | import java.io.InputStream 7 | import java.io.PrintWriter 8 | import java.net.HttpURLConnection 9 | import java.net.URL 10 | import java.nio.charset.Charset 11 | import java.util.Base64 12 | import javax.xml.parsers.DocumentBuilderFactory 13 | 14 | 15 | internal fun sonatypeOpenRepository( 16 | stagingProfileId: String, 17 | description: String, 18 | username: String, 19 | password: String, 20 | urlBase: String 21 | ): PromoteRequestResponse { 22 | val url = "$urlBase/service/local/staging/profiles/$stagingProfileId/start" 23 | URL(url).openConnection().apply { 24 | this as HttpURLConnection 25 | requestMethod = "POST" 26 | doOutput = true 27 | addRequestProperty("Content-Type", "application/xml") 28 | addRequestProperty( 29 | "Authorization", 30 | "Basic: ${ 31 | Base64.getEncoder() 32 | .encodeToString("$username:$password".toByteArray(Charset.defaultCharset())) 33 | }" 34 | ) 35 | 36 | PrintWriter(outputStream).use { output -> 37 | output.write( 38 | """ 39 | 40 | $description 41 | 42 | """.trimIndent() 43 | ) 44 | } 45 | 46 | if (responseCode == HttpURLConnection.HTTP_CREATED) 47 | return parsePromoteRequest(inputStream) 48 | 49 | throw Error("Failed: error: $responseCode: $responseCode: $responseMessage") 50 | } 51 | } 52 | 53 | data class PromoteRequestResponse(val repositoryId: String, val description: String) 54 | 55 | fun parsePromoteRequest(input: InputStream): PromoteRequestResponse { 56 | /* 57 | 58 | 59 | orgdanbrough-1185 60 | 61 | 62 | 63 | 64 | */ 65 | 66 | 67 | val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() 68 | .parse(input) 69 | return doc.getElementsByTagName("data").item(0).run { 70 | this as Element 71 | val repoID = getElementsByTagName("stagedRepositoryId").item(0).textContent 72 | val description = getElementsByTagName("description").item(0).textContent 73 | PromoteRequestResponse(repoID, description) 74 | } 75 | 76 | } 77 | 78 | internal fun Project.createOpenRepoTask(extn: SonatypeExtension) { 79 | project.tasks.create("sonatypeOpenRepository") { 80 | description = """ 81 | Open a new sonatype repository and store the repository id in gradle.properties. 82 | Specify the repository description with -P${SonatypeExtension.DESCRIPTION}="..". 83 | """.trimMargin() 84 | group = SONATYPE_TASK_GROUP 85 | doLast { 86 | if (extn.sonatypeProfileId.isNullOrBlank()) throw Error("sonatype.stagingProfileId not set") 87 | val description = 88 | project.properties[SonatypeExtension.DESCRIPTION]?.toString() ?: "" 89 | 90 | val response = sonatypeOpenRepository( 91 | extn.sonatypeProfileId!!, 92 | description, 93 | extn.sonatypeUsername!!, 94 | extn.sonatypePassword!!, 95 | extn.sonatypeUrlBase 96 | ) 97 | 98 | println("Received response: $response") 99 | 100 | project.rootProject.file("gradle.properties").readLines().also { lines -> 101 | var wroteRepoId = false 102 | 103 | project.rootProject.file("gradle.properties").printWriter().use { output -> 104 | lines.forEach { 105 | if (it.startsWith(SonatypeExtension.REPOSITORY_ID)) { 106 | wroteRepoId = true 107 | output.println("${SonatypeExtension.REPOSITORY_ID}=${response.repositoryId}") 108 | } else { 109 | output.println(it) 110 | } 111 | } 112 | if (!wroteRepoId) { 113 | output.println("${SonatypeExtension.REPOSITORY_ID}=${response.repositoryId}") 114 | } 115 | } 116 | } 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/supportedTargets.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras 2 | 3 | import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension 4 | import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget 5 | import org.jetbrains.kotlin.konan.target.HostManager 6 | import org.jetbrains.kotlin.konan.target.KonanTarget 7 | 8 | /** 9 | * Declares the kotlin native targets that are currently supported 10 | */ 11 | fun KotlinMultiplatformExtension.declareSupportedTargets() { 12 | if (HostManager.hostIsMac) { 13 | macosX64() 14 | macosArm64() 15 | } else { 16 | androidNativeX86() 17 | androidNativeX64() 18 | androidNativeArm32() 19 | androidNativeArm64() 20 | 21 | mingwX64() 22 | 23 | linuxX64() 24 | linuxArm64() 25 | linuxArm32Hfp() 26 | } 27 | 28 | 29 | /* 30 | //TODO 31 | iosArm32() 32 | iosArm64() 33 | iosSimulatorArm64() 34 | iosX64() 35 | 36 | tvosArm64() 37 | tvosX64() 38 | tvosSimulatorArm64() 39 | 40 | watchosArm32() 41 | watchosArm64() 42 | watchosX64() 43 | watchosX86() 44 | watchosSimulatorArm64() 45 | */ 46 | 47 | } 48 | 49 | val xtrasSupportedTargets: List = listOf( 50 | KonanTarget.LINUX_X64, 51 | KonanTarget.LINUX_ARM32_HFP, 52 | KonanTarget.LINUX_ARM64, 53 | KonanTarget.ANDROID_ARM32, 54 | KonanTarget.ANDROID_ARM64, 55 | KonanTarget.ANDROID_X64, 56 | KonanTarget.ANDROID_X86, 57 | KonanTarget.MACOS_X64, 58 | KonanTarget.MACOS_ARM64, 59 | KonanTarget.MINGW_X64, 60 | ) 61 | 62 | 63 | /** 64 | * Declare target support for the host platform 65 | */ 66 | fun KotlinMultiplatformExtension.declareHostTarget(configure: KotlinNativeTarget.() -> Unit = { }) { 67 | when (HostManager.host) { 68 | KonanTarget.MACOS_X64 -> macosX64(configure = configure) 69 | KonanTarget.MACOS_ARM64 -> macosArm64(configure = configure) 70 | KonanTarget.LINUX_ARM64 -> linuxArm64(configure = configure) 71 | KonanTarget.LINUX_X64 -> linuxX64(configure = configure) 72 | KonanTarget.MINGW_X64 -> mingwX64(configure = configure) 73 | else -> throw Error("Unhandled host platform: ${HostManager.host}") 74 | } 75 | } -------------------------------------------------------------------------------- /plugin/src/main/kotlin/org/danbrough/kotlinxtras/xtras.kt: -------------------------------------------------------------------------------- 1 | package org.danbrough.kotlinxtras 2 | 3 | import org.gradle.api.Project 4 | import java.io.File 5 | import java.util.Locale 6 | 7 | const val XTRAS_PACKAGE = "org.danbrough.kotlinxtras" 8 | 9 | const val XTRAS_BINARY_PLUGIN_ID = "$XTRAS_PACKAGE.binaries" 10 | 11 | const val XTRAS_BINARIES_PUBLISHING_GROUP = "$XTRAS_PACKAGE.xtras" 12 | 13 | const val XTRAS_TASK_GROUP = "xtras" 14 | 15 | const val XTRAS_REPO_NAME = "xtras" 16 | 17 | const val PROPERTY_XTRAS_DIR = "xtras.dir" 18 | 19 | /** 20 | * Location of the xtras packages directory 21 | */ 22 | const val PROPERTY_PACKAGES_DIR = "$PROPERTY_XTRAS_DIR.packages" 23 | 24 | 25 | /** 26 | * Location of the xtras packages directory 27 | */ 28 | const val PROPERTY_MAVEN_DIR = "$PROPERTY_XTRAS_DIR.maven" 29 | 30 | /** 31 | * Location of the xtras downloads directory 32 | */ 33 | const val PROPERTY_DOWNLOADS_DIR = "$PROPERTY_XTRAS_DIR.downloads" 34 | 35 | const val PROPERTY_DOCS_DIR = "$PROPERTY_XTRAS_DIR.docs" 36 | 37 | const val PROPERTY_BUILD_DIR = "$PROPERTY_XTRAS_DIR.build" 38 | 39 | const val PROPERTY_LIBS_DIR = "$PROPERTY_XTRAS_DIR.libs" 40 | 41 | const val PROPERTY_CINTEROPS_DIR = "$PROPERTY_XTRAS_DIR.cinterops" 42 | 43 | private fun Project.xtrasPath(name: String, defValue: String? = null): File = 44 | properties[name]?.toString()?.trim()?.let { 45 | project.file(it) 46 | } ?: defValue?.let { rootProject.xtrasDir.resolve(it) } 47 | ?: rootProject.buildDir.resolve("xtras") 48 | 49 | /** 50 | * Path to the top level xtras directory. 51 | * This is where sources and binary packages are downloaded and built. 52 | * 53 | * Defaults to `project.rootProject.buildDir.resolve("xtras")` 54 | */ 55 | 56 | val Project.xtrasDir: File 57 | get() = xtrasPath(PROPERTY_XTRAS_DIR) 58 | 59 | /** 60 | * Path to the xtras downloads directory. 61 | * This is where source archives are downloaded to. 62 | * 63 | * Defaults to `project.xtrasDir.resolve("downloads")` 64 | */ 65 | val Project.xtrasDownloadsDir: File 66 | get() = xtrasPath(PROPERTY_DOWNLOADS_DIR, "downloads") 67 | 68 | 69 | /** 70 | * Path to the xtras build directory. 71 | * This is the prefix directory for compiled source code. 72 | * 73 | * Defaults to `project.xtrasDir.resolve("build")` 74 | */ 75 | val Project.xtrasBuildDir: File 76 | get() = xtrasPath(PROPERTY_BUILD_DIR, "build") 77 | 78 | /** 79 | * Path to the xtras packages directory. 80 | * This is where binary archives are stored. 81 | * 82 | * Defaults to `project.xtrasDir.resolve("packages")` 83 | */ 84 | val Project.xtrasPackagesDir: File 85 | get() = xtrasPath(PROPERTY_PACKAGES_DIR, "packages") 86 | 87 | 88 | /** 89 | * Path to the xtras maven directory. 90 | * This is where binary archives are published to. 91 | * 92 | * Defaults to `project.xtrasDir.resolve("maven")` 93 | */ 94 | val Project.xtrasMavenDir: File 95 | get() = xtrasPath(PROPERTY_MAVEN_DIR, "maven") 96 | 97 | 98 | /** 99 | * Path to the xtras cinterops directory. 100 | * This is where cinterop files are generated from headers. 101 | * 102 | * Defaults to `project.xtrasDir.resolve("cinterops")` 103 | */ 104 | val Project.xtrasCInteropsDir: File 105 | get() = xtrasPath(PROPERTY_CINTEROPS_DIR, "cinterops") 106 | 107 | 108 | /** 109 | * Path to the xtras kdocs directory. 110 | * This is where kdoc documentation is generated to. 111 | * 112 | * Defaults to `project.xtrasDir.resolve("docs")` 113 | */ 114 | val Project.xtrasDocsDir: File 115 | get() = xtrasPath(PROPERTY_DOCS_DIR, "docs") 116 | 117 | 118 | /** 119 | * Path to the xtras libs directory. 120 | * This is the install prefix for binary packages 121 | * 122 | * Defaults to `project.xtrasDir.resolve("libs")` 123 | */ 124 | val Project.xtrasLibsDir: File 125 | get() = xtrasPath(PROPERTY_LIBS_DIR, "libs") 126 | 127 | fun String.capitalize() = 128 | replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } 129 | 130 | fun String.decapitalize() = replaceFirstChar { it.lowercase(Locale.getDefault()) } 131 | -------------------------------------------------------------------------------- /repos/README.md: -------------------------------------------------------------------------------- 1 | # Tweaked kotlin native packages with support for linux arm and android native. 2 | 3 | Staging repo: https://s01.oss.sonatype.org/content/groups/staging/ 4 | 5 | ## Status 6 | 7 | ### KotlinX Serialization 8 | 9 | https://github.com/danbrough/kotlinx.serialization.git 10 | upstream: https://github.com/Kotlin/kotlinx.serialization 11 | 12 | - 1.5.0 released 13 | - 1.4.1 upstream now supports linuxArm32 and linuxArm64. Have released a version for android native. 14 | 15 | ### KotlinX Coroutines 16 | 17 | https://github.com:danbrough/kotlinx.coroutines.git 18 | upstream: https://github.com/Kotlin/kotlinx.coroutines.git 19 | 20 | - 1.6.4 released 21 | - kotlinx.coroutines 1.6.3-native-mt in staging. 22 | 23 | ### KotlinX AtomicFU 24 | 25 | https://github.com:danbrough/kotlinx.atomicfu.git 26 | upstream: https://github.com/Kotlin/kotlinx-atomicfu 27 | 28 | - 0.19.0a on branch danbrough-0.19.0 29 | 30 | ### KotlinX DateTime 31 | 32 | https://github.com/danbrough/kotlinx-datetime.git 33 | upstream: https://github.com/Kotlin/kotlinx-datetime.git 34 | 35 | - branch danbroid-v0.4.0 published. Artifact: "org.danbrough.kotlinx:kotlinx-datetime:0.4.0" 36 | 37 | ### Stately 38 | 39 | https://github.com/danbrough/Stately.git 40 | upstream: https://github.com/touchlab/Stately.git 41 | -- in progress 42 | 43 | ### GNU iconv 44 | 45 | https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz 46 | 47 | ### Sqlite 3 48 | 49 | - at version-3.39.3 from https://github.com/sqlite/sqlite.git 50 | 51 | ### Sqliter 52 | 53 | from https://github.com/touchlab/SQLiter.git 54 | 55 | - at danbrough-1.2.1 on https://github.com/danbrough/SQLiter.git 56 | 57 | ### SqlDelight 58 | 59 | upstream: https://github.com/cashapp/sqldelight.git 60 | 61 | - branch danbrough-2.0.0-alpha04 is working with linux arm and android native targets. 62 | 63 | ### KTor 64 | 65 | upstream: https://github.com/ktorio/ktor 66 | repo: https://github.com/danbrough/ktor.git 67 | 68 | - branch danbrough-2.2.4 69 | - branch danbrough-2.2.3 70 | - branch danbrough-2.2.2 tag 2.2.2-danbrough (with support for linuxArm64 and linuxArm32Hfp) 71 | - branch danbrough-2.1.2 72 | 73 | ### Okio 74 | 75 | upstream: https://github.com/square/okio.git 76 | repo: https://github.com/danbrough/okio.git 77 | 78 | - in progress on branch danbrough-3.2.0 79 | 80 | ### Openssl 81 | 82 | repo: https://github.com/danbrough/openssl.git 83 | upstream: git://git.openssl.org/openssl.git 84 | 85 | - tagged openssl3 version: openssl-3.1.0-danbrough 86 | - latest version tag: OpenSSL_1_1_1t-danbrough 87 | 88 | -------------------------------------------------------------------------------- /scripts/clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd `dirname "$0"` && cd .. 4 | 5 | rm -rf build xtras/build common/build core/build buildSrc/build plugin/build 6 | 7 | -------------------------------------------------------------------------------- /scripts/publish_plugins.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd "$(dirname "$0")" && cd .. 3 | 4 | REPO=${1-Xtras} 5 | echo publishing to $REPO 6 | 7 | OPTS="-PpluginsOnly=true" 8 | 9 | if [ "$REPO" == "SonaType" ]; then 10 | ./gradlew plugin:sonatypeOpen -PsonatypeDescription=xtras:plugin 11 | OPTS="-PsignPublications=true -PpublishDocs=true" 12 | fi 13 | 14 | ./gradlew $OPTS plugin:publishAllPublicationsTo${REPO}Repository || exit 1 15 | ./gradlew $OPTS core:publishAllPublicationsTo${REPO}Repository || exit 1 16 | 17 | -------------------------------------------------------------------------------- /scripts/refreshVersions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | cd `dirname $0` && cd .. 5 | 6 | if [ "$1" == "migrate" ]; then 7 | ./gradlew refreshVersionsMigrate 8 | fi 9 | 10 | ./gradlew refreshVersions 11 | 12 | 13 | git diff versions.properties 14 | 15 | -------------------------------------------------------------------------------- /scripts/sonatype_close.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd "$(dirname "$0")" && cd .. 3 | 4 | 5 | 6 | ./gradlew plugin:sonatypeClose 7 | 8 | 9 | #./gradlew -PpluginsOnly=true $OPTS plugin:publishAllPublicationsTo${REPO}Repository || exit 1 10 | # core:publishAllPublicationsTo${REPO}Repository || exit 1 11 | 12 | #[ "$REPO" == "SonaType" ] && ./gradlew plugin:sonatypeClose 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /scripts/sonatype_open.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd "$(dirname "$0")" && cd .. 3 | 4 | DESCRIPTION=${1-"xtras:plugin"} 5 | 6 | #./gradlew plugin:publishAllPublicationsToXtrasRepository 7 | 8 | ./gradlew -PsonatypeDescription="$DESCRIPTION" plugin:sonatypeOpen 9 | 10 | 11 | #./gradlew -PpluginsOnly=true $OPTS plugin:publishAllPublicationsTo${REPO}Repository || exit 1 12 | # core:publishAllPublicationsTo${REPO}Repository || exit 1 13 | 14 | #[ "$REPO" == "SonaType" ] && ./gradlew plugin:sonatypeClose 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | maven(file("build/xtras/maven")) 4 | maven("https://s01.oss.sonatype.org/content/groups/staging") 5 | mavenCentral() 6 | gradlePluginPortal() 7 | google() 8 | } 9 | } 10 | 11 | 12 | plugins { 13 | id("de.fayard.refreshVersions") version "0.51.0" 14 | } 15 | 16 | rootProject.name = "kotlinxtras" 17 | 18 | val pluginsOnly: String? by settings 19 | 20 | //-PpluginsOnly=true or not specified 21 | if (pluginsOnly == null || pluginsOnly.toBoolean()) { 22 | include(":plugin") 23 | include(":core") 24 | } 25 | 26 | //-PpluginsOnly=false or not specified 27 | if (!pluginsOnly.toBoolean()) { 28 | include(":libssh2") 29 | include(":utils") 30 | include(":common") 31 | include(":binaries") 32 | } 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /utils/README.md: -------------------------------------------------------------------------------- 1 | # Utils library 2 | 3 | `org.danbrough.utils.io` package taken from the ktor project. 4 | 5 | Copyright 2014-2021 JetBrains s.r.o and contributors. 6 | Use of this source code is governed by the Apache 2.0 license. 7 | 8 | 9 | -------------------------------------------------------------------------------- /utils/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.danbrough.kotlinxtras.declareSupportedTargets 2 | 3 | 4 | plugins { 5 | kotlin("multiplatform") 6 | xtras("sonatype") 7 | } 8 | 9 | 10 | version = "0.0.1-beta01" 11 | 12 | kotlin { 13 | 14 | declareSupportedTargets() 15 | 16 | 17 | sourceSets { 18 | val commonTest by getting { 19 | dependencies { 20 | implementation(kotlin("test")) 21 | } 22 | } 23 | } 24 | 25 | 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /utils/src/commonMain/kotlin/org/danbrough/utils/io/Base64.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * From the ktor project. 3 | * Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. 4 | */ 5 | 6 | package org.danbrough.utils.io 7 | 8 | import kotlin.experimental.and 9 | 10 | 11 | private const val BASE64_ALPHABET = 12 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 13 | private const val BASE64_MASK: Byte = 0x3f 14 | private const val BASE64_MASK_INT: Int = 0x3f 15 | private const val BASE64_PAD = '=' 16 | fun ByteArray.toBase64(): String { 17 | val array = this@toBase64 18 | var position = 0 19 | var writeOffset = 0 20 | val charArray = CharArray(size * 8 / 6 + 3) 21 | 22 | while (position + 3 <= array.size) { 23 | val first = array[position].toInt() 24 | val second = array[position + 1].toInt() 25 | val third = array[position + 2].toInt() 26 | position += 3 27 | 28 | val chunk = ((first and 0xFF) shl 16) or ((second and 0xFF) shl 8) or (third and 0xFF) 29 | for (index in 3 downTo 0) { 30 | val char = (chunk shr (6 * index)) and BASE64_MASK_INT 31 | charArray[writeOffset++] = (char.toBase64()) 32 | } 33 | } 34 | 35 | val remaining = array.size - position 36 | if (remaining == 0) return charArray.concatToString(0, writeOffset) 37 | 38 | val chunk = if (remaining == 1) { 39 | ((array[position].toInt() and 0xFF) shl 16) or ((0 and 0xFF) shl 8) or (0 and 0xFF) 40 | } else { 41 | ((array[position].toInt() and 0xFF) shl 16) or ((array[position + 1].toInt() and 0xFF) shl 8) or (0 and 0xFF) 42 | } 43 | 44 | val padSize = (3 - remaining) * 8 / 6 45 | for (index in 3 downTo padSize) { 46 | val char = (chunk shr (6 * index)) and BASE64_MASK_INT 47 | charArray[writeOffset++] = char.toBase64() 48 | } 49 | 50 | repeat(padSize) { charArray[writeOffset++] = BASE64_PAD } 51 | 52 | return charArray.concatToString(0, writeOffset) 53 | } 54 | 55 | 56 | fun String.fromBase64(): ByteArray { 57 | val bytes = dropLastWhile { it == BASE64_PAD }.encodeToByteArray() 58 | val bytesLength = bytes.size 59 | val data = ByteArray(4) 60 | val output = mutableListOf() 61 | 62 | for (n in 0 until bytesLength step 4) { 63 | var endIndex = n + 4 64 | if (endIndex > bytesLength) endIndex = bytesLength 65 | bytes.copyInto(data, 0, n, endIndex) 66 | val read = endIndex - n 67 | 68 | val chunk = data.foldIndexed(0) { index, result, current -> 69 | result or (current.fromBase64().toInt() shl ((3 - index) * 6)) 70 | } 71 | 72 | 73 | for (index in data.size - 2 downTo (data.size - read)) { 74 | val origin = (chunk shr (8 * index)) and 0xff 75 | output.add(origin.toByte()) 76 | } 77 | } 78 | 79 | return output.toByteArray() 80 | } 81 | 82 | internal inline fun Int.toBase64(): Char = BASE64_ALPHABET[this] 83 | 84 | private val BASE64_INVERSE_ALPHABET = IntArray(256) { 85 | BASE64_ALPHABET.indexOf(it.toChar()) 86 | } 87 | 88 | internal inline fun Byte.fromBase64(): Byte = 89 | BASE64_INVERSE_ALPHABET[toInt() and 0xff].toByte() and BASE64_MASK -------------------------------------------------------------------------------- /utils/src/commonMain/kotlin/org/danbrough/utils/io/Hex.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * From the ktor project. 3 | * Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. 4 | */ 5 | package org.danbrough.utils.io 6 | 7 | private val digits = "0123456789abcdef".toCharArray() 8 | 9 | /** 10 | * Encode [bytes] as a HEX string with no spaces, newlines and `0x` prefixes. 11 | */ 12 | fun hex(bytes: ByteArray): String { 13 | val result = CharArray(bytes.size * 2) 14 | var resultIndex = 0 15 | val digits = digits 16 | 17 | for (element in bytes) { 18 | val b = element.toInt() and 0xff 19 | result[resultIndex++] = digits[b shr 4] 20 | result[resultIndex++] = digits[b and 0x0f] 21 | } 22 | 23 | return result.concatToString() 24 | } 25 | 26 | 27 | fun hex(s: String): ByteArray { 28 | val result = ByteArray(s.length / 2) 29 | for (idx in result.indices) { 30 | val srcIdx = idx * 2 31 | val high = s[srcIdx].toString().toInt(16) shl 4 32 | val low = s[srcIdx + 1].toString().toInt(16) 33 | result[idx] = (high or low).toByte() 34 | } 35 | 36 | return result 37 | } 38 | 39 | 40 | fun ByteArray.toHex(): String = hex(this) 41 | 42 | fun String.fromHex(): ByteArray = hex(this) 43 | -------------------------------------------------------------------------------- /versions.properties: -------------------------------------------------------------------------------- 1 | #### Dependencies and Plugin versions with their available updates. 2 | #### Generated by `./gradlew refreshVersions` version 0.51.0 3 | #### 4 | #### Don't manually edit or split the comments that start with four hashtags (####), 5 | #### they will be overwritten by refreshVersions. 6 | #### 7 | #### suppress inspection "SpellCheckingInspection" for whole file 8 | #### suppress inspection "UnusedProperty" for whole file 9 | 10 | version.org.jetbrains.dokka..dokka-gradle-plugin=1.8.20 11 | 12 | version.kotlin=1.9.0 13 | 14 | plugin.org.jetbrains.dokka=1.8.20 15 | --------------------------------------------------------------------------------