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 7, 2023
1 parent 3e636be commit d8b1be5
Show file tree
Hide file tree
Showing 42 changed files with 1,123 additions and 599 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
28 changes: 2 additions & 26 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 All @@ -28,7 +27,6 @@ kotlin {
}
if (os.isMacOsX) {
ios()
macosX64()
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
iosSimulatorArm64()
macosArm64()
Expand Down Expand Up @@ -69,21 +67,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 Expand Up @@ -115,22 +98,15 @@ kotlin {
val iosMain by getting
val iosTest by getting

val macosX64Main by getting
val macosX64Test by getting

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
val macosArm64Test by getting
}
}
}
Expand Down
17 changes: 6 additions & 11 deletions base-asymmetric-encryption/base_asymmetric_encryption.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@ Pod::Spec.new do |spec|
spec.version = '1.7.0-alpha'
spec.homepage = ''
spec.source = { :http=> ''}
spec.authors = 'IOG'
spec.authors = ''
spec.license = ''
spec.summary = 'ApolloBaseAsymmetricEncryption is a base for symmetric encryption libs'
spec.vendored_frameworks = 'build/cocoapods/framework/ApolloBaseAsymmetricEncryption.framework'
spec.summary = ''
spec.vendored_frameworks = 'build/cocoapods/framework/base_asymmetric_encryption.framework'
spec.libraries = 'c++'
spec.ios.deployment_target = '13.0'
spec.osx.deployment_target = '12.0'
spec.tvos.deployment_target = '13.0'
spec.watchos.deployment_target = '8.0'
spec.dependency 'IOHKCryptoKit', '1.0.0'
spec.dependency 'IOHKRSA', '1.0.0'
spec.dependency 'IOHKSecureRandomGeneration', '1.0.0'



spec.pod_target_xcconfig = {
'KOTLIN_PROJECT_PATH' => ':base-asymmetric-encryption',
'PRODUCT_MODULE_NAME' => 'ApolloBaseAsymmetricEncryption',
'PRODUCT_MODULE_NAME' => 'base_asymmetric_encryption',
}

spec.script_phases = [
Expand Down
157 changes: 69 additions & 88 deletions base-asymmetric-encryption/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ val os: OperatingSystem = OperatingSystem.current()

plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.chromaticnoise.multiplatform-swiftpackage") version "2.0.3"
val osName = System.getProperty("os.name").toLowerCase()
if (osName.contains("mac os x") || osName.contains("darwin") || osName.contains("osx")) {
if (System.getProperty("os.arch") != "x86_64") { // M1Chip
id("io.github.luca992.multiplatform-swiftpackage") version "2.0.5-arm64"
} else {
id("io.github.luca992.multiplatform-swiftpackage") version("2.0.3")
}
}
id("com.android.library")
id("org.jetbrains.dokka")
}
Expand All @@ -29,14 +35,60 @@ kotlin {
useJUnitPlatform()
}
}
ios()
macosX64()

fun org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget.swiftCinterop(library: String, platform: String) {
compilations.getByName("main") {
cinterops.create(library) {
extraOpts = listOf("-compiler-option", "-DNS_FORMAT_ARGUMENT(A)=")
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 {
swiftCinterop("IOHKCryptoKit", name)
swiftCinterop("IOHKSecureRandomGeneration", name)

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

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

swiftCinterop("IOHKCryptoKit", name)
swiftCinterop("IOHKSecureRandomGeneration", name)
}
// tvosSimulatorArm64()
// watchosSimulatorArm64()
macosArm64()
macosArm64 {
binaries.framework {
baseName = currentModuleName
embedBitcode("disable")
}

swiftCinterop("IOHKCryptoKit", name)
swiftCinterop("IOHKSecureRandomGeneration", name)
}
}
js(IR) {
this.moduleName = currentModuleName
Expand All @@ -54,24 +106,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 @@ -89,37 +132,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 {
this.baseName = currentModuleName
}

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 @@ -198,21 +210,15 @@ kotlin {
val iosTest by getting {
this.dependsOn(commonTest)
}
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(iosMain) }
val macosArm64Test by getting { this.dependsOn(iosTest) }
}
// 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 @@ -275,15 +281,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 @@ -294,28 +300,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,33 +1,21 @@
package io.iohk.atala.prism.apollo.utils

import cocoapods.IOHKCryptoKit.Ed25519
import kotlinx.cinterop.ObjCObjectVar
import kotlinx.cinterop.alloc
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.ptr
import kotlinx.cinterop.value
import platform.Foundation.NSError
import swift.cryptoKit.Ed25519

public actual class KMMEdPrivateKey(val raw: ByteArray = Ed25519.createPrivateKey().toByteArray()) {
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")
}
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 {
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)
}
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)
}
}
Loading

0 comments on commit d8b1be5

Please sign in to comment.