Skip to content

Commit 0c57644

Browse files
authored
Redesign jextract-swift: plugins and avoid custom swift features (#170)
1 parent fff9483 commit 0c57644

File tree

62 files changed

+2263
-838
lines changed

Some content is hidden

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

62 files changed

+2263
-838
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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# shellcheck disable=SC2034
4+
declare -r GREEN='\033[0;32m'
5+
declare -r BOLD='\033[1m'
6+
declare -r RESET='\033[0m'
7+
8+
# shellcheck disable=SC2155
9+
declare -r SAMPLE_PACKAGES=$(find Samples -name Package.swift -maxdepth 2)
10+
declare -r CI_VALIDATE_SCRIPT='ci-validate.sh'
11+
12+
for samplePackage in ${SAMPLE_PACKAGES} ; do
13+
sampleDir=$(dirname "$samplePackage")
14+
15+
echo ""
16+
echo ""
17+
echo "========================================================================"
18+
printf "Validate sample '${BOLD}%s${RESET}' using: " "$sampleDir"
19+
cd "$sampleDir" || exit
20+
if [[ $(find . -name ${CI_VALIDATE_SCRIPT} -maxdepth 1) ]]; then
21+
echo -e "Custom ${BOLD}${CI_VALIDATE_SCRIPT}${RESET} script..."
22+
./${CI_VALIDATE_SCRIPT} || exit
23+
elif [[ $(find . -name 'build.gradle*' -maxdepth 1) ]]; then
24+
echo -e "${BOLD}Gradle${RESET} build..."
25+
./gradlew build || ./gradlew build --info # re-run to get better failure output
26+
else
27+
echo -e "${BOLD}SwiftPM${RESET} build..."
28+
swift build || exit
29+
fi
30+
31+
echo -e "Validated sample '${BOLD}${sampleDir}${RESET}': ${BOLD}passed${RESET}."
32+
cd - || exit
33+
done
34+
35+
echo
36+
printf "Done validating samples: "
37+
echo -e "${GREEN}done${RESET}."

.github/workflows/pull_request.yml

Lines changed: 42 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ jobs:
88
soundness:
99
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
1010
with:
11+
# Not API stable package (yet)
1112
api_breakage_check_enabled: false
1213
# FIXME: Something is off with the format task and it gets "stuck", need to investigate
1314
format_check_enabled: false
@@ -19,7 +20,8 @@ jobs:
1920
strategy:
2021
fail-fast: true
2122
matrix:
22-
swift_version: ['nightly-main']
23+
# swift_version: ['nightly-main']
24+
swift_version: ['6.0.2']
2325
os_version: ['jammy']
2426
jdk_vendor: ['Corretto']
2527
container:
@@ -28,58 +30,23 @@ jobs:
2830
JAVA_HOME: "/usr/lib/jvm/default-jdk"
2931
steps:
3032
- uses: actions/checkout@v4
31-
- name: Install System Dependencies
32-
run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev
33-
- name: Cache JDK
34-
id: cache-jdk
35-
uses: actions/cache@v4
36-
continue-on-error: true
37-
with:
38-
path: /usr/lib/jvm/default-jdk/
39-
key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }}
40-
restore-keys: |
41-
${{ runner.os }}-jdk-
42-
- name: Install JDK
43-
if: steps.cache-jdk.outputs.cache-hit != 'true'
44-
run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'"
45-
# TODO: not using setup-java since incompatible with the swiftlang/swift base image
46-
- name: Install Untested Nightly Swift
47-
run: "bash -xc './docker/install_untested_nightly_swift.sh'"
48-
- name: Cache local Gradle repository
49-
uses: actions/cache@v4
50-
continue-on-error: true
51-
with:
52-
path: |
53-
/root/.gradle/caches
54-
/root/.gradle/wrapper
55-
key: ${{ runner.os }}-gradle-${{ hashFiles('*/*.gradle*', 'settings.gradle') }}
56-
restore-keys: |
57-
${{ runner.os }}-gradle-
58-
- name: Cache local SwiftPM repository
59-
uses: actions/cache@v4
60-
continue-on-error: true
61-
with:
62-
path: /__w/swift-java/swift-java/.build/checkouts
63-
key: ${{ runner.os }}-swiftpm-cache-${{ hashFiles('Package.swift') }}
64-
restore-keys: |
65-
${{ runner.os }}-swiftpm-cache
66-
${{ runner.os }}-swiftpm-
67-
# run the actual build
68-
- name: Gradle build
69-
run: |
70-
./gradlew build -x test --no-daemon # just build
71-
./gradlew build --info --no-daemon
72-
- name: Gradle build (benchmarks)
73-
run: |
74-
./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
7541

7642
test-swift:
7743
name: Swift tests (swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}} os:${{ matrix.os_version }})
7844
runs-on: ubuntu-latest
7945
strategy:
8046
fail-fast: false
8147
matrix:
82-
swift_version: ['nightly-main']
48+
# swift_version: ['nightly-main']
49+
swift_version: ['6.0.2']
8350
os_version: ['jammy']
8451
jdk_vendor: ['Corretto']
8552
container:
@@ -88,51 +55,33 @@ jobs:
8855
JAVA_HOME: "/usr/lib/jvm/default-jdk"
8956
steps:
9057
- uses: actions/checkout@v4
91-
- name: Install System Dependencies
92-
run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev
93-
- name: Cache JDK
94-
id: cache-jdk
95-
uses: actions/cache@v4
96-
continue-on-error: true
97-
with:
98-
path: /usr/lib/jvm/default-jdk/
99-
key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }}
100-
restore-keys: |
101-
${{ runner.os }}-jdk-
102-
- name: Install JDK
103-
if: steps.cache-jdk.outputs.cache-hit != 'true'
104-
run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'"
105-
# TODO: not using setup-java since incompatible with the swiftlang/swift base image
106-
- name: Install Untested Nightly Swift
107-
run: "bash -xc './docker/install_untested_nightly_swift.sh'"
108-
- name: Cache local Gradle repository
109-
uses: actions/cache@v4
110-
continue-on-error: true
111-
with:
112-
path: |
113-
/root/.gradle/caches
114-
/root/.gradle/wrapper
115-
key: ${{ runner.os }}-gradle-${{ hashFiles('*/*.gradle*', 'settings.gradle') }}
116-
restore-keys: |
117-
${{ runner.os }}-gradle-
118-
- name: Cache local SwiftPM repository
119-
uses: actions/cache@v4
120-
continue-on-error: true
121-
with:
122-
path: /__w/swift-java/swift-java/.build/checkouts
123-
key: ${{ runner.os }}-swiftpm-cache-${{ hashFiles('Package.swift') }}
124-
restore-keys: |
125-
${{ runner.os }}-swiftpm-cache
126-
${{ runner.os }}-swiftpm-
127-
# run the actual build
128-
- name: Generate sources (make) (Temporary)
129-
# TODO: this should be triggered by the respective builds
130-
run: "make jextract-generate"
131-
- 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
13263
run: "swift test"
133-
- name: Build (Swift) Sample Apps
134-
run: |
135-
find Samples/ -name Package.swift -maxdepth 2 -exec swift build --package-path $(dirname {}) \;;
136-
# TODO: Benchmark compile crashes in CI, enable when nightly toolchains in better shape.
137-
# - name: Build (Swift) Benchmarks
138-
# run: "swift package --package-path Benchmarks/ benchmark list"
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)
84+
run: .github/scripts/validate_samples.sh
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ Makefile
3737
gradle/wrapper/gradle-wrapper.properties
3838
gradlew
3939
gradlew.bat
40+
**/gradlew
41+
**/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)