Skip to content

Commit

Permalink
fix: The need to publish another module to use Apollo
Browse files Browse the repository at this point in the history
- Remove Secp256k1-kmp module as dependency and use the module as source code only.

Signed-off-by: Ahmed Moussa <[email protected]>
  • Loading branch information
hamada147 committed Mar 11, 2024
1 parent 046e5de commit c2ea292
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 22 deletions.
99 changes: 95 additions & 4 deletions apollo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dev.petuska.npm.publish.extension.domain.NpmAccess
import org.gradle.internal.os.OperatingSystem
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.plugin.mpp.BitcodeEmbeddingMode
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackOutput.Target
import org.jetbrains.kotlin.gradle.tasks.CInteropProcess
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand All @@ -10,6 +11,7 @@ import java.time.Year

val currentModuleName: String = "Apollo"
val os: OperatingSystem = OperatingSystem.current()
val secp256k1Dir = rootDir.resolve("secp256k1-kmp")

plugins {
kotlin("multiplatform")
Expand All @@ -19,7 +21,13 @@ plugins {
id("dev.petuska.npm.publish") version "3.4.1"
}

fun org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget.swiftCinterop(library: String, platform: String) {
/**
* Adds a Swift interop configuration for a library.
*
* @param library The name of the library.
* @param platform The platform for which the interop is being configured.
*/
fun KotlinNativeTarget.swiftCinterop(library: String, platform: String) {
compilations.getByName("main") {
cinterops.create(library) {
extraOpts = listOf("-compiler-option", "-DNS_FORMAT_ARGUMENT(A)=")
Expand All @@ -41,6 +49,27 @@ fun org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget.swiftCinterop(libr
}
}

/**
* Configures the interop settings for the `secp256k1CInterop` method.
*
* @param target The target platform for which to configure the interop.
* @throws IllegalStateException if the compilation is not found or if the interop processing task dependency is not properly set.
*/
fun KotlinNativeTarget.secp256k1CInterop(target: String) {
compilations["main"].cinterops {
val libsecp256k1 by creating {
includeDirs.headerFilterOnly(
secp256k1Dir
.resolve("native")
.resolve("secp256k1")
.resolve("include")
)
tasks[interopProcessingTaskName]
.dependsOn(":secp256k1-kmp:native:buildSecp256k1${target.replaceFirstChar(Char::uppercase)}")
}
}
}

/**
* The `javadocJar` variable is used to register a `Jar` task to generate a Javadoc JAR file.
* The Javadoc JAR file is created with the classifier "javadoc" and it includes the HTML documentation generated
Expand Down Expand Up @@ -77,6 +106,19 @@ kotlin {
swiftCinterop("IOHKSecureRandomGeneration", name)
swiftCinterop("IOHKCryptoKit", name)

secp256k1CInterop("ios")
// https://youtrack.jetbrains.com/issue/KT-39396
compilations["main"].kotlinOptions.freeCompilerArgs += listOf(
"-include-binary",
secp256k1Dir
.resolve("native")
.resolve("build")
.resolve("ios")
.resolve("arm64-iphoneos")
.resolve("libsecp256k1.a")
.absolutePath
)

binaries.framework {
baseName = "ApolloLibrary"
embedBitcode(BitcodeEmbeddingMode.DISABLE)
Expand All @@ -86,6 +128,19 @@ kotlin {
swiftCinterop("IOHKSecureRandomGeneration", name)
swiftCinterop("IOHKCryptoKit", name)

secp256k1CInterop("ios")
// https://youtrack.jetbrains.com/issue/KT-39396
compilations["main"].kotlinOptions.freeCompilerArgs += listOf(
"-include-binary",
secp256k1Dir
.resolve("native")
.resolve("build")
.resolve("ios")
.resolve("x86_x64-iphonesimulator")
.resolve("libsecp256k1.a")
.absolutePath
)

binaries.framework {
baseName = "ApolloLibrary"
embedBitcode(BitcodeEmbeddingMode.DISABLE)
Expand All @@ -100,6 +155,19 @@ kotlin {
swiftCinterop("IOHKSecureRandomGeneration", name)
swiftCinterop("IOHKCryptoKit", name)

secp256k1CInterop("ios")
// https://youtrack.jetbrains.com/issue/KT-39396
compilations["main"].kotlinOptions.freeCompilerArgs += listOf(
"-include-binary",
secp256k1Dir
.resolve("native")
.resolve("build")
.resolve("ios")
.resolve("arm64-iphonesimulator")
.resolve("libsecp256k1.a")
.absolutePath
)

binaries.framework {
baseName = "ApolloLibrary"
embedBitcode(BitcodeEmbeddingMode.DISABLE)
Expand All @@ -109,6 +177,19 @@ kotlin {
swiftCinterop("IOHKSecureRandomGeneration", name)
swiftCinterop("IOHKCryptoKit", name)

secp256k1CInterop("macosArm64")
// https://youtrack.jetbrains.com/issue/KT-39396
compilations["main"].kotlinOptions.freeCompilerArgs += listOf(
"-include-binary",
secp256k1Dir
.resolve("native")
.resolve("build")
.resolve("ios")
.resolve("arm64-macosx")
.resolve("libsecp256k1.a")
.absolutePath
)

binaries.framework {
baseName = "ApolloLibrary"
embedBitcode(BitcodeEmbeddingMode.DISABLE)
Expand Down Expand Up @@ -219,9 +300,16 @@ kotlin {
val jsTest by getting

val appleMain by getting {
dependencies {
implementation(project(":secp256k1-kmp"))
}
kotlin.srcDirs(
secp256k1Dir
.resolve("src")
.resolve("commonMain")
.resolve("kotlin"),
secp256k1Dir
.resolve("src")
.resolve("nativeMain")
.resolve("kotlin")
)
}
}

Expand Down Expand Up @@ -395,6 +483,9 @@ afterEvaluate {
tasks.withType<PublishToMavenRepository> {
dependsOn(tasks.withType<Sign>())
}
tasks.withType<PublishToMavenLocal> {
dependsOn(tasks.withType<Sign>())
}
// Disable publish of targets
if (tasks.findByName("publishIosX64PublicationToSonatypeRepository") != null) {
tasks.named("publishIosX64PublicationToSonatypeRepository") {
Expand Down
10 changes: 10 additions & 0 deletions apollo/src/nativeInterop/cinterop/libsecp256k1.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package = secp256k1

headers = secp256k1.h secp256k1_ecdh.h secp256k1_recovery.h secp256k1_extrakeys.h secp256k1_schnorrsig.h
headerFilter = secp256k1/** secp256k1_ecdh.h secp256k1_recovery.h secp256k1_extrakeys.h secp256k1_schnorrsig.h secp256k1.h

libraryPaths.linux = c/secp256k1/build/linux/
linkerOpts.linux = -L/usr/lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib

libraryPaths.ios = c/secp256k1/build/ios/ /usr/local/lib
linkerOpts.ios = -framework Security -framework Foundation
22 changes: 8 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import java.util.Base64
val publishedMavenId: String = "io.iohk.atala.prism.apollo"

plugins {
id("org.jetbrains.dokka") version "1.9.10"
id("org.jetbrains.dokka") version "1.9.20"
id("org.jlleitschuh.gradle.ktlint") version "11.6.1"
id("maven-publish")
id("org.jetbrains.kotlinx.kover") version "0.7.5"
Expand All @@ -20,7 +20,7 @@ buildscript {
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22")
classpath("org.jetbrains.dokka:dokka-base:1.9.10")
classpath("org.jetbrains.dokka:dokka-base:1.9.20")
}
}

Expand Down Expand Up @@ -126,22 +126,16 @@ allprojects {
signing {
val base64EncodedAsciiArmoredSigningKey: String = System.getenv("BASE64_ARMORED_GPG_SIGNING_KEY_MAVEN") ?: ""
val signingKeyPassword: String = System.getenv("SIGNING_KEY_PASSWORD") ?: ""
useInMemoryPgpKeys(String(Base64.getDecoder().decode(base64EncodedAsciiArmoredSigningKey.toByteArray())), signingKeyPassword)
useInMemoryPgpKeys(
String(
Base64.getDecoder().decode(base64EncodedAsciiArmoredSigningKey.toByteArray())
),
signingKeyPassword
)
sign(this@withType)
}
}
}
repositories {
// GitHub Maven Repo
// maven {
// this.name = "GitHubPackages"
// this.url = uri("https://maven.pkg.github.com/input-output-hk/atala-prism-apollo")
// credentials {
// this.username = System.getenv("ATALA_GITHUB_ACTOR")
// this.password = System.getenv("ATALA_GITHUB_TOKEN")
// }
// }
}
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions secp256k1-kmp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
api("com.ionspin.kotlin:bignum:0.3.8")
api("com.ionspin.kotlin:bignum:0.3.9")
}
}
val nativeMain by getting {
Expand Down Expand Up @@ -112,7 +112,4 @@ afterEvaluate {
tasks.withType<PublishToMavenRepository>().configureEach {
enabled = false
}
tasks.withType<PublishToMavenLocal>().configureEach {
enabled = false
}
}

0 comments on commit c2ea292

Please sign in to comment.