diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..dc74f98 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +# These are supported funding model platforms +ko_fi: colemancda diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..07929eb --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,15 @@ +**Issue** + +Fixes #1. + +**What does this PR Do?** + +Description of the changes in this pull request. + +**Where should the reviewer start?** + +`main.swift` + +**Sweet giphy showing how you feel about this PR** + +![Giphy](https://media.giphy.com/media/rkDXJA9GoWR2/giphy.gif) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml new file mode 100644 index 0000000..83f4540 --- /dev/null +++ b/.github/workflows/swift.yml @@ -0,0 +1,21 @@ +name: Swift +on: [push] +jobs: + + android: + name: Android + strategy: + fail-fast: false + matrix: + swift: ['6.1'] + arch: ['aarch64', 'x86_64'] + sdk: ['24', '28', '29'] + runs-on: macos-15 + timeout-minutes: 30 + steps: + - uses: actions/checkout@v4 + - name: "Build Swift Package for Android" + run: | + brew install skiptools/skip/skip || (brew update && brew install skiptools/skip/skip) + skip android sdk install --version ${{ matrix.swift }} + ANDROID_NDK_ROOT="" ANDROID_SDK_VERSION=${{ matrix.sdk }} skip android build --arch ${{ matrix.arch }} --android-api-level ${{ matrix.sdk }} \ No newline at end of file diff --git a/Demo/app/build.gradle.kts b/Demo/app/build.gradle.kts index 0049bd9..0fb11be 100644 --- a/Demo/app/build.gradle.kts +++ b/Demo/app/build.gradle.kts @@ -10,7 +10,7 @@ android { defaultConfig { applicationId = "com.pureswift.swiftandroid" - minSdk = 24 + minSdk = 29 targetSdk = 35 versionCode = 1 versionName = "1.0" diff --git a/Demo/build-swift-preview.sh b/Demo/build-swift-preview.sh deleted file mode 100755 index ebf81ff..0000000 --- a/Demo/build-swift-preview.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -e -source swift-define - -# Build locally for preview -xcrun --toolchain swift swift build -c $SWIFT_COMPILATION_MODE \ - --package-path $SWIFT_PACKAGE_SRC - -# Copy to default Java JNI path -$ mkdir -p ~/Library/Java/Extensions -cp -rf $SWIFT_PACKAGE_SRC/.build/arm64-apple-macosx/debug/libSwiftAndroidApp.dylib \ - ~/Library/Java/Extensions/ \ No newline at end of file diff --git a/Demo/build-swift.sh b/Demo/build-swift.sh index 436790c..d2dcb53 100755 --- a/Demo/build-swift.sh +++ b/Demo/build-swift.sh @@ -3,11 +3,7 @@ set -e source swift-define # Build with SwiftPM -export JAVA_HOME=$SWIFT_ANDROID_SYSROOT/usr -xcrun --toolchain swift swift build -c $SWIFT_COMPILATION_MODE \ - --swift-sdk $SWIFT_TARGET_NAME \ - --toolchain $XCTOOLCHAIN \ - --package-path $SWIFT_PACKAGE_SRC +ANDROID_NDK_ROOT="" ANDROID_SDK_VERSION=$ANDROID_SDK_VERSION skip android build --arch $SWIFT_TARGET_ARCH --android-api-level $ANDROID_SDK_VERSION # Copy compiled Swift package mkdir -p $SRC_ROOT/app/src/main/jniLibs/$ANDROID_ARCH/ diff --git a/Demo/setup.sh b/Demo/setup.sh index a798ef5..5c15cea 100755 --- a/Demo/setup.sh +++ b/Demo/setup.sh @@ -5,32 +5,17 @@ source swift-define # Install macOS dependencies if [[ $OSTYPE == 'darwin'* ]]; then echo "Install macOS build dependencies" + brew install skiptools/skip/skip + brew update HOMEBREW_NO_AUTO_UPDATE=1 brew install wget cmake ninja android-ndk - - # Verify toolchain installed - if [ ! -d ${XCTOOLCHAIN} ] - then - echo "Please install the swift-6.0.3-RELEASE toolchain (or set XCTOOLCHAIN)" - echo "On Mac: https://download.swift.org/swift-6.0.3-release/xcode/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-osx.pkg" - exit 1 - fi -fi - -# Check swift-autolink-extract exists -if [[ ! -f "${XCTOOLCHAIN}/usr/bin/swift-autolink-extract" ]]; -then - echo "Missing symlink '${XCTOOLCHAIN}/usr/bin/swift-autolink-extract'." - echo "We need 'sudo' permission to create it (just this once)." - sudo ln -s swift ${XCTOOLCHAIN}/usr/bin/swift-autolink-extract || exit 1 fi # Copy Swift libraries +rm -rf $SRC_ROOT/app/src/main/jniLibs/$ANDROID_ARCH/ mkdir -p $SRC_ROOT/app/src/main/jniLibs/$ANDROID_ARCH/ -cp -rf $SWIFT_ANDROID_SYSROOT/usr/lib/$ANDROID_LIB/*.so \ +cp -rf $SWIFT_ANDROID_LIBS/*.so \ $SRC_ROOT/app/src/main/jniLibs/$ANDROID_ARCH/ # Copy C stdlib cp -rf $SWIFT_ANDROID_SYSROOT/usr/lib/$ANDROID_LIB/libc++_shared.so \ $SRC_ROOT/app/src/main/jniLibs/$ANDROID_ARCH/ -# Copy Swift dependencies -cp -rf $SWIFT_ANDROID_SYSROOT/usr/lib/$ANDROID_LIB/libandroid-spawn.so \ - $SRC_ROOT/app/src/main/jniLibs/$ANDROID_ARCH/ +echo "Copied Swift libraries" \ No newline at end of file diff --git a/Demo/swift-define b/Demo/swift-define index 459491d..66efe0b 100644 --- a/Demo/swift-define +++ b/Demo/swift-define @@ -6,16 +6,19 @@ ANDROID_LIB="${ANDROID_LIB:=aarch64-linux-android}" SWIFT_COMPILATION_MODE="${SWIFT_COMPILATION_MODE:=debug}" # Version -ANDROID_NDK_VERSION=24 -SWIFT_VERSION_SHORT=6.0.3 +ANDROID_SDK_VERSION=29 +SWIFT_VERSION_SHORT=6.1.1 SWIFT_VERSION=swift-$SWIFT_VERSION_SHORT-RELEASE -SWIFT_TARGET_NAME=$SWIFT_TARGET_ARCH-unknown-linux-android$ANDROID_NDK_VERSION +SWIFT_TARGET_NAME=$SWIFT_TARGET_ARCH-unknown-linux-android$ANDROID_SDK_VERSION XCTOOLCHAIN=/Library/Developer/Toolchains/$SWIFT_VERSION.xctoolchain +SWIFT_ARTIFACT_BUNDLE=swift-$SWIFT_VERSION_SHORT-RELEASE-android-0.1.artifactbundle # Paths -SWIFT_SDK=swift-$SWIFT_VERSION_SHORT-release-android-$ANDROID_NDK_VERSION-sdk -SWIFT_ANDROID_SYSROOT=~/.swiftpm/swift-sdks/swift-$SWIFT_VERSION_SHORT-RELEASE-android-24-0.1.artifactbundle/$SWIFT_SDK/android-27c-sysroot +SWIFT_SDK=swift-$SWIFT_VERSION_SHORT-release-android-$ANDROID_SDK_VERSION-sdk +SWIFT_ANDROID_SYSROOT=~/.swiftpm/swift-sdks/$SWIFT_ARTIFACT_BUNDLE/swift-android/ndk-sysroot +SWIFT_ANDROID_LIBS=~/.swiftpm/swift-sdks/$SWIFT_ARTIFACT_BUNDLE/swift-android/swift-resources/usr/lib/swift-$SWIFT_TARGET_ARCH/android/ SWIFT_PACKAGE_SRC=$SRC_ROOT +JAVA_HOME=$SWIFT_ANDROID_SYSROOT/usr # Configurable SWIFT_NATIVE_PATH="${SWIFT_NATIVE_PATH:=$XCTOOLCHAIN/usr/bin}" diff --git a/Package.swift b/Package.swift index 128f16e..5e557b9 100644 --- a/Package.swift +++ b/Package.swift @@ -1,44 +1,10 @@ -// swift-tools-version: 6.0 -// The swift-tools-version declares the minimum version of Swift required to build this package. - +// swift-tools-version: 6.1 import CompilerPluginSupport import PackageDescription import class Foundation.FileManager import class Foundation.ProcessInfo -// Note: the JAVA_HOME environment variable must be set to point to where -// Java is installed, e.g., -// Library/Java/JavaVirtualMachines/openjdk-21.jdk/Contents/Home. -func findJavaHome() -> String { - if let home = ProcessInfo.processInfo.environment["JAVA_HOME"] { - return home - } - - // This is a workaround for envs (some IDEs) which have trouble with - // picking up env variables during the build process - let path = "\(FileManager.default.homeDirectoryForCurrentUser.path()).java_home" - if let home = try? String(contentsOfFile: path, encoding: .utf8) { - if let lastChar = home.last, lastChar.isNewline { - return String(home.dropLast()) - } - - return home - } - - fatalError("Please set the JAVA_HOME environment variable to point to where Java is installed.") -} -let javaHome = findJavaHome() - -let javaIncludePath = "\(javaHome)/include" -#if os(Linux) - let javaPlatformIncludePath = "\(javaIncludePath)/linux" -#elseif os(macOS) - let javaPlatformIncludePath = "\(javaIncludePath)/darwin" -#elseif os(Windows) - let javaPlatformIncludePath = "\(javaIncludePath)/win32" -#endif - // Get NDK version from command line let ndkVersion = ProcessInfo.processInfo.environment["ANDROID_NDK_VERSION"].flatMap { UInt($0) } ?? 27 let ndkVersionDefine = SwiftSetting.define("ANDROID_NDK_VERSION_" + ndkVersion.description) @@ -118,10 +84,6 @@ var package = Package( name: "JavaKitReflection", package: "swift-java" ), - .product( - name: "Binder", - package: "Binder" - ), "AndroidNDK", "AndroidJava", "AndroidManifest", @@ -140,7 +102,6 @@ var package = Package( ], swiftSettings: [ .swiftLanguageMode(.v5), - .unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]), ndkVersionDefine, sdkVersionDefine ] diff --git a/README.md b/README.md index 5301981..46c2757 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Swift bindings to Android SDK (via Java Native Interface) ## Compile -Tested against [@finagolfin Swift Android SDK](https://github.com/finagolfin/swift-android-sdk) v6.0.3 +Tested against [Skip Tools](https://skip.tools/docs/gettingstarted/#installation) There is an included example Android application under `/Demo`. diff --git a/swift-define b/swift-define deleted file mode 100644 index 459491d..0000000 --- a/swift-define +++ /dev/null @@ -1,21 +0,0 @@ -# Configurable -SRC_ROOT="${SRC_ROOT:=$(pwd)}" -SWIFT_TARGET_ARCH="${SWIFT_TARGET_ARCH:=aarch64}" -ANDROID_ARCH="${ANDROID_ARCH:=arm64-v8a}" -ANDROID_LIB="${ANDROID_LIB:=aarch64-linux-android}" -SWIFT_COMPILATION_MODE="${SWIFT_COMPILATION_MODE:=debug}" - -# Version -ANDROID_NDK_VERSION=24 -SWIFT_VERSION_SHORT=6.0.3 -SWIFT_VERSION=swift-$SWIFT_VERSION_SHORT-RELEASE -SWIFT_TARGET_NAME=$SWIFT_TARGET_ARCH-unknown-linux-android$ANDROID_NDK_VERSION -XCTOOLCHAIN=/Library/Developer/Toolchains/$SWIFT_VERSION.xctoolchain - -# Paths -SWIFT_SDK=swift-$SWIFT_VERSION_SHORT-release-android-$ANDROID_NDK_VERSION-sdk -SWIFT_ANDROID_SYSROOT=~/.swiftpm/swift-sdks/swift-$SWIFT_VERSION_SHORT-RELEASE-android-24-0.1.artifactbundle/$SWIFT_SDK/android-27c-sysroot -SWIFT_PACKAGE_SRC=$SRC_ROOT - -# Configurable -SWIFT_NATIVE_PATH="${SWIFT_NATIVE_PATH:=$XCTOOLCHAIN/usr/bin}"