Skip to content

Commit 7f9a986

Browse files
committed
lots of fixing around how we deal with config and library loading
Change how we do static initialization, to automatically load library as we first use a class from it! rename verify step fix variable import test for new scheme gitignore .d and similar files split out samples into separate job ci: reorganize jobs include objc workaround for linux dont rebuild twice to get better output build dependency fixes in gradle: depend on SwiftKit as well lib paths: workaround for swiftly installed 6.0.2 lib path ignore .idea directory
1 parent f10bdea commit 7f9a986

File tree

43 files changed

+477
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+477
-324
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: 'Swift Java CI Env'
2+
description: 'Prepare the CI environment by installing Swift and selected JDK etc.'
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Install System Dependencies
8+
run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev
9+
shell: bash
10+
- name: Cache JDK
11+
id: cache-jdk
12+
uses: actions/cache@v4
13+
continue-on-error: true
14+
with:
15+
path: /usr/lib/jvm/default-jdk/
16+
key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }}
17+
restore-keys: |
18+
${{ runner.os }}-jdk-
19+
- name: Install JDK
20+
if: steps.cache-jdk.outputs.cache-hit != 'true'
21+
run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'"
22+
shell: bash
23+
# TODO: not using setup-java since incompatible with the swiftlang/swift base image
24+
# - name: Install Untested Nightly Swift
25+
# run: "bash -xc './docker/install_untested_nightly_swift.sh'"
26+
- name: Cache local Gradle repository
27+
uses: actions/cache@v4
28+
continue-on-error: true
29+
with:
30+
path: |
31+
/root/.gradle/caches
32+
/root/.gradle/wrapper
33+
key: ${{ runner.os }}-gradle-${{ hashFiles('*/*.gradle*', 'settings.gradle') }}
34+
restore-keys: |
35+
${{ runner.os }}-gradle-
36+
- name: Cache local SwiftPM repository
37+
uses: actions/cache@v4
38+
continue-on-error: true
39+
with:
40+
path: /__w/swift-java/swift-java/.build/checkouts
41+
key: ${{ runner.os }}-swiftpm-cache-${{ hashFiles('Package.swift') }}
42+
restore-keys: |
43+
${{ runner.os }}-swiftpm-cache
44+
${{ runner.os }}-swiftpm-

.github/scripts/validate_samples.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
# shellcheck disable=SC2034
4-
declare -r GREEN='\033[0;31m'
4+
declare -r GREEN='\033[0;32m'
55
declare -r BOLD='\033[1m'
66
declare -r RESET='\033[0m'
77

@@ -15,7 +15,7 @@ for samplePackage in ${SAMPLE_PACKAGES} ; do
1515
echo ""
1616
echo ""
1717
echo "========================================================================"
18-
printf "Validate sample: '${BOLD}%s${RESET}' using: " "$sampleDir"
18+
printf "Validate sample '${BOLD}%s${RESET}' using: " "$sampleDir"
1919
cd "$sampleDir" || exit
2020
if [[ $(find . -name ${CI_VALIDATE_SCRIPT} -maxdepth 1) ]]; then
2121
echo -e "Custom ${BOLD}${CI_VALIDATE_SCRIPT}${RESET} script..."
@@ -28,9 +28,10 @@ for samplePackage in ${SAMPLE_PACKAGES} ; do
2828
swift build || exit
2929
fi
3030

31+
echo -e "Validated sample '${BOLD}${sampleDir}${RESET}': ${BOLD}passed${RESET}."
3132
cd - || exit
3233
done
3334

34-
35+
echo
3536
printf "Done validating samples: "
36-
echo "${GREEN}done${RESET}."
37+
echo -e "${GREEN}done${RESET}."

.github/workflows/pull_request.yml

Lines changed: 36 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -30,50 +30,14 @@ jobs:
3030
JAVA_HOME: "/usr/lib/jvm/default-jdk"
3131
steps:
3232
- uses: actions/checkout@v4
33-
- name: Install System Dependencies
34-
run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev
35-
- name: Cache JDK
36-
id: cache-jdk
37-
uses: actions/cache@v4
38-
continue-on-error: true
39-
with:
40-
path: /usr/lib/jvm/default-jdk/
41-
key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }}
42-
restore-keys: |
43-
${{ runner.os }}-jdk-
44-
- name: Install JDK
45-
if: steps.cache-jdk.outputs.cache-hit != 'true'
46-
run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'"
47-
# TODO: not using setup-java since incompatible with the swiftlang/swift base image
48-
# - name: Install Untested Nightly Swift
49-
# run: "bash -xc './docker/install_untested_nightly_swift.sh'"
50-
- name: Cache local Gradle repository
51-
uses: actions/cache@v4
52-
continue-on-error: true
53-
with:
54-
path: |
55-
/root/.gradle/caches
56-
/root/.gradle/wrapper
57-
key: ${{ runner.os }}-gradle-${{ hashFiles('*/*.gradle*', 'settings.gradle') }}
58-
restore-keys: |
59-
${{ runner.os }}-gradle-
60-
- name: Cache local SwiftPM repository
61-
uses: actions/cache@v4
62-
continue-on-error: true
63-
with:
64-
path: /__w/swift-java/swift-java/.build/checkouts
65-
key: ${{ runner.os }}-swiftpm-cache-${{ hashFiles('Package.swift') }}
66-
restore-keys: |
67-
${{ runner.os }}-swiftpm-cache
68-
${{ runner.os }}-swiftpm-
69-
# run the actual build
70-
- name: Gradle build
71-
run: |
72-
./gradlew build -x test --no-daemon # just build
73-
./gradlew build --info --no-daemon
74-
- name: Gradle build (benchmarks)
75-
run: |
76-
./gradlew compileJmh --info --no-daemon
33+
- name: Prepare CI Environment
34+
uses: ./.github/actions/prepare_env
35+
- name: Gradle :SwiftKit:build
36+
run: ./gradlew build -x test
37+
- name: Gradle :SwiftKit:check
38+
run: ./gradlew :SwiftKit:check --info
39+
- name: Gradle compile JMH benchmarks
40+
run: ./gradlew compileJmh --info
7741

7842
test-swift:
7943
name: Swift tests (swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}} os:${{ matrix.os_version }})
@@ -91,50 +55,33 @@ jobs:
9155
JAVA_HOME: "/usr/lib/jvm/default-jdk"
9256
steps:
9357
- uses: actions/checkout@v4
94-
- name: Install System Dependencies
95-
run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev
96-
- name: Cache JDK
97-
id: cache-jdk
98-
uses: actions/cache@v4
99-
continue-on-error: true
100-
with:
101-
path: /usr/lib/jvm/default-jdk/
102-
key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }}
103-
restore-keys: |
104-
${{ runner.os }}-jdk-
105-
- name: Install JDK
106-
if: steps.cache-jdk.outputs.cache-hit != 'true'
107-
run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'"
108-
# TODO: not using setup-java since incompatible with the swiftlang/swift base image
109-
# - name: Install Untested Nightly Swift
110-
# run: "bash -xc './docker/install_untested_nightly_swift.sh'"
111-
- name: Cache local Gradle repository
112-
uses: actions/cache@v4
113-
continue-on-error: true
114-
with:
115-
path: |
116-
/root/.gradle/caches
117-
/root/.gradle/wrapper
118-
key: ${{ runner.os }}-gradle-${{ hashFiles('*/*.gradle*', 'settings.gradle') }}
119-
restore-keys: |
120-
${{ runner.os }}-gradle-
121-
- name: Cache local SwiftPM repository
122-
uses: actions/cache@v4
123-
continue-on-error: true
124-
with:
125-
path: /__w/swift-java/swift-java/.build/checkouts
126-
key: ${{ runner.os }}-swiftpm-cache-${{ hashFiles('Package.swift') }}
127-
restore-keys: |
128-
${{ runner.os }}-swiftpm-cache
129-
${{ runner.os }}-swiftpm-
130-
# run the actual build
131-
# - name: Generate sources (make) (Temporary)
132-
# # TODO: this should be triggered by the respective builds
133-
# run: "make jextract-generate"
134-
- name: Test Swift
58+
- name: Prepare CI Environment
59+
uses: ./.github/actions/prepare_env
60+
- name: Swift Build
61+
run: "swift build --build-tests"
62+
- name: Swift Test
13563
run: "swift test"
136-
- name: Build (Swift) Sample Apps
64+
65+
verify-samples:
66+
name: Verify Samples (swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}} os:${{ matrix.os_version }})
67+
runs-on: ubuntu-latest
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
# swift_version: ['nightly-main']
72+
swift_version: ['6.0.2']
73+
os_version: ['jammy']
74+
jdk_vendor: ['Corretto']
75+
container:
76+
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
77+
env:
78+
JAVA_HOME: "/usr/lib/jvm/default-jdk"
79+
steps:
80+
- uses: actions/checkout@v4
81+
- name: Prepare CI Environment
82+
uses: ./.github/actions/prepare_env
83+
- name: Verify Samples (All)
13784
run: .github/scripts/validate_samples.sh
138-
# TODO: Benchmark compile crashes in CI, enable when nightly toolchains in better shape.
139-
# - name: Build (Swift) Benchmarks
140-
# run: "swift package --package-path Benchmarks/ benchmark list"
85+
# TODO: Benchmark compile crashes in CI, enable when nightly toolchains in better shape.
86+
# - name: Build (Swift) Benchmarks
87+
# run: "swift package --package-path Benchmarks/ benchmark list"

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.build
3+
.idea
34
Packages
45
xcuserdata/
56
DerivedData/
@@ -33,3 +34,8 @@ Package.resolved
3334

3435
# Ignore files generated by jextract, we always can re-generate them
3536
*/**/src/generated/java/**/*
37+
38+
*/**/*.d
39+
*/**/*.o
40+
*/**/*.swiftdeps
41+
*/**/*.swiftdeps~

.licenseignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ gradlew
3939
gradlew.bat
4040
**/gradlew
4141
**/gradlew.bat
42+
**/ci-validate.sh

BuildLogic/src/main/kotlin/build-logic.java-common-conventions.gradle.kts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import java.util.*
16+
import java.io.*
1617

1718
plugins {
1819
java
@@ -44,30 +45,36 @@ tasks.withType(JavaCompile::class).forEach {
4445

4546

4647
// FIXME: cannot share definition with 'buildSrc' so we duplicated the impl here
47-
fun javaLibraryPaths(): List<String> {
48+
fun javaLibraryPaths(dir: File): List<String> {
4849
val osName = System.getProperty("os.name")
4950
val osArch = System.getProperty("os.arch")
5051
val isLinux = osName.lowercase(Locale.getDefault()).contains("linux")
5152

5253
return listOf(
5354
if (isLinux) {
5455
if (osArch.equals("x86_64") || osArch.equals("amd64")) {
55-
"$rootDir/.build/x86_64-unknown-linux-gnu/debug/"
56+
"$dir/.build/x86_64-unknown-linux-gnu/debug/"
5657
} else {
57-
"$rootDir/.build/$osArch-unknown-linux-gnu/debug/"
58+
"$dir/.build/$osArch-unknown-linux-gnu/debug/"
5859
}
5960
} else {
6061
if (osArch.equals("aarch64")) {
61-
"$rootDir/.build/arm64-apple-macosx/debug/"
62+
"$dir/.build/arm64-apple-macosx/debug/"
6263
} else {
63-
"$rootDir/.build/$osArch-apple-macosx/debug/"
64+
"$dir/.build/$osArch-apple-macosx/debug/"
6465
}
6566
},
6667
if (isLinux) {
6768
"/usr/lib/swift/linux"
6869
} else {
6970
// assume macOS
7071
"/usr/lib/swift/"
72+
},
73+
if (isLinux) {
74+
System.getProperty("user.home") + "/.local/share/swiftly/toolchains/6.0.2/usr/lib/swift/linux"
75+
} else {
76+
// assume macOS
77+
"/usr/lib/swift/"
7178
}
7279
)
7380
}
@@ -79,7 +86,9 @@ tasks.test {
7986
"--enable-native-access=ALL-UNNAMED",
8087

8188
// Include the library paths where our dylibs are that we want to load and call
82-
"-Djava.library.path=" + javaLibraryPaths().joinToString(File.pathSeparator)
89+
"-Djava.library.path=" +
90+
(javaLibraryPaths(rootDir) + javaLibraryPaths(project.projectDir))
91+
.joinToString(File.pathSeparator)
8392
)
8493
}
8594

@@ -88,17 +97,3 @@ tasks.withType<Test> {
8897
this.showStandardStreams = true
8998
}
9099
}
91-
92-
93-
// TODO: This is a crude workaround, we'll remove 'make' soon and properly track build dependencies
94-
// val buildSwiftJExtract = tasks.register<Exec>("buildMake") {
95-
// description = "Triggers 'make' build"
96-
//
97-
// workingDir(rootDir)
98-
// commandLine("make")
99-
// }
100-
//
101-
// tasks.build {
102-
// dependsOn(buildSwiftJExtract)
103-
// }
104-

0 commit comments

Comments
 (0)