Skip to content

Commit

Permalink
feat(ios): removed cocoapods and made all the ios libs as static
Browse files Browse the repository at this point in the history
This change was needed because ios requires a dependency manager for any dependency.
Using cocoapods for internal xcode projects would not work quite right when trying to use Apollo as a framework.
  • Loading branch information
goncalo-frade-iohk committed Aug 2, 2023
1 parent f4303c7 commit e2a7517
Show file tree
Hide file tree
Showing 29 changed files with 407 additions and 630 deletions.
27 changes: 0 additions & 27 deletions aes/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ val os: OperatingSystem = OperatingSystem.current()

plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.android.library")
id("org.jetbrains.dokka")
}
Expand Down Expand Up @@ -77,32 +76,6 @@ kotlin {
}
}

if (os.isMacOsX) {
cocoapods {
this.summary = "ApolloAES is an AES lib"
this.version = rootProject.version.toString()
this.authors = "IOG"
this.ios.deploymentTarget = "13.0"
this.osx.deploymentTarget = "12.0"
this.tvos.deploymentTarget = "13.0"
this.watchos.deploymentTarget = "8.0"
framework {
this.baseName = currentModuleName
}
// workaround for KMM bug
pod("IOHKSecureRandomGeneration") {
version = "1.0.0"
packageName = "IOHKSecureRandomGeneration1"
source = path(project.file("../iOSLibs/IOHKSecureRandomGeneration"))
}

pod("IOHKAES") {
version = "1.0.0"
source = path(project.file("../iOSLibs/IOHKAES"))
}
}
}

sourceSets {
val commonMain by getting {
dependencies {
Expand Down
16 changes: 0 additions & 16 deletions apollo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ val os: OperatingSystem = OperatingSystem.current()

plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.android.library")
id("org.jetbrains.dokka")
}
Expand Down Expand Up @@ -69,21 +68,6 @@ kotlin {
}
}

if (os.isMacOsX) {
cocoapods {
this.summary = "Apollo"
this.version = rootProject.version.toString()
this.authors = "IOG"
this.ios.deploymentTarget = "13.0"
this.osx.deploymentTarget = "12.0"
this.tvos.deploymentTarget = "13.0"
this.watchos.deploymentTarget = "8.0"
framework {
this.baseName = currentModuleName
}
}
}

sourceSets {
val commonMain by getting {
dependencies {
Expand Down
166 changes: 53 additions & 113 deletions base-asymmetric-encryption/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,58 +33,64 @@ kotlin {
compilations.getByName("main") {
cinterops.create(library) {
extraOpts = listOf("-compiler-option", "-DNS_FORMAT_ARGUMENT(A)=")
includeDirs.headerFilterOnly("$rootDir/iOSLibs/$library/build/")
tasks[interopProcessingTaskName].dependsOn(":iOSLibs:build${library.capitalize()}${platform.capitalize()}")
when (platform) {
"iosX64", "iosSimulatorArm64" -> {
includeDirs.headerFilterOnly("$rootDir/iOSLibs/$library/build/Release-iphonesimulator/include/")
tasks[interopProcessingTaskName].dependsOn(":iOSLibs:build${library.capitalize()}Iphonesimulator")
}
"iosArm64" -> {
includeDirs.headerFilterOnly("$rootDir/iOSLibs/$library/build/Release-iphoneos/include/")
tasks[interopProcessingTaskName].dependsOn(":iOSLibs:build${library.capitalize()}Iphoneos")
}
"macosX64", "macosArm64" -> {
includeDirs.headerFilterOnly("$rootDir/iOSLibs/$library/build/Release/include/")
tasks[interopProcessingTaskName].dependsOn(":iOSLibs:build${library.capitalize()}Macosx")
}
}
}
}
}

ios() {
binaries.all {
swiftCinterop("IOHKCryptoKit", name)
swiftCinterop("IOHKSecureRandomGeneration", name)

binaries.framework {
baseName = currentModuleName
embedBitcode("disable")
}
}
macosX64() {
binaries.framework {
baseName = currentModuleName
embedBitcode("disable")
}

swiftCinterop("IOHKCryptoKit", name)
swiftCinterop("IOHKSecureRandomGeneration", name)

// compilations.getByName("main") {
// cinterops.create("SwiftCryptoKit") {
// extraOpts = listOf("-compiler-option", "-DNS_FORMAT_ARGUMENT(A)=")
// includeDirs.headerFilterOnly("$rootDir/iOSLibs/SwiftCryptoKit/build/")
// tasks[interopProcessingTaskName].dependsOn(":iOSLibs:buildSwiftCryptoKitIphone")
// }
// }
}
// macosX64() {
// binaries.all {
// baseName = currentModuleName
// linkerOpts("-L../iOSLibs/IOHKCryptoKit/build/x86_64-macos/libIOHKCryptoKit.a")
// }
//
// swiftCinterop("IOHKCryptoKit", name)
// swiftCinterop("IOHKSecureRandomGeneration", name)
// }

if (System.getProperty("os.arch") != "x86_64") { // M1Chip
iosSimulatorArm64() {
binaries.all {
binaries.framework {
baseName = currentModuleName
embedBitcode("disable")
}

swiftCinterop("IOHKCryptoKit", name)
swiftCinterop("IOHKSecureRandomGeneration", name)
}
// tvosSimulatorArm64()
// watchosSimulatorArm64()
// macosArm64() {
// binaries.all {
// baseName = currentModuleName
// linkerOpts("-L../iOSLibs/IOHKCryptoKit/build/arm64-macos/libIOHKCryptoKit.a")
// }
//
// swiftCinterop("IOHKCryptoKit", name)
// swiftCinterop("IOHKSecureRandomGeneration", name)
// }
macosArm64() {
binaries.framework {
baseName = currentModuleName
embedBitcode("disable")
}

swiftCinterop("IOHKCryptoKit", name)
swiftCinterop("IOHKSecureRandomGeneration", name)
}
}
js(IR) {
this.moduleName = currentModuleName
Expand All @@ -102,24 +108,15 @@ kotlin {
this.output.libraryTarget = Target.VAR
}
this.commonWebpackConfig {
this.cssSupport {
this.enabled = true
}
}
this.testTask {
if (os.isWindows) {
this.enabled = false
}
this.useKarma {
this.useChromeHeadless()
}
}
}
nodejs {
this.testTask {
if (os.isWindows) {
this.enabled = false
}
this.useKarma {
this.useChromeHeadless()
}
Expand All @@ -137,38 +134,6 @@ kotlin {
outputDirectory(File(rootDir, "base-asymmetric-encryption/build/packages/ApolloSwift"))
}

// if (os.isMacOsX) {
// cocoapods {
// this.summary = "ApolloBaseAsymmetricEncryption is a base for symmetric encryption libs"
// this.version = rootProject.version.toString()
// this.authors = "IOG"
// this.ios.deploymentTarget = "13.0"
// this.osx.deploymentTarget = "12.0"
// this.tvos.deploymentTarget = "13.0"
// this.watchos.deploymentTarget = "8.0"
// framework {
// baseName = currentModuleName
// isStatic = false
// }
//
// pod("IOHKRSA") {
// version = "1.0.0"
// source = path(project.file("../iOSLibs/IOHKRSA"))
// }
//
// pod("IOHKSecureRandomGeneration") {
// version = "1.0.0"
// packageName = "IOHKSecureRandomGeneration1"
// source = path(project.file("../iOSLibs/IOHKSecureRandomGeneration"))
// }
//
// pod("IOHKCryptoKit") {
// version = "1.0.0"
// source = path(project.file("../iOSLibs/IOHKCryptoKit"))
// }
// }
// }

sourceSets {
val commonMain by getting {
dependencies {
Expand Down Expand Up @@ -247,21 +212,21 @@ kotlin {
val iosTest by getting {
this.dependsOn(commonTest)
}
// val macosX64Main by getting {
// this.dependsOn(iosMain)
// }
// val macosX64Test by getting {
// this.dependsOn(iosTest)
// }
val macosX64Main by getting {
this.dependsOn(iosMain)
}
val macosX64Test by getting {
this.dependsOn(iosTest)
}
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
val iosSimulatorArm64Main by getting {
this.dependsOn(iosMain)
}
val iosSimulatorArm64Test by getting {
this.dependsOn(iosTest)
}
// val macosArm64Main by getting { this.dependsOn(macosX64Main) }
// val macosArm64Test by getting { this.dependsOn(macosX64Test) }
val macosArm64Main by getting { this.dependsOn(macosX64Main) }
val macosArm64Test by getting { this.dependsOn(macosX64Test) }
}
// if (os.isWindows) {
// // val mingwX86Main by getting // it depend on kotlinx-datetime lib to support this platform before we can support it as well
Expand Down Expand Up @@ -324,15 +289,15 @@ tasks.withType<DokkaTask> {
}
}

// afterEvaluate {
// tasks.withType<AbstractTestTask> {
// testLogging {
// events("passed", "skipped", "failed", "standard_out", "standard_error")
// showExceptions = true
// showStackTraces = true
// }
// }
// }
afterEvaluate {
tasks.withType<AbstractTestTask> {
testLogging {
events("passed", "skipped", "failed", "standard_out", "standard_error")
showExceptions = true
showStackTraces = true
}
}
}

ktlint {
filter {
Expand All @@ -343,28 +308,3 @@ ktlint {
exclude { projectDir.toURI().relativize(it.file.toURI()).path.contains("/external/") }
}
}

// TODO(Investigate why the below tasks fails)
tasks.matching {
fun String.isOneOf(values: List<String>): Boolean {
for (value in values) {
if (this == value) {
return true
}
}
return false
}

it.name.isOneOf(
listOf(
"linkPodReleaseFrameworkIosFat",
":linkPodReleaseFrameworkIosFat",
":base-asymmetric-encryption:linkPodReleaseFrameworkIosFat",
"linkPodDebugFrameworkIosFat",
":linkPodDebugFrameworkIosFat",
":base-asymmetric-encryption:linkPodDebugFrameworkIosFat"
)
)
}.all {
this.enabled = false
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
package io.iohk.atala.prism.apollo.utils

import swift.cryptoKit.Ed25519

public actual class KMMEdPrivateKey(val raw: ByteArray = ByteArray(0)) {
//
// @Throws(RuntimeException::class)
// actual fun sign(message: ByteArray): ByteArray {
// memScoped {
// val errorRef = alloc<ObjCObjectVar<NSError?>>()
// val result = Ed25519.signWithPrivateKey(raw.toNSData(), message.toNSData(), errorRef.ptr)
// errorRef.value?.let { throw RuntimeException(it.localizedDescription()) }
// return result?.toByteArray() ?: throw RuntimeException("Null result")
// }
// }
//

@Throws(RuntimeException::class)
public fun publicKey(): KMMEdPublicKey {
TODO("Not yet implemented")
// memScoped {
// val errorRef = alloc<ObjCObjectVar<NSError?>>()
// val result = Ed25519.publicKeyWithPrivateKey(raw.toNSData(), errorRef.ptr)
// errorRef.value?.let { throw RuntimeException(it.localizedDescription()) }
// val publicRaw = result?.toByteArray() ?: throw RuntimeException("Null result")
// return KMMEdPublicKey(publicRaw)
// }
}
actual fun sign(message: ByteArray): ByteArray {
TODO("Not yet implemented")
val result = Ed25519.signWithPrivateKey(raw.toNSData(), message.toNSData())
result.failure()?.let { throw RuntimeException(it.localizedDescription()) }
return result.success()?.toByteArray() ?: throw RuntimeException("Null result")
}

@Throws(RuntimeException::class)
public fun publicKey(): KMMEdPublicKey {
val result = Ed25519.publicKeyWithPrivateKey(raw.toNSData())
result.failure()?.let { throw RuntimeException(it.localizedDescription()) }
val publicRaw = result.success()?.toByteArray() ?: throw RuntimeException("Null result")
return KMMEdPublicKey(publicRaw)
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package io.iohk.atala.prism.apollo.utils

import swift.cryptoKit.Ed25519

public actual class KMMEdPublicKey(val raw: ByteArray = ByteArray(0)) {
//
// @Throws(RuntimeException::class)
// actual fun verify(message: ByteArray, sig: ByteArray): Boolean {
// memScoped {
// val errorRef = alloc<ObjCObjectVar<NSError?>>()
// val result = Ed25519.verifyWithPublicKey(raw.toNSData(), sig.toNSData(), message.toNSData(), errorRef.ptr)
// errorRef.value?.let { throw RuntimeException(it.localizedDescription()) }
// return result?.boolValue ?: throw RuntimeException("Null result")
// }
// }

@Throws(RuntimeException::class)
actual fun verify(message: ByteArray, sig: ByteArray): Boolean {
TODO("Not yet implemented")
val result = Ed25519.verifyWithPublicKey(raw.toNSData(), sig.toNSData(), message.toNSData())
result.failure()?.let { throw RuntimeException(it.localizedDescription()) }
return result.success()?.boolValue ?: throw RuntimeException("Null result")
}
}
Loading

0 comments on commit e2a7517

Please sign in to comment.