Skip to content

libraryOverride doesn't work with FFM loading #58

@skeet70

Description

@skeet70

My problem now is that with the Kotlin/JNA bindings I could set jna.library.path, but with the Java/FFM bindings it always calls System.loadLibrary("name") but I need to create a tempfile, copy my bundled lib, and run System.load("/tmp/libname.so") but I can't seem to find any way to get around this.

Actually it looks like uniffi.component.name.libraryOverride could also accept a path, but now cannot because it uses System.loadLibrary instead of System.load internally. I was also using NativeLibrary.addSearchPath but that's from JNA.

val platform = Platform()
val resourcePath = "/native/${platform.target}/${platform.name}"
val inputStream = Native::class.java.getResourceAsStream(resourcePath)
    ?: error("Native library not found in resources: $resourcePath")

val prefix = platform.name.substringBeforeLast('.')
val suffix = platform.name.substringAfterLast('.')
val tempFile = File.createTempFile(prefix, suffix).also(File::deleteOnExit)

Files.copy(inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
System.setProperty("uniffi.component.native.libraryOverride", tempFile.toString())
System.load(tempFile.absolutePath)
static java.lang.foreign.SymbolLookup loadLibrary() {
    System.loadLibrary(findLibraryName("native"));
    return java.lang.foreign.SymbolLookup.loaderLookup();
}

Reported by @ShayBox in mozilla/uniffi-rs#2155 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions