diff --git a/zenoh-java/src/jvmMain/kotlin/io/zenoh/Target.kt b/zenoh-java/src/jvmMain/kotlin/io/zenoh/Target.kt index 4bb087e..0e58c21 100644 --- a/zenoh-java/src/jvmMain/kotlin/io/zenoh/Target.kt +++ b/zenoh-java/src/jvmMain/kotlin/io/zenoh/Target.kt @@ -14,7 +14,7 @@ package io.zenoh -enum class Target { +internal enum class Target { WINDOWS_X86_64_MSVC, LINUX_X86_64, LINUX_AARCH64, diff --git a/zenoh-java/src/jvmMain/kotlin/io/zenoh/Zenoh.kt b/zenoh-java/src/jvmMain/kotlin/io/zenoh/Zenoh.kt index 11ae638..593e451 100644 --- a/zenoh-java/src/jvmMain/kotlin/io/zenoh/Zenoh.kt +++ b/zenoh-java/src/jvmMain/kotlin/io/zenoh/Zenoh.kt @@ -27,7 +27,7 @@ import java.util.zip.ZipInputStream internal actual object ZenohLoad { private const val ZENOH_LIB_NAME = "zenoh_jni" - init { + init { // Try first to load the local native library for cases in which the module was built locally, // otherwise try to load from the JAR. if (tryLoadingLocalLibrary().isFailure) { @@ -45,24 +45,33 @@ internal actual object ZenohLoad { */ private fun determineTarget(): Result = runCatching { val osName = System.getProperty("os.name").lowercase() - val osArch = System.getProperty("os.arch") + val osArch = System.getProperty("os.arch").lowercase() val target = when { osName.contains("win") -> when { - osArch.contains("x86_64") || osArch.contains("amd64") -> Target.WINDOWS_X86_64_MSVC - else -> throw UnsupportedOperationException("Unsupported architecture: $osArch") + osArch.contains("x86_64") || osArch.contains("amd64") || osArch.contains("x64") -> + Target.WINDOWS_X86_64_MSVC + else -> throw UnsupportedOperationException("Unsupported architecture on Windows: $osArch") } - osName.contains("mac") -> when { - osArch.contains("x86_64") || osArch.contains("amd64") -> Target.APPLE_X86_64 - osArch.contains("aarch64") -> Target.APPLE_AARCH64 - else -> throw UnsupportedOperationException("Unsupported architecture: $osArch") + osName.contains("mac") || osName.contains("darwin") || osName.contains("os x") -> when { + osArch.contains("x86_64") || osArch.contains("amd64") || osArch.contains("x64") -> + Target.APPLE_X86_64 + + osArch.contains("aarch64") || osArch.contains("arm64") -> + Target.APPLE_AARCH64 + + else -> throw UnsupportedOperationException("Unsupported architecture on macOS: $osArch") } osName.contains("nix") || osName.contains("nux") || osName.contains("aix") -> when { - osArch.contains("x86_64") || osArch.contains("amd64") -> Target.LINUX_X86_64 - osArch.contains("aarch64") -> Target.LINUX_AARCH64 - else -> throw UnsupportedOperationException("Unsupported architecture: $osArch") + osArch.contains("x86_64") || osArch.contains("amd64") || osArch.contains("x64") -> + Target.LINUX_X86_64 + + osArch.contains("aarch64") || osArch.contains("arm64") -> + Target.LINUX_AARCH64 + + else -> throw UnsupportedOperationException("Unsupported architecture on Linux/Unix: $osArch") } else -> throw UnsupportedOperationException("Unsupported platform: $osName") @@ -108,7 +117,9 @@ internal actual object ZenohLoad { } private fun loadLibraryAsInputStream(target: Target): Result = runCatching { - val libUrl = ClassLoader.getSystemClassLoader().getResourceAsStream("$target/$target.zip")!! + val targetName = "$target/$target.zip" + val libUrl = ClassLoader.getSystemClassLoader().getResourceAsStream(targetName) + ?: javaClass.classLoader.getResourceAsStream(targetName)!! val uncompressedLibFile = unzipLibrary(libUrl) return Result.success(FileInputStream(uncompressedLibFile.getOrThrow())) } @@ -145,6 +156,9 @@ internal actual object ZenohLoad { */ private fun tryLoadingLocalLibrary(): Result = runCatching { val lib = ClassLoader.getSystemClassLoader().findLibraryStream(ZENOH_LIB_NAME) + ?: javaClass.classLoader.findLibraryStream( + ZENOH_LIB_NAME + ) if (lib != null) { loadZenohJNI(lib) } else {