Skip to content

Commit 71e7115

Browse files
committed
fixing classpaths and library paths...
1 parent df75e74 commit 71e7115

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ let javaIncludePath = "\(javaHome)/include"
8686
let package = Package(
8787
name: "SwiftJava",
8888
platforms: [
89-
.macOS(.v13)
89+
.macOS(.v15)
9090
],
9191
products: [
9292
// ==== JavaKit (i.e. calling Java directly Swift utilities)

Samples/JavaDependencySampleApp/ci-validate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ swift run --disable-sandbox
88

99
# explicitly invoke resolve without explicit path or dependency
1010
# the dependencies should be uses from the --swift-module
11-
.build/plugins/tools/debug/SwiftJavaTool-tool resolve \
11+
swift run swift-java resolve \
1212
Sources/JavaCommonsCSV/swift-java.config \
1313
--swift-module JavaCommonsCSV \
1414
--output-directory .build/plugins/outputs/javadependencysampleapp/JavaCommonsCSV/destination/SwiftJavaPlugin/

Samples/SwiftAndJavaJarSampleLib/ci-validate.sh

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,52 @@ set -x
55

66
./gradlew jar
77

8+
export SWIFT_VERSION="$(swift -version | awk '/Swift version/ { print $3 }')"
9+
810
# 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
1019

1120
# 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+
# The classpath MUST end with a * if it contains jar files, and must not if it directly contains class files.
22+
SWIFTKIT_CLASSPATH="$(pwd)/../../SwiftKit/build/libs/*"
23+
MYLIB_CLASSPATH="$(pwd)/build/libs/*"
24+
CLASSPATH="$(pwd)/:${SWIFTKIT_CLASSPATH}:${MYLIB_CLASSPATH}"
25+
echo "CLASSPATH = ${CLASSPATH}"
26+
27+
javac -cp "${CLASSPATH}" Example.java
1428

1529
if [ "$(uname -s)" = 'Linux' ]
1630
then
1731
SWIFT_LIB_PATHS=/usr/lib/swift/linux
1832
SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:$(find . | grep libMySwiftLibrary.so$ | sort | head -n1 | xargs dirname)"
33+
34+
# if we are on linux, find the Swiftly or System-wide installed libraries dir
35+
SWIFT_CORE_LIB=$(find "$HOME"/.local -name "libswiftCore.so" 2>/dev/null | grep "$SWIFT_VERSION" | head -n1)
36+
if [ -n "$SWIFT_CORE_LIB" ]; then
37+
SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:$(dirname "$SWIFT_CORE_LIB")"
38+
else
39+
# maybe there is one installed system-wide in /usr/lib?
40+
SWIFT_CORE_LIB2=$(find /usr/lib -name "libswiftCore.so" 2>/dev/null | grep "$SWIFT_VERSION" | head -n1)
41+
if [ -n "$SWIFT_CORE_LIB2" ]; then
42+
SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:$(dirname "$SWIFT_CORE_LIB2")"
43+
fi
44+
fi
1945
elif [ "$(uname -s)" = 'Darwin' ]
2046
then
2147
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)"
48+
SWIFT_LIB_PATHS="${SWIFT_LIB_PATHS}:$(pwd)/$(find . | grep libMySwiftLibrary.dylib$ | sort | head -n1 | xargs dirname)"
2349
fi
50+
echo "SWIFT_LIB_PATHS = ${SWIFT_LIB_PATHS}"
2451

2552
# Can we run the example?
26-
SWIFTKIT_CLASSPATH="$(ls ../../SwiftKit/build/libs/*.jar)"
2753
java --enable-native-access=ALL-UNNAMED \
2854
-Djava.library.path="${SWIFT_LIB_PATHS}" \
29-
-cp ".:${MYLIB_CLASSPATH}:${SWIFTKIT_CLASSPATH}" \
55+
-cp "${CLASSPATH}" \
3056
Example

Samples/SwiftKitSampleApp/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let javaIncludePath = "\(javaHome)/include"
4343
let package = Package(
4444
name: "SwiftKitSampleApp",
4545
platforms: [
46-
.macOS(.v10_15)
46+
.macOS(.v15)
4747
],
4848
products: [
4949
.library(

0 commit comments

Comments
 (0)