Skip to content

Commit 3fdfe71

Browse files
authored
Merge pull request #25 from kdroidFilter/fix/flatten-native-lib-extraction
fix(sandboxing): flatten native lib extraction to resources root
2 parents b18bbf5 + dec66fb commit 3fdfe71

2 files changed

Lines changed: 17 additions & 45 deletions

File tree

plugin-build/plugin/src/main/kotlin/io/github/kdroidfilter/nucleus/desktop/application/internal/configureJvmApplication.kt

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -859,37 +859,14 @@ private fun JvmApplicationContext.configurePackageUberJarForCurrentOS(
859859
* JNA-specific args are always included: they are harmless if JNA is not on the classpath
860860
* (the JVM simply ignores unknown system properties).
861861
*
862-
* `jna.boot.library.path` must include the platform-specific subdirectory (e.g. `darwin-aarch64`)
863-
* because JNA looks for `libjnidispatch` directly in the listed directories without adding
864-
* any platform prefix itself.
862+
* Native libs are extracted flat into [resourcesPath] (no platform subdirectories),
863+
* so a single directory entry is sufficient for all lookup mechanisms.
865864
*/
866-
private fun sandboxingJvmArgs(resourcesPath: String): List<String> {
867-
val sep = java.io.File.pathSeparator
868-
val jnaPlatformDir = "$resourcesPath/${jnaPlatformPrefix()}"
869-
return listOf(
870-
"-Djava.library.path=$jnaPlatformDir$sep$resourcesPath",
865+
private fun sandboxingJvmArgs(resourcesPath: String): List<String> =
866+
listOf(
867+
"-Djava.library.path=$resourcesPath",
871868
"-Djna.nounpack=true",
872869
"-Djna.nosys=true",
873-
"-Djna.boot.library.path=$jnaPlatformDir$sep$resourcesPath",
874-
"-Djna.library.path=$jnaPlatformDir$sep$resourcesPath",
870+
"-Djna.boot.library.path=$resourcesPath",
871+
"-Djna.library.path=$resourcesPath",
875872
)
876-
}
877-
878-
/**
879-
* Returns the JNA platform resource prefix for the current OS and architecture.
880-
* This matches the directory name JNA uses inside its JAR (e.g. `darwin-aarch64`, `linux-x86-64`).
881-
*/
882-
private fun jnaPlatformPrefix(): String {
883-
val os =
884-
when (currentOS) {
885-
OS.Windows -> "win32"
886-
OS.Linux -> "linux"
887-
OS.MacOS -> "darwin"
888-
}
889-
val arch =
890-
when (currentArch) {
891-
Arch.X64 -> "x86-64"
892-
Arch.Arm64 -> "aarch64"
893-
}
894-
return "$os-$arch"
895-
}

plugin-build/plugin/src/main/kotlin/io/github/kdroidfilter/nucleus/desktop/application/tasks/AbstractExtractNativeLibsTask.kt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,16 @@ abstract class AbstractExtractNativeLibsTask : AbstractNucleusTask() {
6666
val info = detectInfo(entry.name, zis)
6767
if (shouldExtract(info, expectedOs, expectedArch)) {
6868
val fileName = entry.name.substringAfterLast('/')
69-
// Preserve parent directory for libs that use path-based lookup (e.g. JNA
70-
// expects <boot.library.path>/darwin-aarch64/libjnidispatch.jnilib).
71-
// Universal-arch libraries go directly into the resources root so they
72-
// are found via the base java.library.path entry without needing
73-
// an architecture-specific subdirectory.
74-
val parentDir =
75-
entry.name
76-
.substringBeforeLast('/', "")
77-
.substringAfterLast('/')
78-
val relativePath =
79-
if (parentDir.isEmpty() || info.arch == NativeArch.UNIVERSAL) {
80-
fileName
81-
} else {
82-
"$parentDir/$fileName"
83-
}
69+
// Always flatten to the output root. We already filter by
70+
// target OS/arch so there are no naming conflicts, and
71+
// flattening is required for:
72+
// 1. macOS universal builds – lipo needs the same relative
73+
// path in both the arm64 and x64 .app bundles.
74+
// 2. JNA boot library loading – jna.boot.library.path
75+
// looks directly in the listed directories.
76+
// 3. Simplicity – a single java.library.path entry is
77+
// enough for all native libs.
78+
val relativePath = fileName
8479
if (fileName in extractedFiles) {
8580
logger.warn(
8681
"Sandboxing: skipping duplicate native lib" +

0 commit comments

Comments
 (0)