Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Begin MultiArchitecture
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe committed Jul 5, 2024
1 parent 74149a6 commit 7271683
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bound/kt/src/main/kotlin/tbdex/sdk/httpclient/Offerings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Offering> {
val rustCoreOfferings = rustCoreGetOfferings(pfiDidUri)
// val rustCoreOfferings = rustCoreGetOfferings(pfiDidUri)
val rustCoreOfferings = RustCore.getOfferings(pfiDidUri)
return rustCoreOfferings.map { Offering(it) }
}
66 changes: 66 additions & 0 deletions bound/kt/src/main/kotlin/tbdex/sdk/rust/MultiArchitecture.kt
Original file line number Diff line number Diff line change
@@ -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<tbdex.sdk.rust.Offering> {
return tbdex.sdk.rust.getOfferings(pfiDidUri)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7271683

Please sign in to comment.