summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-08-05 05:18:59 +0200
committerSven Gothel <[email protected]>2023-08-05 05:18:59 +0200
commit287780236de7e3cea7ba826a76f720cf4501e4c0 (patch)
tree417d999216438c2ac75e194862bf11253afea0e1
parent05a931d587feb3116892f5b146b3a4bb2867e923 (diff)
Add notes `Loading a MacOS Native Library's Dependencies` and use absolute path in unit test script for library-path
-rw-r--r--doc/misc/macos_nativelib_dependencies.md30
-rwxr-xr-xmake/scripts/runtest.sh20
2 files changed, 44 insertions, 6 deletions
diff --git a/doc/misc/macos_nativelib_dependencies.md b/doc/misc/macos_nativelib_dependencies.md
new file mode 100644
index 0000000..70d0973
--- /dev/null
+++ b/doc/misc/macos_nativelib_dependencies.md
@@ -0,0 +1,30 @@
+# Loading a MacOS Native Library's Dependencies
+Assume we have `libBindingtest1p1.dylib`, which links to `libtest1.dylib`,
+i.e. requires the OS native library to load `libtest1.dylib` to resolve symbols.
+
+Usually we just se `DYLD_LIBRARY_PATH` including the path where `libtest1.dylib`
+is located and we are good to go.
+
+## Just use dynamic loading via GlueGen's ProcAddressTable
+Note, the above problem does not occur when using GlueGen's ProcAddressTable,
+i.e. loading the underlying tool library `libtest2.dylib` w/ dlopen
+and passing all symbols to the JNI library `libBindingtest1p2.dylib`.
+
+## Can't pass `DYLD_LIBRARY_PATH` to `java`
+This is supposed to be related to MacOS's `System Integrity Protect (SIP)`.
+
+## Workaround inability to pass `DYLD_LIBRARY_PATH` to `java`
+
+### Using ``@loader_path` within dependent library
+Set location of referenced library `libtest1.dylib` to same path of dependent library `libBindingtest1p1.dylib`
+using `@loader_path`.
+```
+cd build-macosx/test/build/natives/
+otool -L libBindingtest1p1.dylib
+install_name_tool -change libtest1.dylib @loader_path/libtest1.dylib libBindingtest1p1.dylib
+otool -L libBindingtest1p1.dylib
+```
+
+Further we could try `@executable_path` and `@rpath`.
+
+See [An alternative to macOS's DYLD_LIBRARY_PATH](https://www.joyfulbikeshedding.com/blog/2021-01-13-alternative-to-macos-dyld-library-path.html).
diff --git a/make/scripts/runtest.sh b/make/scripts/runtest.sh
index 7c6a957..03b14b9 100755
--- a/make/scripts/runtest.sh
+++ b/make/scripts/runtest.sh
@@ -41,8 +41,14 @@ rm -f $LOG
GLUEGEN_ROOT=`dirname $builddir`
ROOTREL_BUILD=`basename $builddir`
+builddirAbs=`readlink -f $builddir`
+
+# MODULE_ARGS="--illegal-access=warn"
+# MODULE_ARGS="--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.desktop/sun.awt=ALL-UNNAMED --add-opens java.desktop/sun.java2d=ALL-UNNAMED"
+MODULE_ARGS="--add-opens java.desktop/sun.awt=ALL-UNNAMED --add-opens java.desktop/sun.java2d=ALL-UNNAMED"
X_ARGS="-Drootrel.build=$ROOTREL_BUILD -Dgluegen.root=$GLUEGEN_ROOT"
+
#D_ARGS="-Djogamp.debug.ProcAddressHelper -Djogamp.debug.NativeLibrary -Djogamp.debug.NativeLibrary.Lookup"
#D_ARGS="-Djogamp.debug.TraceLock"
#D_ARGS="-Djogamp.debug.Platform -Djogamp.debug.NativeLibrary"
@@ -55,6 +61,7 @@ X_ARGS="-Drootrel.build=$ROOTREL_BUILD -Dgluegen.root=$GLUEGEN_ROOT"
#D_ARGS="-Djogamp.debug.Uri -Djogamp.debug.Uri.ShowFix"
#D_ARGS="-Djogamp.debug.JNILibLoader -Djogamp.gluegen.UseTempJarCache=false"
#D_ARGS="-Djogamp.debug.JNILibLoader -Djogamp.debug.TempJarCache"
+#D_ARGS="-Djogamp.debug.JNILibLoader -Djogamp.debug.NativeLibrary"
#D_ARGS="-Djogamp.debug.JNILibLoader"
#D_ARGS="-Djogamp.debug.JNILibLoader.Perf"
#D_ARGS="-Djogamp.debug.Lock"
@@ -74,17 +81,18 @@ function onetest() {
#USE_CLASSPATH=lib/junit.jar:$ANT_JARS:lib/semantic-versioning/semver.jar:"$builddir"/../make/lib/TestJarsInJar.jar:"$builddir"/gluegen-rt.jar:"$builddir"/gluegen.jar:"$builddir"/gluegen-test-util.jar:"$builddir"/test/build/gluegen-test.jar
USE_CLASSPATH=lib/junit.jar:$ANT_JARS:lib/semantic-versioning/semver.jar:"$builddir"/../make/lib/TestJarsInJar.jar:"$builddir"/gluegen-rt.jar:"$builddir"/gluegen.jar:"$builddir"/gluegen-test-util.jar:"$builddir"/test/build/gluegen-test.jar:"$builddir"/gluegen-rt-natives.jar
#USE_CLASSPATH=lib/junit.jar:$ANT_JARS:lib/semantic-versioning/semver.jar:"$builddir"/../make/lib/TestJarsInJar.jar:"$builddir"/gluegen-rt-alt.jar:"$builddir"/gluegen.jar:"$builddir"/gluegen-test-util.jar:"$builddir"/test/build/gluegen-test.jar
- libspath="$builddir"/test/build/natives
#USE_CLASSPATH=lib/junit.jar:$ANT_JARS:"$builddir"/../make/lib/TestJarsInJar.jar:"$builddir"/classes:"$builddir"/test/build/classes
- #libspath="$builddir"/obj:"$builddir"/test/build/natives:
- LD_LIBRARY_PATH=$libspath:$LD_LIBRARY_PATH
- DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
+ #libspath="${builddirAbs}"/test/build/natives
+ libspath="${builddirAbs}"/obj:"${builddirAbs}"/test/build/natives
+ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$libspath
+ DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$libspath
export LD_LIBRARY_PATH DYLD_LIBRARY_PATH
echo LD_LIBRARY_PATH $LD_LIBRARY_PATH
+ echo DYLD_LIBRARY_PATH $DYLD_LIBRARY_PATH
echo USE_CLASSPATH $USE_CLASSPATH
which java
- echo java -cp "$USE_CLASSPATH" $X_ARGS $D_ARGS -Djava.library.path=$libspath $*
- java -cp "$USE_CLASSPATH" $X_ARGS $D_ARGS -Djava.library.path="$libspath" $*
+ echo java $MODULE_ARGS $X_ARGS -Djava.library.path=$libspath -cp "$USE_CLASSPATH" $D_ARGS $*
+ java $MODULE_ARGS $X_ARGS -Djava.library.path="$libspath" -cp "$USE_CLASSPATH" $D_ARGS $*
#echo java -cp "$USE_CLASSPATH" $X_ARGS $D_ARGS $*
#java -cp "$USE_CLASSPATH" $X_ARGS $D_ARGS $*
#j3 -cp "$USE_CLASSPATH" $X_ARGS $D_ARGS $*