Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ATL-5386: Remove cocoapods so it works on the iOS #87

Merged
merged 1 commit into from
Aug 8, 2023
Merged
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
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
150 changes: 62 additions & 88 deletions base-asymmetric-encryption/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ val os: OperatingSystem = OperatingSystem.current()

plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.chromaticnoise.multiplatform-swiftpackage") version "2.0.3"
id("io.github.luca992.multiplatform-swiftpackage") version "2.0.5-arm64"
Copy link
Contributor

@hamada147 hamada147 Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
id("io.github.luca992.multiplatform-swiftpackage") version "2.0.5-arm64"
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")
}
}

Copy link
Contributor Author

@goncalo-frade-iohk goncalo-frade-iohk Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to add this? I don't think it makes a difference :) also I tried doing this and it was giving me an error when I add an If like so inside the plugins {...}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I've update the code snippet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated to code. This version should work inside the plugins block now.

id("com.android.library")
id("org.jetbrains.dokka")
}
Expand All @@ -29,14 +28,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 +99,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 +125,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 +203,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 +274,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 +293,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
Loading