diff --git a/swift-ci/sdks/android/patches/apply-patches.sh b/swift-ci/sdks/android/patches/apply-patches.sh index 38f5fa89..51eeb9e3 100755 --- a/swift-ci/sdks/android/patches/apply-patches.sh +++ b/swift-ci/sdks/android/patches/apply-patches.sh @@ -3,6 +3,10 @@ patches_dir=$(dirname $(realpath -- "${BASH_SOURCE[0]}")) cd ${1} +# https://github.com/swiftlang/swift/pull/81596 +git apply -v -C1 ${patches_dir}/page-size-16KB-81398-AddSwiftStdlib.patch +git apply -v -C1 ${patches_dir}/page-size-16KB-81398-targets.patch + case "${BUILD_SCHEME}" in swift-*-branch) git apply -v -C1 ${patches_dir}/swift-android.patch @@ -20,3 +24,4 @@ esac # disable backtrace() for Android (needs either API33+ or libandroid-execinfo, or to manually add in backtrace backport) perl -pi -e 's;os\(Android\);os\(AndroidDISABLED\);g' swift-testing/Sources/Testing/SourceAttribution/Backtrace.swift + diff --git a/swift-ci/sdks/android/patches/page-size-16KB-81398-AddSwiftStdlib.patch b/swift-ci/sdks/android/patches/page-size-16KB-81398-AddSwiftStdlib.patch new file mode 100644 index 00000000..111bacd7 --- /dev/null +++ b/swift-ci/sdks/android/patches/page-size-16KB-81398-AddSwiftStdlib.patch @@ -0,0 +1,23 @@ +From 8db43c6290ee04145264c04728a030dd74f87452 Mon Sep 17 00:00:00 2001 +From: Marc Prud'hommeaux +Date: Sun, 18 May 2025 19:10:36 -0400 +Subject: [PATCH] Support 16 KB page sizes on Android + +Android 15+ requires that native libraries be compiled with a linker flag to support 16 KB page sizes. See: https://developer.android.com/guide/practices/page-sizes#compile-r26-lower +--- + stdlib/cmake/modules/AddSwiftStdlib.cmake | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake +index ce113989ad75d..089f5f30acbb5 100644 +--- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake ++++ b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake +@@ -2469,6 +2469,8 @@ function(add_swift_target_library name) + list(APPEND swiftlib_link_flags_all "-shared") + # TODO: Instead of `lib${name}.so` find variable or target property which already have this value. + list(APPEND swiftlib_link_flags_all "-Wl,-soname,lib${name}.so") ++ # Ensure compatibility with Android 15+ devices using 16KB memory pages. ++ list(APPEND swiftlib_link_flags_all "-Wl,-z,max-page-size=16384") + endif() + + if (SWIFTLIB_BACK_DEPLOYMENT_LIBRARY) diff --git a/swift-ci/sdks/android/patches/page-size-16KB-81398-targets.patch b/swift-ci/sdks/android/patches/page-size-16KB-81398-targets.patch new file mode 100644 index 00000000..8b3d12c5 --- /dev/null +++ b/swift-ci/sdks/android/patches/page-size-16KB-81398-targets.patch @@ -0,0 +1,13 @@ +diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py +index fba09416ddb..3fbc51955f4 100644 +--- a/swift/utils/swift_build_support/swift_build_support/targets.py ++++ b/swift/utils/swift_build_support/swift_build_support/targets.py +@@ -165,6 +165,7 @@ class AndroidPlatform(Platform): + + flags += '-sdk %s/sysroot ' % (android_toolchain_path) + flags += '-tools-directory %s/bin' % (android_toolchain_path) ++ flags += ' -Xclang-linker -Wl,-z,max-page-size=16384' + return flags + + def cmake_options(self, args): + diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index 06606a7f..562e3f08 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -463,6 +463,8 @@ for arch in $archs; do --libdispatch-cmake-options=-DCMAKE_SHARED_LINKER_FLAGS= \ --foundation-cmake-options=-DCMAKE_SHARED_LINKER_FLAGS= \ --cross-compile-append-host-target-to-destdir=False + + # --extra-cmake-options='-DCMAKE_EXTRA_LINK_FLAGS="-Wl,-z,max-page-size=16384"' # need to remove symlink that gets created in the NDK to the previous arch's build # or else we get errors like: