-
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.
Shim vips library loading to fix Windows lookup, and allow multiple a…
…ttempts (#57)
- Loading branch information
Showing
21 changed files
with
155 additions
and
36 deletions.
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
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
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 |
---|---|---|
|
@@ -8,7 +8,6 @@ build | |
|
||
jextract* | ||
logo* | ||
native_libs/lib* | ||
includes.txt | ||
includes_filtered.txt | ||
hs_err* | ||
|
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
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
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
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
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
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
87 changes: 87 additions & 0 deletions
87
core/src/main/java/app/photofox/vipsffm/VipsLibLookup.java
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,87 @@ | ||
package app.photofox.vipsffm; | ||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.SymbolLookup; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class VipsLibLookup { | ||
|
||
public static SymbolLookup buildSymbolLoader(Arena arena) { | ||
var vipsLoader = findVipsLoader(arena); | ||
if (vipsLoader == null) { | ||
throw new UnsatisfiedLinkError("could not make loader for libvips"); | ||
} | ||
var glibLoader = findGlibLoader(arena); | ||
if (glibLoader == null) { | ||
throw new UnsatisfiedLinkError("could not make loader for glib"); | ||
} | ||
var gobjectLoader = findGObjectLoader(arena); | ||
if (gobjectLoader == null) { | ||
throw new UnsatisfiedLinkError("could not make loader for gobject"); | ||
} | ||
|
||
return vipsLoader.or(glibLoader).or(gobjectLoader); | ||
} | ||
|
||
private static SymbolLookup findVipsLoader(Arena arena) { | ||
var abiNumber = Optional.ofNullable(System.getProperty("vipsffm.abinumber.vips.override")) | ||
.orElse("42"); | ||
var names = List.of( | ||
"vips", // default unix-like | ||
"vips." + abiNumber, // some linux systems don't symlink and need abi number | ||
"libvips-" + abiNumber // windows needs everything | ||
); | ||
for (var name : names) { | ||
var attempt = attemptLibraryLookup(name, arena); | ||
if (attempt.isPresent()) { | ||
return attempt.get(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private static SymbolLookup findGlibLoader(Arena arena) { | ||
var abiNumber = Optional.ofNullable(System.getProperty("vipsffm.abinumber.glib.override")) | ||
.orElse("0"); | ||
var names = List.of( | ||
"glib-2.0", // default unix-like | ||
"glib-2.0." + abiNumber, // some linux systems don't symlink and need abi number | ||
"libglib-2.0-" + abiNumber // windows needs everything | ||
); | ||
for (var name : names) { | ||
var attempt = attemptLibraryLookup(name, arena); | ||
if (attempt.isPresent()) { | ||
return attempt.get(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private static SymbolLookup findGObjectLoader(Arena arena) { | ||
var abiNumber = Optional.ofNullable(System.getProperty("vipsffm.abinumber.gobject.override")) | ||
.orElse("0"); | ||
var names = List.of( | ||
"gobject-2.0", // default unix-like | ||
"gobject-2.0." + abiNumber, // some linux systems don't symlink and need abi number | ||
"libgobject-2.0-" + abiNumber // windows needs everything | ||
); | ||
for (var name : names) { | ||
var attempt = attemptLibraryLookup(name, arena); | ||
if (attempt.isPresent()) { | ||
return attempt.get(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
static Optional<SymbolLookup> attemptLibraryLookup(String name, Arena arena) { | ||
try { | ||
return Optional.of( | ||
SymbolLookup.libraryLookup(System.mapLibraryName(name), arena) | ||
); | ||
} catch (IllegalArgumentException _) { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
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
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
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
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package vipsffm | ||
|
||
fun main(args: Array<String>) { | ||
ReplaceVipsLoader.main(args) | ||
GenerateVipsHelperClass.main(args) | ||
GenerateVClasses.main(args) | ||
} |
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,22 @@ | ||
package vipsffm | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
|
||
object ReplaceVipsLoader { | ||
|
||
@JvmStatic fun main(args: Array<String>) { | ||
val vipsRawPath = Path.of("core/src/main/java/app/photofox/vipsffm/jextract/VipsRaw.java") | ||
|
||
val content = String(Files.readAllBytes(vipsRawPath), Charsets.UTF_8) | ||
.replace( | ||
"SymbolLookup.libraryLookup(System.mapLibraryName(\"vips\"), LIBRARY_ARENA)", | ||
"VipsLibLookup.buildSymbolLoader(LIBRARY_ARENA)" | ||
) | ||
.replace( | ||
"package app.photofox.vipsffm.jextract;\n\n", | ||
"package app.photofox.vipsffm.jextract;\nimport app.photofox.vipsffm.VipsLibLookup;\n\n", | ||
) | ||
Files.write(vipsRawPath, content.toByteArray(Charsets.UTF_8)) | ||
} | ||
} |
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
Empty file.
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
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
This file was deleted.
Oops, something went wrong.