Bug 1519 - NativeLibrary: Clarify search order, allow added search-path + add property `jogamp.primary.library.path`
Summary: NativeLibrary: Clarify search order, allow added search-path + add property `...
Status: RESOLVED FIXED
Alias: None
Product: Gluegen
Classification: JogAmp
Component: core (show other bugs)
Version: 2.6.0
Hardware: All all
: P4 normal
Assignee: Sven Gothel
URL:
Depends on: 1510
Blocks: 1511
  Show dependency treegraph
 
Reported: 2025-07-12 18:22 CEST by Sven Gothel
Modified: 2025-07-12 21:00 CEST (History)
0 users

See Also:
Type: FEATURE
SCM Refs:
581549571c0a0bd245621a004cc2a9be6d10888b f051db16085b615e8609b889817d43209ebd1ebf
Workaround: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Gothel 2025-07-12 18:22:20 CEST
This feature enhances Bug 1510 further.

+++

NativeLibrary shall allow adding (user) search path to the OS linker facility where supported (Windows).

For this feature, we require to have more information for the `DynamicLinker`
implementation, i.e. the new `NativeLibrary.LibPath` exposing 
- whether its an absolute path, 
- contained directory shall be added to search path (first) and 
- otherwise potential added search path to prepend.

This feature is currently only supported by the Windows native linker,
since the POSIX `dlopen` facility doesn't allow to modify `LD_LIBRARY_PATH` at runtime.

+++

Add Java property `jogamp.primary.library.path` containing a separated path
in the OS system's format.

These paths will be searched first, 
allowing to inject custom native libraries at runtime.

+++

NativeLibrary's search order is not clear, or has a bug in regards to `searchSystemPathFirst`. Here the system and user lib-path is not well separated.

Clarified search order:

 * ## System Search Resolution
 * System search's behavior depends on `searchOSSystemPath` and `searchSystemPathFirst`.
 *
 * ### OS System Search
 * - System search path direct lookup (absolute path)
 *   - Windows: `PATH`
 *   - MacOS: `DYLD_LIBRARY_PATH`
 *   - Unix: `LD_LIBRARY_PATH`
 * - System search path implicit lookup (relative path)
 * - OSX System search path direct lookup (absolute path)
 *   - `/Library/Frameworks/`
 *   - `/System/Library/Frameworks/`
 *
 * ### System Search
 * - if `searchSystemPathFirst`
 *   - If `searchOSSystemPath`
 *     - Perform described `OS System Search` above
 *   - Java's ClassLoader `findLibrary` mechanism
 *   - Java's Java system library path property
 *     - `sun.boot.library.path`
 * - if `!searchSystemPathFirst`
 *   - Java's Java system library path property
 *     - `sun.boot.library.path`
 *   - Java's ClassLoader `findLibrary` mechanism
 *   - If `searchOSSystemPath`
 *     - Perform described `OS System Search` above
 *
 * ## Native Library Search Resolution
 * - Absolute path only, if given
 * - JogAmp's optional primary search path from Java property `jogamp.primary.library.path`
 *   - path is separated via `File.pathseparator`
 * - if `searchSystemPathFirst`
 *   - Perform described `System Search Resolution` above
 * - Java's Java user library path property
 *   - `java.library.path`
 * - Java's Java user current working directory
 *   - user: `user.dir`
 *   - user+fat: `user.dir` + File.separator + `natives` + File.separator + `PlatformPropsImpl.os_and_arch`
 * - if `!searchSystemPathFirst`
 *   - Perform described `System Search Resolution` above
Comment 1 Sven Gothel 2025-07-12 18:27:42 CEST
Resolved as described in commit 581549571c0a0bd245621a004cc2a9be6d10888b
Comment 2 Sven Gothel 2025-07-12 20:49:44 CEST
commit f051db16085b615e8609b889817d43209ebd1ebf

    Bug 1519 - NativeLibrary: `searchPathPrepend` shall act independent of `addToSearchPath`, do a null-check when using (Windows)
    
    Current usage sets both, i.e. addToSearchPath=true and searchPathPrepend=<some-valid-path>.
    However, it shall be used independent offering more flexibility and fail-proof.