Skip to content

Commit 888ffc1

Browse files
committed
ci: workaround for macOS GHA issue with wrapper fetching from spm plugin
1 parent b5116d5 commit 888ffc1

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

Samples/SwiftJavaExtractJNISampleApp/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,11 @@ jmh {
209209
"-Djextract.trace.downcalls=false"
210210
]
211211
}
212+
213+
task printGradleHome {
214+
doLast {
215+
println "Gradle Home: ${gradle.gradleHomeDir}"
216+
println "Gradle Version: ${gradle.gradleVersion}"
217+
println "Gradle User Home: ${gradle.gradleUserHomeDir}"
218+
}
219+
}

Samples/SwiftJavaExtractJNISampleApp/ci-validate.sh

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,37 @@
33
set -x
44
set -e
55

6-
# GitHub Actions workaround; We seem to be hitting gradle wrapper download issues, and this attempts to workaround them
7-
./gradlew -h
6+
if [[ "$(uname)" == "Darwin" && -n "$GITHUB_ACTION" ]]; then
7+
# WORKAROUND: GitHub Actions on macOS issue with downloading gradle wrapper
8+
# We seem to be hitting a problem when the swiftpm plugin, needs to execute gradle wrapper in a new gradle_user_home.
9+
# Normally, this would just download gradle again and kick off a build, this seems to timeout *specifically* on
10+
# github actions runners.
11+
#
12+
# It is not a sandbox problem, becuase the ./gradlew is run without sandboxing as we already execute
13+
# the entire swift build with '--disable-sandbox' for other reasons.
14+
#
15+
# We cannot use the same gradle user home as the default one since we might make gradle think we're
16+
# building the same project concurrently, which we kind of are, however only a limited subset in order
17+
# to trigger wrap-java with those dependencies.
18+
#
19+
# TODO: this may use some further improvements so normal usage does not incur another wrapper download.
820

9-
GRADLE_USER_HOME="$(pwd)/.build/plugins/outputs/swiftjavaextractjnisampleapp/MySwiftLibrary/destination/JExtractSwiftPlugin/gradle-user-home"
10-
if [ -d "$HOME/.gradle" ] ; then
11-
echo "COPY $HOME/.gradle to $GRADLE_USER_HOME"
12-
mkdir -p "$GRADLE_USER_HOME"
13-
cp -r "$HOME/.gradle/*" "$GRADLE_USER_HOME/" || true
14-
fi
21+
./gradlew -h # prime ~/.gradle/wrapper/dists/...
1522

16-
# Verify the custom gradle home directory works # TODO: remove this once verified
17-
./gradlew :SwiftKitCore:build --gradle-user-home $GRADLE_USER_HOME -p "$(pwd)/../../" --configure-on-demand --no-daemon
23+
# Worst part of workaround here; we make sure to pre-load the resolved gradle wrapper downloaded distribution
24+
# to the "known" location the plugin will use for its local builds, which are done in order to compile SwiftKitCore.
25+
# This build is only necessary in order to drive wrap-java on sources generated during the build itself
26+
# which enables the "Implement Swift protocols in Java" feature of jextract/jni mode.
27+
GRADLE_USER_HOME="$(pwd)/.build/plugins/outputs/swiftjavaextractjnisampleapp/MySwiftLibrary/destination/JExtractSwiftPlugin/gradle-user-home"
28+
if [ -d "$HOME/.gradle" ] ; then
29+
echo "COPY $HOME/.gradle to $GRADLE_USER_HOME"
30+
mkdir -p "$GRADLE_USER_HOME"
31+
cp -r "$HOME/.gradle/"* "$GRADLE_USER_HOME/" || true
32+
fi
33+
fi
1834

19-
swift build --disable-experimental-prebuilts --disable-sandbox --verbose # FIXME: until prebuilt swift-syntax isn't broken on 6.2 anymore: https://github.com/swiftlang/swift-java/issues/418
35+
# FIXME: disable prebuilts until prebuilt swift-syntax isn't broken on 6.2 anymore: https://github.com/swiftlang/swift-java/issues/418
36+
swift build --disable-experimental-prebuilts --disable-sandbox
2037

2138
./gradlew run
2239
./gradlew test

Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+SwiftThunkPrinting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ extension JNISwift2JavaGenerator {
318318
#".init(name: "\#(name)", signature: "\#(signature.mangledName)")"#
319319
}.joined(separator: ",\n")
320320

321-
return #"_JNIMethodIDCache(environment: try! JavaVirtualMachine.shared().environment(), className: "\#(fullClassName)", methods: [\#(methods)])"#
321+
return #"_JNIMethodIDCache(className: "\#(fullClassName)", methods: [\#(methods)])"#
322322
}
323323

324324
private func printEnumGetAsCaseThunk(

0 commit comments

Comments
 (0)