Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign jextract-swift: plugins and avoid custom swift features #170

Merged
merged 8 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/actions/prepare_env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: 'Swift Java CI Env'
description: 'Prepare the CI environment by installing Swift and selected JDK etc.'

runs:
using: composite
steps:
- name: Install System Dependencies
run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev
shell: bash
- name: Cache JDK
id: cache-jdk
uses: actions/cache@v4
continue-on-error: true
with:
path: /usr/lib/jvm/default-jdk/
key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }}
restore-keys: |
${{ runner.os }}-jdk-
- name: Install JDK
if: steps.cache-jdk.outputs.cache-hit != 'true'
run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'"
shell: bash
# TODO: not using setup-java since incompatible with the swiftlang/swift base image
# - name: Install Untested Nightly Swift
# run: "bash -xc './docker/install_untested_nightly_swift.sh'"
- name: Cache local Gradle repository
uses: actions/cache@v4
continue-on-error: true
with:
path: |
/root/.gradle/caches
/root/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('*/*.gradle*', 'settings.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache local SwiftPM repository
uses: actions/cache@v4
continue-on-error: true
with:
path: /__w/swift-java/swift-java/.build/checkouts
key: ${{ runner.os }}-swiftpm-cache-${{ hashFiles('Package.swift') }}
restore-keys: |
${{ runner.os }}-swiftpm-cache
${{ runner.os }}-swiftpm-
37 changes: 37 additions & 0 deletions .github/scripts/validate_samples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# shellcheck disable=SC2034
declare -r GREEN='\033[0;32m'
declare -r BOLD='\033[1m'
declare -r RESET='\033[0m'

# shellcheck disable=SC2155
declare -r SAMPLE_PACKAGES=$(find Samples -name Package.swift -maxdepth 2)
declare -r CI_VALIDATE_SCRIPT='ci-validate.sh'

for samplePackage in ${SAMPLE_PACKAGES} ; do
sampleDir=$(dirname "$samplePackage")

echo ""
echo ""
echo "========================================================================"
printf "Validate sample '${BOLD}%s${RESET}' using: " "$sampleDir"
cd "$sampleDir" || exit
if [[ $(find . -name ${CI_VALIDATE_SCRIPT} -maxdepth 1) ]]; then
echo -e "Custom ${BOLD}${CI_VALIDATE_SCRIPT}${RESET} script..."
./${CI_VALIDATE_SCRIPT} || exit
elif [[ $(find . -name 'build.gradle*' -maxdepth 1) ]]; then
echo -e "${BOLD}Gradle${RESET} build..."
./gradlew build || ./gradlew build --info # re-run to get better failure output
else
echo -e "${BOLD}SwiftPM${RESET} build..."
swift build || exit
fi

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

echo
printf "Done validating samples: "
echo -e "${GREEN}done${RESET}."
135 changes: 42 additions & 93 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
soundness:
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
with:
# Not API stable package (yet)
api_breakage_check_enabled: false
# FIXME: Something is off with the format task and it gets "stuck", need to investigate
format_check_enabled: false
Expand All @@ -19,7 +20,8 @@ jobs:
strategy:
fail-fast: true
matrix:
swift_version: ['nightly-main']
# swift_version: ['nightly-main']
swift_version: ['6.0.2']
os_version: ['jammy']
jdk_vendor: ['Corretto']
container:
Expand All @@ -28,58 +30,23 @@ jobs:
JAVA_HOME: "/usr/lib/jvm/default-jdk"
steps:
- uses: actions/checkout@v4
- name: Install System Dependencies
run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev
- name: Cache JDK
id: cache-jdk
uses: actions/cache@v4
continue-on-error: true
with:
path: /usr/lib/jvm/default-jdk/
key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }}
restore-keys: |
${{ runner.os }}-jdk-
- name: Install JDK
if: steps.cache-jdk.outputs.cache-hit != 'true'
run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'"
# TODO: not using setup-java since incompatible with the swiftlang/swift base image
- name: Install Untested Nightly Swift
run: "bash -xc './docker/install_untested_nightly_swift.sh'"
- name: Cache local Gradle repository
uses: actions/cache@v4
continue-on-error: true
with:
path: |
/root/.gradle/caches
/root/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('*/*.gradle*', 'settings.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache local SwiftPM repository
uses: actions/cache@v4
continue-on-error: true
with:
path: /__w/swift-java/swift-java/.build/checkouts
key: ${{ runner.os }}-swiftpm-cache-${{ hashFiles('Package.swift') }}
restore-keys: |
${{ runner.os }}-swiftpm-cache
${{ runner.os }}-swiftpm-
# run the actual build
- name: Gradle build
run: |
./gradlew build -x test --no-daemon # just build
./gradlew build --info --no-daemon
- name: Gradle build (benchmarks)
run: |
./gradlew compileJmh --info --no-daemon
- name: Prepare CI Environment
uses: ./.github/actions/prepare_env
- name: Gradle :SwiftKit:build
run: ./gradlew build -x test
- name: Gradle :SwiftKit:check
run: ./gradlew :SwiftKit:check --info
- name: Gradle compile JMH benchmarks
run: ./gradlew compileJmh --info

test-swift:
name: Swift tests (swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}} os:${{ matrix.os_version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ['nightly-main']
# swift_version: ['nightly-main']
swift_version: ['6.0.2']
os_version: ['jammy']
jdk_vendor: ['Corretto']
container:
Expand All @@ -88,51 +55,33 @@ jobs:
JAVA_HOME: "/usr/lib/jvm/default-jdk"
steps:
- uses: actions/checkout@v4
- name: Install System Dependencies
run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev
- name: Cache JDK
id: cache-jdk
uses: actions/cache@v4
continue-on-error: true
with:
path: /usr/lib/jvm/default-jdk/
key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }}
restore-keys: |
${{ runner.os }}-jdk-
- name: Install JDK
if: steps.cache-jdk.outputs.cache-hit != 'true'
run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'"
# TODO: not using setup-java since incompatible with the swiftlang/swift base image
- name: Install Untested Nightly Swift
run: "bash -xc './docker/install_untested_nightly_swift.sh'"
- name: Cache local Gradle repository
uses: actions/cache@v4
continue-on-error: true
with:
path: |
/root/.gradle/caches
/root/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('*/*.gradle*', 'settings.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Cache local SwiftPM repository
uses: actions/cache@v4
continue-on-error: true
with:
path: /__w/swift-java/swift-java/.build/checkouts
key: ${{ runner.os }}-swiftpm-cache-${{ hashFiles('Package.swift') }}
restore-keys: |
${{ runner.os }}-swiftpm-cache
${{ runner.os }}-swiftpm-
# run the actual build
- name: Generate sources (make) (Temporary)
# TODO: this should be triggered by the respective builds
run: "make jextract-generate"
- name: Test Swift
- name: Prepare CI Environment
uses: ./.github/actions/prepare_env
- name: Swift Build
run: "swift build --build-tests"
- name: Swift Test
run: "swift test"
- name: Build (Swift) Sample Apps
run: |
find Samples/ -name Package.swift -maxdepth 2 -exec swift build --package-path $(dirname {}) \;;
# TODO: Benchmark compile crashes in CI, enable when nightly toolchains in better shape.
# - name: Build (Swift) Benchmarks
# run: "swift package --package-path Benchmarks/ benchmark list"

verify-samples:
name: Verify Samples (swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}} os:${{ matrix.os_version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# swift_version: ['nightly-main']
swift_version: ['6.0.2']
os_version: ['jammy']
jdk_vendor: ['Corretto']
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
env:
JAVA_HOME: "/usr/lib/jvm/default-jdk"
steps:
- uses: actions/checkout@v4
- name: Prepare CI Environment
uses: ./.github/actions/prepare_env
- name: Verify Samples (All)
run: .github/scripts/validate_samples.sh
# TODO: Benchmark compile crashes in CI, enable when nightly toolchains in better shape.
# - name: Build (Swift) Benchmarks
# run: "swift package --package-path Benchmarks/ benchmark list"
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.build
.idea
Packages
xcuserdata/
DerivedData/
Expand Down Expand Up @@ -33,3 +34,8 @@ Package.resolved

# Ignore files generated by jextract, we always can re-generate them
*/**/src/generated/java/**/*

*/**/*.d
*/**/*.o
*/**/*.swiftdeps
*/**/*.swiftdeps~
3 changes: 3 additions & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ Makefile
gradle/wrapper/gradle-wrapper.properties
gradlew
gradlew.bat
**/gradlew
**/gradlew.bat
**/ci-validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//

import java.util.*
import java.io.*

plugins {
java
Expand Down Expand Up @@ -44,30 +45,36 @@ tasks.withType(JavaCompile::class).forEach {


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

return listOf(
if (isLinux) {
if (osArch.equals("x86_64") || osArch.equals("amd64")) {
"$rootDir/.build/x86_64-unknown-linux-gnu/debug/"
"$dir/.build/x86_64-unknown-linux-gnu/debug/"
} else {
"$rootDir/.build/$osArch-unknown-linux-gnu/debug/"
"$dir/.build/$osArch-unknown-linux-gnu/debug/"
}
} else {
if (osArch.equals("aarch64")) {
"$rootDir/.build/arm64-apple-macosx/debug/"
"$dir/.build/arm64-apple-macosx/debug/"
} else {
"$rootDir/.build/$osArch-apple-macosx/debug/"
"$dir/.build/$osArch-apple-macosx/debug/"
}
},
if (isLinux) {
"/usr/lib/swift/linux"
} else {
// assume macOS
"/usr/lib/swift/"
},
if (isLinux) {
System.getProperty("user.home") + "/.local/share/swiftly/toolchains/6.0.2/usr/lib/swift/linux"
} else {
// assume macOS
"/usr/lib/swift/"
}
)
}
Expand All @@ -79,7 +86,9 @@ tasks.test {
"--enable-native-access=ALL-UNNAMED",

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

Expand All @@ -88,17 +97,3 @@ tasks.withType<Test> {
this.showStandardStreams = true
}
}


// TODO: This is a crude workaround, we'll remove 'make' soon and properly track build dependencies
// val buildSwiftJExtract = tasks.register<Exec>("buildMake") {
// description = "Triggers 'make' build"
//
// workingDir(rootDir)
// commandLine("make")
// }
//
// tasks.build {
// dependsOn(buildSwiftJExtract)
// }

Loading