This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74149a6
commit 7271683
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
bound/kt/src/main/kotlin/tbdex/sdk/rust/MultiArchitecture.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters