|
5 | 5 |
|
6 | 6 | ./gradlew jar
|
7 | 7 |
|
| 8 | +export SWIFT_VERSION="$(swift -version | awk '/Swift version/ { print $3 }')" |
| 9 | + |
8 | 10 | # we make sure to build and run with JDK 24 because the runtime needs latest JDK, unlike Gradle which needed 21.
|
9 |
| -export PATH="${PATH}:/usr/lib/jvm/jdk-24/bin" |
| 11 | +if [ "$(uname -s)" = 'Darwin' ] |
| 12 | +then |
| 13 | + export OS='osx' |
| 14 | +elif [ "$(uname -s)" = 'Linux' ] |
| 15 | +then |
| 16 | + export OS='linux' |
| 17 | + export PATH="${PATH}:/usr/lib/jvm/jdk-24/bin" # we need to make sure to use the latest JDK to actually compile/run the executable |
| 18 | +fi |
10 | 19 |
|
11 | 20 | # check if we can compile a plain Example file that uses the generated Java bindings that should be in the generated jar
|
12 |
| -MYLIB_CLASSPATH="$(ls bin/default/build/libs/*.jar)" |
13 |
| -javac -cp "${MYLIB_CLASSPATH}" Example.java |
| 21 | +SWIFTKIT_CLASSPATH="$(pwd)/../../SwiftKit/build/libs/*" |
| 22 | +MYLIB_CLASSPATH="$(pwd)/build/libs/*" |
| 23 | +CLASSPATH="$(pwd)/*:${SWIFTKIT_CLASSPATH}:${MYLIB_CLASSPATH}" |
| 24 | +echo "CLASSPATH = ${CLASSPATH}" |
| 25 | + |
| 26 | +javac -cp "${CLASSPATH}" Example.java |
14 | 27 |
|
15 | 28 | if [ "$(uname -s)" = 'Linux' ]
|
16 | 29 | then
|
17 | 30 | SWIFT_LIB_PATHS=/usr/lib/swift/linux
|
18 | 31 | SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:$(find . | grep libMySwiftLibrary.so$ | sort | head -n1 | xargs dirname)"
|
| 32 | + |
| 33 | + # if we are on linux, find the Swiftly or System-wide installed libraries dir |
| 34 | + SWIFT_CORE_LIB=$(find "$HOME"/.local -name "libswiftCore.so" 2>/dev/null | grep "$SWIFT_VERSION" | head -n1) |
| 35 | + if [ -n "$SWIFT_CORE_LIB" ]; then |
| 36 | + SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:$(dirname "$SWIFT_CORE_LIB")" |
| 37 | + else |
| 38 | + # maybe there is one installed system-wide in /usr/lib? |
| 39 | + SWIFT_CORE_LIB2=$(find /usr/lib -name "libswiftCore.so" 2>/dev/null | grep "$SWIFT_VERSION" | head -n1) |
| 40 | + if [ -n "$SWIFT_CORE_LIB2" ]; then |
| 41 | + SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:$(dirname "$SWIFT_CORE_LIB2")" |
| 42 | + fi |
| 43 | + fi |
19 | 44 | elif [ "$(uname -s)" = 'Darwin' ]
|
20 | 45 | then
|
21 | 46 | SWIFT_LIB_PATHS=$(find "$(swiftly use --print-location)" | grep dylib$ | grep libswiftCore | grep macos | xargs dirname)
|
22 |
| - SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:$(find . | grep libMySwiftLibrary.dylib$ | sort | head -n1 | xargs dirname)" |
| 47 | + SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:$(pwd)/$(find . | grep libMySwiftLibrary.dylib$ | sort | head -n1 | xargs dirname)" |
23 | 48 | fi
|
| 49 | +echo "SWIFT_LIB_PATHS = ${SWIFT_LIB_PATHS}" |
24 | 50 |
|
25 | 51 | # Can we run the example?
|
26 |
| -SWIFTKIT_CLASSPATH="$(ls ../../SwiftKit/build/libs/*.jar)" |
27 | 52 | java --enable-native-access=ALL-UNNAMED \
|
28 | 53 | -Djava.library.path="${SWIFT_LIB_PATHS}" \
|
29 |
| - -cp ".:${MYLIB_CLASSPATH}:${SWIFTKIT_CLASSPATH}" \ |
| 54 | + -cp "${CLASSPATH}" \ |
30 | 55 | Example
|
0 commit comments