Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions kotlin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Module Iroh

A toolkit for building distributed applications
3 changes: 2 additions & 1 deletion kotlin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties

org.gradle.configuration-cache=true

org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
2 changes: 2 additions & 0 deletions kotlin/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", vers

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version = "2.0.20" }
dokka = { id = "org.jetbrains.dokka", version = "2.0.0" }

159 changes: 158 additions & 1 deletion kotlin/lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* This file was generated by the Gradle 'init' task.
*
Expand All @@ -12,8 +11,15 @@ plugins {

// Apply the java-library plugin for API and implementation separation.
`java-library`

`maven-publish`
alias(libs.plugins.dokka)
signing
}

group = "computer.iroh"
version = "0.31.0"

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
Expand All @@ -35,6 +41,8 @@ dependencies {

// Apply a specific Java toolchain to ease working on different environments.
java {
withJavadocJar()
withSourcesJar()
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
Expand All @@ -46,6 +54,52 @@ kotlin {
}
}

val nativeLibraryDir = rootDir.resolve("..").normalize()
val profile = providers.gradleProperty("profile").orElse("release")

val buildNativeLibraryTask by tasks.register<Exec>("buildNativeLibrary") {
inputs.dir(nativeLibraryDir.resolve("src"))
inputs.files(
nativeLibraryDir.resolve("Cargo.toml"),
nativeLibraryDir.resolve("Cargo.lock"),
nativeLibraryDir.resolve("build.rs"),
)
outputs.dir(nativeLibraryDir.resolve("target"))

workingDir = nativeLibraryDir
commandLine = listOf(
"cargo", "build",
"--lib", "--profile", profile.get(),
"--color", "always",
)
}

val generateNativeBindingsTask by tasks.register<Exec>("generateNativeBindings") {
dependsOn(buildNativeLibraryTask)

val libName = System.mapLibraryName("iroh_ffi")
val libFile = nativeLibraryDir.resolve("target/${profile.get()}/$libName")
val generatedFFIDir = layout.buildDirectory.dir("generated/uniffi/main/kotlin")

inputs.file(libFile)
outputs.dir(generatedFFIDir)

workingDir = nativeLibraryDir
commandLine = listOf(
"cargo", "run", "--bin", "uniffi-bindgen",
"generate",
"--language", "kotlin",
"--out-dir", generatedFFIDir.get().asFile.absolutePath,
"--config", "uniffi.toml",
"--library", libFile.absolutePath,
"--no-format", // roughly 60x speedup
)
}

sourceSets.main {
kotlin.srcDir(generateNativeBindingsTask)
}

tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
Expand All @@ -57,3 +111,106 @@ tasks.named<Test>("test") {
events("passed", "skipped", "failed")
}
}

val stagingDir = layout.buildDirectory.dir("staging")

signing {
// Use property `signing.keyId` to pick GPG signing key
// e.g. `./gradlew publish -Psigning.keyId=24875D73`
// Or, place it in `~/.gradle/gradle.properties` for persistence.

useGpgCmd()
sign(publishing.publications)
}

dokka {
moduleName = "Iroh"
dokkaSourceSets.main {
includes.from(rootProject.projectDir.resolve("README.md"))
sourceLink {
localDirectory = file("src/main/kotlin")
remoteUrl("https://github.com/n0-computer/iroh-ffi/blob/main/kotlin/lib/src/main/kotlin")
remoteLineSuffix.set("#L")
}
}
pluginsConfiguration.html {
footerMessage.set("© n0, inc.")
}
// Runs Dokka in the current Gradle process
dokkaGeneratorIsolation = ClassLoaderIsolation()
}

tasks.named("javadocJar", Jar::class) {
dependsOn(tasks.dokkaGenerate)
from(layout.buildDirectory.dir("dokka/html"))
}

publishing {
publications {
register<MavenPublication>("maven") {
groupId = project.group.toString()
version = project.version.toString()
artifactId = "iroh"

pom {
// https://central.sonatype.org/publish/requirements/#required-pom-metadata

name = "Iroh"
description = "A toolkit for building distributed applications"
inceptionYear = "2025"
url = "https://iroh.computer"

developers {
developer {
id = "number0"
email = "[email protected]"
organization = "number0"
organizationUrl = "https://n0.computer"
}
}

licenses {
license {
name = "Apache License, Version 2.0"
url = "https://opensource.org/license/apache-2-0"
}
license {
name = "The MIT License"
url = "https://opensource.org/licenses/MIT"
}
}

scm {
connection = "scm:git:git://https://github.com/n0-computer/iroh-ffi.git"
developerConnection = "scm:git:ssh://https://github.com/n0-computer/iroh-ffi.git"
url = "https://github.com/n0-computer/iroh-ffi"
}
}

from(components["java"])
}
}

repositories {
maven(uri(stagingDir)) {
name = "staging"
}
}
}

val cleanStagingDir by tasks.register<Delete>("cleanStagingDir") {
delete(stagingDir)
}

val stagingDirJar by tasks.register<Jar>("stagingDirJar") {
from(stagingDir)
archiveFileName.set("deploy.jar")
}

tasks.named("publishMavenPublicationToStagingRepository") {
dependsOn(cleanStagingDir)
}

tasks.publish {
finalizedBy(stagingDirJar)
}
Loading
Loading