From 66e45166e4b82217aec5bfc7050f1c93e8edd33d Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sat, 19 Jul 2025 14:34:23 -0400 Subject: [PATCH 1/7] Apply patches for 16KB page size for https://github.com/swiftlang/swift/pull/81596 --- .../sdks/android/patches/apply-patches.sh | 5 ++++ .../page-size-16KB-81398-AddSwiftStdlib.patch | 23 +++++++++++++++++++ .../page-size-16KB-81398-targets.patch | 13 +++++++++++ 3 files changed, 41 insertions(+) create mode 100644 swift-ci/sdks/android/patches/page-size-16KB-81398-AddSwiftStdlib.patch create mode 100644 swift-ci/sdks/android/patches/page-size-16KB-81398-targets.patch diff --git a/swift-ci/sdks/android/patches/apply-patches.sh b/swift-ci/sdks/android/patches/apply-patches.sh index dabb8e93..0800947e 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..a2bcbdc2 --- /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): + From 0f30c760c360eb7bbf54a91028962ffa606faa6d Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sat, 19 Jul 2025 15:15:38 -0400 Subject: [PATCH 2/7] Fix spacing in patch argument --- .../sdks/android/patches/page-size-16KB-81398-targets.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index a2bcbdc2..49308b51 100644 --- a/swift-ci/sdks/android/patches/page-size-16KB-81398-targets.patch +++ b/swift-ci/sdks/android/patches/page-size-16KB-81398-targets.patch @@ -5,7 +5,7 @@ index fba09416ddb..3fbc51955f4 100644 @@ -165,6 +165,7 @@ class AndroidPlatform(Platform): flags += '-sdk %s/sysroot ' % (android_toolchain_path) - flags += '-tools-directory %s/bin' % (android_toolchain_path) + flags += '-tools-directory %s/bin ' % (android_toolchain_path) + flags += '--Xclang-linker -Wl,-z,max-page-size=16384' return flags From 3ca9b6c5a3d27167f966e7e5083674077bddb795 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sat, 19 Jul 2025 15:40:26 -0400 Subject: [PATCH 3/7] Fix spacing in patch argument --- .../sdks/android/patches/page-size-16KB-81398-targets.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 49308b51..782a0ffe 100644 --- a/swift-ci/sdks/android/patches/page-size-16KB-81398-targets.patch +++ b/swift-ci/sdks/android/patches/page-size-16KB-81398-targets.patch @@ -5,8 +5,8 @@ index fba09416ddb..3fbc51955f4 100644 @@ -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' + flags += '-tools-directory %s/bin' % (android_toolchain_path) ++ flags += ' --Xclang-linker -Wl,-z,max-page-size=16384' return flags def cmake_options(self, args): From 5c68b61cc588fba06a752d5c3ae2095ec0fc62dc Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Sat, 19 Jul 2025 16:20:39 -0400 Subject: [PATCH 4/7] Fix linker argument in patch --- .../sdks/android/patches/page-size-16KB-81398-targets.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 782a0ffe..8b3d12c5 100644 --- a/swift-ci/sdks/android/patches/page-size-16KB-81398-targets.patch +++ b/swift-ci/sdks/android/patches/page-size-16KB-81398-targets.patch @@ -6,7 +6,7 @@ index fba09416ddb..3fbc51955f4 100644 flags += '-sdk %s/sysroot ' % (android_toolchain_path) flags += '-tools-directory %s/bin' % (android_toolchain_path) -+ flags += ' --Xclang-linker -Wl,-z,max-page-size=16384' ++ flags += ' -Xclang-linker -Wl,-z,max-page-size=16384' return flags def cmake_options(self, args): From 2bea7e00db78121a51149e4aba9e87b89954bc21 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Mon, 21 Jul 2025 15:38:24 -0400 Subject: [PATCH 5/7] Add -DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON to build --extra-cmake-options --- swift-ci/sdks/android/scripts/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index c28fa68f..e9f73c80 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -460,6 +460,7 @@ for arch in $archs; do --swift-testing --install-swift-testing \ --cross-compile-build-swift-tools=0 \ --llvm-ninja-targets-for-cross-compile-hosts=help \ + --extra-cmake-options='-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON' \ --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 From e7d18605b665073e6a00f34b620284e5f28d9f8d Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Mon, 21 Jul 2025 15:53:35 -0400 Subject: [PATCH 6/7] Push to trigger CI --- swift-ci/sdks/android/scripts/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index e9f73c80..ab66231c 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -462,6 +462,7 @@ for arch in $archs; do --llvm-ninja-targets-for-cross-compile-hosts=help \ --extra-cmake-options='-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON' \ --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: From 7af65b123f3d12f94d73f098111ae418d0b886d6 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Mon, 21 Jul 2025 17:50:20 -0400 Subject: [PATCH 7/7] Remove flag -DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON --- swift-ci/sdks/android/scripts/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swift-ci/sdks/android/scripts/build.sh b/swift-ci/sdks/android/scripts/build.sh index 3dcd78f8..562e3f08 100755 --- a/swift-ci/sdks/android/scripts/build.sh +++ b/swift-ci/sdks/android/scripts/build.sh @@ -462,9 +462,9 @@ for arch in $archs; do --llvm-ninja-targets-for-cross-compile-hosts=help \ --libdispatch-cmake-options=-DCMAKE_SHARED_LINKER_FLAGS= \ --foundation-cmake-options=-DCMAKE_SHARED_LINKER_FLAGS= \ - --extra-cmake-options='-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON' \ --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: