Skip to content

ci: simplistic way to get macOS running #294

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

Merged
merged 22 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c5e7107
ci: more simple way to get macOS running, reusable workflows facing some
ktoso Jun 30, 2025
5d222c6
ci: change how we install jdk on macos
ktoso Jun 30, 2025
33117fd
ci: we must use jdk21 for gradle, 24 is not supported yet
ktoso Jun 30, 2025
ea14b00
check if we can rely on setup-java again
ktoso Jun 30, 2025
19dbbf6
bump samples macos platform
ktoso Jun 30, 2025
7881418
ci: use setup-java to install multiple JDKs
ktoso Jun 30, 2025
47d063b
bump platform dependencies in samples
ktoso Jun 30, 2025
925f76f
cleanup
ktoso Jun 30, 2025
42f40d8
debuggin java home
ktoso Jun 30, 2025
519590c
arch must be uppercase for env variable
ktoso Jun 30, 2025
dca4ade
Help Gradle discover other installed JDKs
ktoso Jun 30, 2025
9a27372
set javac/java from setup-java env
ktoso Jun 30, 2025
44af804
futher help Gradle finding installed JDKs
ktoso Jun 30, 2025
efb23f8
try to teach gradle about setup-java env variables
ktoso Jun 30, 2025
5d151ca
gradle.properties in order to force gradle to use setup-java env
ktoso Jun 30, 2025
64328a7
gradle.properties does not need license
ktoso Jun 30, 2025
36cb245
split out JMH into separate job, remove redundant java_home env
ktoso Jul 1, 2025
e93c785
include new JNI jextract sample
ktoso Jul 1, 2025
6fca8b4
figure out where Swift lib paths are on CI
ktoso Jul 1, 2025
f6cee38
resort to Swiftly to simplify locating swift dylib paths for samples
ktoso Jul 1, 2025
18907f8
add gradle.properties to JNI example
ktoso Jul 1, 2025
defb820
cleaner swiftly install script
ktoso Jul 1, 2025
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
50 changes: 23 additions & 27 deletions .github/actions/prepare_env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,32 @@ description: 'Prepare the CI environment by installing Swift and selected JDK et
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 JDKs
id: cache-jdk
uses: actions/cache@v4
continue-on-error: true
- name: Set up JDK ${{ matrix.jdk_version }}
uses: actions/setup-java@v4
with:
path: /usr/lib/jvm/
key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/*') }}
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'"
distribution: ${{ matrix.jdk_vendor }}
java-version: |
24
21
cache: 'gradle'
- name: Set JAVA_HOME_{N}
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-
run: |
if [[ -n "$JAVA_HOME_21_X64" ]]; then
echo "JAVA_HOME_21=$JAVA_HOME_21_X64" >> $GITHUB_ENV
elif [[ -n "$JAVA_HOME_21_ARM64" ]]; then
echo "JAVA_HOME_21=$JAVA_HOME_21_ARM64" >> $GITHUB_ENV
fi
if [[ -n "$JAVA_HOME_24_X64" ]]; then
echo "JAVA_HOME_24=$JAVA_HOME_24_X64" >> $GITHUB_ENV
elif [[ -n "$JAVA_HOME_24_ARM64" ]]; then
echo "JAVA_HOME_24=$JAVA_HOME_24_ARM64" >> $GITHUB_ENV
fi
- name: Check Java environment
shell: bash
run: ./gradlew -q javaToolchains
- name: Cache local SwiftPM repository
if: matrix.os_version == 'jammy'
uses: actions/cache@v4
continue-on-error: true
with:
Expand Down
88 changes: 88 additions & 0 deletions .github/scripts/install_swiftly.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash

# This script is reused from Swiftly itself, see:
# https://github.com/swiftlang/swiftly/blob/main/scripts/prep-gh-action.sh
#
# This script does a bit of extra preparation of the docker containers used to run the GitHub workflows
# that are specific to this project's needs when building/testing. Note that this script runs on
# every supported Linux distribution and macOS so it must adapt to the distribution that it is running.

if [[ "$(uname -s)" == "Linux" ]]; then
# Install the basic utilities depending on the type of Linux distribution
apt-get --help && apt-get update && TZ=Etc/UTC apt-get -y install curl make gpg tzdata
yum --help && (curl --help && yum -y install curl) && yum install make gpg
fi

set -e

while [ $# -ne 0 ]; do
arg="$1"
case "$arg" in
snapshot)
swiftMainSnapshot=true
;;
*)
;;
esac
shift
done

echo "Installing swiftly"

if [[ "$(uname -s)" == "Linux" ]]; then
curl -O "https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz" && tar zxf swiftly-*.tar.gz && ./swiftly init -y --skip-install
# shellcheck disable=SC1091
. "/root/.local/share/swiftly/env.sh"
else
# shellcheck disable=SC2155
export SWIFTLY_HOME_DIR="$(pwd)/swiftly-bootstrap"
export SWIFTLY_BIN_DIR="$SWIFTLY_HOME_DIR/bin"
export SWIFTLY_TOOLCHAINS_DIR="$SWIFTLY_HOME_DIR/toolchains"

curl -O https://download.swift.org/swiftly/darwin/swiftly.pkg && pkgutil --check-signature swiftly.pkg && pkgutil --verbose --expand swiftly.pkg "${SWIFTLY_HOME_DIR}" && tar -C "${SWIFTLY_HOME_DIR}" -xvf "${SWIFTLY_HOME_DIR}"/swiftly-*/Payload && "$SWIFTLY_HOME_DIR/bin/swiftly" init -y --skip-install

# shellcheck disable=SC1091
. "$SWIFTLY_HOME_DIR/env.sh"
fi

hash -r

if [ -n "$GITHUB_ENV" ]; then
echo "Updating GitHub environment"
echo "PATH=$PATH" >> "$GITHUB_ENV" && echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> "$GITHUB_ENV" && echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> "$GITHUB_ENV" && echo "SWIFTLY_TOOLCHAINS_DIR=$SWIFTLY_TOOLCHAINS_DIR" >> "$GITHUB_ENV"
fi

selector=()
runSelector=()

if [ "$swiftMainSnapshot" == true ]; then
echo "Installing latest main-snapshot toolchain"
selector=("main-snapshot")
runSelector=("+main-snapshot")
elif [ -n "${SWIFT_VERSION}" ]; then
echo "Installing selected swift toolchain from SWIFT_VERSION environment variable"
selector=("${SWIFT_VERSION}")
runSelector=()
elif [ -f .swift-version ]; then
echo "Installing selected swift toolchain from .swift-version file"
selector=()
runSelector=()
else
echo "Installing latest toolchain"
selector=("latest")
runSelector=("+latest")
fi

swiftly install --post-install-file=post-install.sh "${selector[@]}"

if [ -f post-install.sh ]; then
echo "Performing swift toolchain post-installation"
chmod u+x post-install.sh && ./post-install.sh
fi

echo "Displaying swift version"
swiftly run "${runSelector[@]}" swift --version

if [[ "$(uname -s)" == "Linux" ]]; then
CC=clang swiftly run "${runSelector[@]}" "$(dirname "$0")/install-libarchive.sh"
fi
2 changes: 2 additions & 0 deletions .github/scripts/validate_sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ declare -r RESET='\033[0m'
declare -r sampleDir="$1"
declare -r CI_VALIDATE_SCRIPT='ci-validate.sh'

echo "Using Swift: $(which swift)"

echo ""
echo ""
echo "========================================================================"
Expand Down
110 changes: 97 additions & 13 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,37 @@ jobs:
license_header_check_project_name: Swift.org

test-java:
name: Java tests (swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}} os:${{ matrix.os_version }})
name: Test (Java) (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}})
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
swift_version: ['6.1.2']
os_version: ['jammy']
jdk_vendor: ['Corretto']
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"
SWIFT_JAVA_VERBOSE: true
steps:
- uses: actions/checkout@v4
- 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

test-java-macos:
name: Test (Java) (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}})
runs-on: [self-hosted, macos, sequoia, ARM64]
strategy:
fail-fast: true
matrix:
swift_version: ['6.1.2']
os_version: ['macos']
jdk_vendor: ['corretto']
env:
SWIFT_JAVA_VERBOSE: true
steps:
- uses: actions/checkout@v4
Expand All @@ -36,22 +55,59 @@ jobs:
run: ./gradlew build -x test
- name: Gradle :SwiftKit:check
run: ./gradlew :SwiftKit:check --debug

benchmark-java:
name: Benchmark (JMH) (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}})
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
swift_version: ['6.1.2']
os_version: ['jammy']
jdk_vendor: ['corretto']
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
env:
SWIFT_JAVA_VERBOSE: true
steps:
- uses: actions/checkout@v4
- name: Prepare CI Environment
uses: ./.github/actions/prepare_env
- 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 }})
name: Test (Swift) (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ['6.1.2']
os_version: ['jammy']
jdk_vendor: ['Corretto']
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"
SWIFT_JAVA_VERBOSE: true
steps:
- uses: actions/checkout@v4
- name: Prepare CI Environment
uses: ./.github/actions/prepare_env
- name: Swift Build
run: "swift build --build-tests --disable-sandbox"
- name: Swift Test
run: "swift test"

test-swift-macos:
name: Test (Swift) (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}})
runs-on: [self-hosted, macos, sequoia, ARM64]
strategy:
fail-fast: false
matrix:
swift_version: ['6.1.2']
os_version: ['macos']
jdk_vendor: ['corretto']
env:
SWIFT_JAVA_VERBOSE: true
steps:
- uses: actions/checkout@v4
Expand All @@ -63,30 +119,58 @@ jobs:
run: "swift test"

verify-samples:
name: Verify Sample ${{ matrix.sample_app }} (swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}} os:${{ matrix.os_version }})
name: Sample ${{ matrix.sample_app }} (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ['6.1.2']
os_version: ['jammy']
jdk_vendor: ['Corretto']
sample_app: [
jdk_vendor: ['corretto']
sample_app: [ # TODO: use a reusable-workflow to generate those names
'JavaDependencySampleApp',
'JavaKitSampleApp',
'JavaProbablyPrime',
'JavaSieve',
'SwiftAndJavaJarSampleLib',
'SwiftKitSampleApp',
'JExtractJNISampleApp'
'JExtractJNISampleApp',
]
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 sample"
- name: "Verify sample: ${{ matrix.sample_app }}"
run: .github/scripts/validate_sample.sh Samples/${{ matrix.sample_app }}


verify-samples-macos:
name: Sample ${{ matrix.sample_app }} (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}})
runs-on: [self-hosted, macos, sequoia, ARM64]
strategy:
fail-fast: false
matrix:
swift_version: ['6.1.2']
os_version: ['macos']
jdk_vendor: ['corretto']
sample_app: [ # TODO: use a reusable-workflow to generate those names
'JavaDependencySampleApp',
'JavaKitSampleApp',
'JavaProbablyPrime',
'JavaSieve',
'SwiftAndJavaJarSampleLib',
'SwiftKitSampleApp',
'JExtractJNISampleApp',
]
steps:
- uses: actions/checkout@v4
- name: Prepare CI Environment
uses: ./.github/actions/prepare_env
- name: Install Swiftly # we specifically install Swiftly in macOS jobs because we want a simpler way to find the right dylib paths for libraries
run: ./.github/scripts/install_swiftly.sh
env:
SWIFT_VERSION: "${{ matrix.swift_version }}"
- name: "Verify sample ${{ matrix.sample_app }}"
run: .github/scripts/validate_sample.sh Samples/${{ matrix.sample_app }}
2 changes: 2 additions & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Makefile
**/CMakeLists.txt
**/*.jar
**/generated/*.java
gradle.properties
**/gradle.properties
**/generated/*.swift
gradle/wrapper/gradle-wrapper.properties
gradlew
Expand Down
1 change: 1 addition & 0 deletions Samples/JExtractJNISampleApp/gradle.properties
3 changes: 3 additions & 0 deletions Samples/JavaDependencySampleApp/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ let package = Package(
name: "JavaDependencySampleApp",
platforms: [
.macOS(.v15),
.iOS(.v18),
.watchOS(.v11),
.tvOS(.v18),
],

products: [
Expand Down
1 change: 1 addition & 0 deletions Samples/JavaDependencySampleApp/gradle.properties
9 changes: 4 additions & 5 deletions Samples/JavaKitSampleApp/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ let javaIncludePath = "\(javaHome)/include"
let package = Package(
name: "JavaKitSampleApp",
platforms: [
.macOS(.v13),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6),
.macCatalyst(.v13),
.macOS(.v15),
.iOS(.v18),
.watchOS(.v11),
.tvOS(.v18),
],

products: [
Expand Down
1 change: 1 addition & 0 deletions Samples/JavaKitSampleApp/gradle.properties
5 changes: 4 additions & 1 deletion Samples/JavaProbablyPrime/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import PackageDescription
let package = Package(
name: "JavaProbablyPrime",
platforms: [
.macOS(.v10_15),
.macOS(.v15),
.iOS(.v18),
.watchOS(.v11),
.tvOS(.v18),
],

products: [
Expand Down
1 change: 1 addition & 0 deletions Samples/JavaProbablyPrime/gradle.properties
5 changes: 4 additions & 1 deletion Samples/JavaSieve/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ let javaIncludePath = "\(javaHome)/include"
let package = Package(
name: "JavaSieve",
platforms: [
.macOS(.v10_15),
.macOS(.v15),
.iOS(.v18),
.watchOS(.v11),
.tvOS(.v18),
],
dependencies: [
.package(name: "swift-java", path: "../../"),
Expand Down
Loading
Loading