From 72716832ad5dd3ac2607c7ad506ede3fb3fcd22c Mon Sep 17 00:00:00 2001 From: Kendall Weihe Date: Fri, 5 Jul 2024 11:18:57 -0400 Subject: [PATCH] Begin MultiArchitecture --- .../kotlin/tbdex/sdk/httpclient/Offerings.kt | 4 +- .../tbdex/sdk/rust/MultiArchitecture.kt | 66 +++++++++++++++++++ .../E2ePfiExemplarIntegrationTest.kt | 1 + 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 bound/kt/src/main/kotlin/tbdex/sdk/rust/MultiArchitecture.kt diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Offerings.kt b/bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Offerings.kt index 491c6bde..a39e5621 100644 --- a/bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Offerings.kt +++ b/bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Offerings.kt @@ -2,8 +2,10 @@ package tbdex.sdk.httpclient import tbdex.sdk.resources.Offering import tbdex.sdk.rust.getOfferings as rustCoreGetOfferings +import tbdex.sdk.rust.MultiArchitecture as RustCore fun getOfferings(pfiDidUri: String): List { - val rustCoreOfferings = rustCoreGetOfferings(pfiDidUri) +// val rustCoreOfferings = rustCoreGetOfferings(pfiDidUri) + val rustCoreOfferings = RustCore.getOfferings(pfiDidUri) return rustCoreOfferings.map { Offering(it) } } \ No newline at end of file diff --git a/bound/kt/src/main/kotlin/tbdex/sdk/rust/MultiArchitecture.kt b/bound/kt/src/main/kotlin/tbdex/sdk/rust/MultiArchitecture.kt new file mode 100644 index 00000000..d28df3a5 --- /dev/null +++ b/bound/kt/src/main/kotlin/tbdex/sdk/rust/MultiArchitecture.kt @@ -0,0 +1,66 @@ +package tbdex.sdk.rust + +import java.io.File + +private enum class SystemArchitecture { + MAC_APPLE_SILICON, + MAC_INTEL, + LINUX_UBUNTU_AMD64, + LINUX_ALPINE_AMD64, + UNSUPPORTED +} + +private fun getSystemArchitecture(): SystemArchitecture { + val arch = System.getProperty("os.arch")?.lowercase() ?: return SystemArchitecture.UNSUPPORTED + val name = System.getProperty("os.name")?.lowercase() ?: return SystemArchitecture.UNSUPPORTED + + return when { + name.contains("mac") && arch.contains("aarch64") -> SystemArchitecture.MAC_APPLE_SILICON + name.contains("mac") && arch.contains("x86_64") -> SystemArchitecture.MAC_INTEL + + name.contains("linux") && arch.contains("amd64") -> { + val osRelease = File("/etc/os-release") + if (osRelease.exists()) { + val osReleaseContent = osRelease.readText().lowercase() + when { + osReleaseContent.contains("ubuntu") -> SystemArchitecture.LINUX_UBUNTU_AMD64 + osReleaseContent.contains("alpine") -> SystemArchitecture.LINUX_ALPINE_AMD64 + else -> SystemArchitecture.UNSUPPORTED + } + } else { + SystemArchitecture.UNSUPPORTED + } + } + + else -> SystemArchitecture.UNSUPPORTED + } +} + +class MultiArchitecture { + companion object { + init { + val systemArchitecture = getSystemArchitecture() + when (systemArchitecture) { + SystemArchitecture.MAC_APPLE_SILICON -> { + System.setProperty("uniffi.component.tbdex.libraryOverride", "tbdex_uniffi_aarch64_apple_darwin") + } + SystemArchitecture.MAC_INTEL -> { + System.setProperty("uniffi.component.tbdex.libraryOverride", "tbdex_uniffi_x86_64_apple_darwin") + } + SystemArchitecture.LINUX_UBUNTU_AMD64 -> { + throw Exception("${SystemArchitecture.LINUX_UBUNTU_AMD64} not yet supported") + } + SystemArchitecture.LINUX_ALPINE_AMD64 -> { + throw Exception("${SystemArchitecture.LINUX_ALPINE_AMD64} not yet supported") + } + else -> { + throw Exception("unsupported sysytem architecture") + } + } + } + + fun getOfferings(pfiDidUri: String): List { + return tbdex.sdk.rust.getOfferings(pfiDidUri) + } + } +} \ No newline at end of file diff --git a/bound/kt/src/test/kotlin/tbdex/sdk/httpclient/E2ePfiExemplarIntegrationTest.kt b/bound/kt/src/test/kotlin/tbdex/sdk/httpclient/E2ePfiExemplarIntegrationTest.kt index 5b02fc23..81e2ef21 100644 --- a/bound/kt/src/test/kotlin/tbdex/sdk/httpclient/E2ePfiExemplarIntegrationTest.kt +++ b/bound/kt/src/test/kotlin/tbdex/sdk/httpclient/E2ePfiExemplarIntegrationTest.kt @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import tbdex.sdk.messages.* import tbdex.sdk.web5.* +import java.io.File class E2ePfiExemplarIntegrationTest { // this test is intended for early-development purposes