|
| 1 | +diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake |
| 2 | +index 0b18957eadb..5021409ba06 100644 |
| 3 | +--- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake |
| 4 | ++++ b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake |
| 5 | +@@ -2504,6 +2504,8 @@ function(add_swift_target_library name) |
| 6 | + list(APPEND swiftlib_link_flags_all "-shared") |
| 7 | + # TODO: Instead of `lib${name}.so` find variable or target property which already have this value. |
| 8 | + list(APPEND swiftlib_link_flags_all "-Wl,-soname,lib${name}.so") |
| 9 | ++ # Ensure compatibility with Android 15+ devices using 16KB memory pages. |
| 10 | ++ list(APPEND swiftlib_link_flags_all "-Wl,-z,max-page-size=16384") |
| 11 | + endif() |
| 12 | + |
| 13 | + if (SWIFTLIB_BACK_DEPLOYMENT_LIBRARY) |
| 14 | +diff --git a/swift/test/SILOptimizer/concat_string_literals.32.swift b/swift/test/SILOptimizer/concat_string_literals.32.swift |
| 15 | +index 01390761c8c..d84c142397c 100644 |
| 16 | +--- a/swift/test/SILOptimizer/concat_string_literals.32.swift |
| 17 | ++++ b/swift/test/SILOptimizer/concat_string_literals.32.swift |
| 18 | +@@ -4,6 +4,7 @@ |
| 19 | + |
| 20 | + // We have a separate test for 64-bit architectures. |
| 21 | + // REQUIRES: PTRSIZE=32 |
| 22 | ++// XFAIL: OS=linux-androideabi |
| 23 | + |
| 24 | + // NOTE: 25185.byteSwapped = 0x62 'a', 0x61 'b' |
| 25 | + // CHECK-LABEL: test_ascii_scalar_scalar2 |
| 26 | +diff --git a/swift/utils/swift_build_support/swift_build_support/products/product.py b/swift/utils/swift_build_support/swift_build_support/products/product.py |
| 27 | +index 47e7ab79905..6bd94c3cad8 100644 |
| 28 | +--- a/swift/utils/swift_build_support/swift_build_support/products/product.py |
| 29 | ++++ b/swift/utils/swift_build_support/swift_build_support/products/product.py |
| 30 | +@@ -389,7 +389,7 @@ class Product(object): |
| 31 | + sysroot_arch, vendor, abi = self.get_linux_target_components(arch) |
| 32 | + return '{}-{}-linux-{}'.format(sysroot_arch, vendor, abi) |
| 33 | + |
| 34 | +- def generate_linux_toolchain_file(self, platform, arch): |
| 35 | ++ def generate_linux_toolchain_file(self, platform, arch, crosscompiling=True): |
| 36 | + """ |
| 37 | + Generates a new CMake tolchain file that specifies Linux as a target |
| 38 | + platform. |
| 39 | +@@ -402,18 +402,34 @@ class Product(object): |
| 40 | + |
| 41 | + toolchain_args = {} |
| 42 | + |
| 43 | +- toolchain_args['CMAKE_SYSTEM_NAME'] = 'Linux' |
| 44 | +- toolchain_args['CMAKE_SYSTEM_PROCESSOR'] = arch |
| 45 | ++ if crosscompiling: |
| 46 | ++ if platform == "linux": |
| 47 | ++ toolchain_args['CMAKE_SYSTEM_NAME'] = 'Linux' |
| 48 | ++ toolchain_args['CMAKE_SYSTEM_PROCESSOR'] = arch |
| 49 | ++ elif platform == "android": |
| 50 | ++ toolchain_args['CMAKE_SYSTEM_NAME'] = 'Android' |
| 51 | ++ toolchain_args['CMAKE_SYSTEM_VERSION'] = self.args.android_api_level |
| 52 | ++ toolchain_args['CMAKE_SYSTEM_PROCESSOR'] = arch if not arch == 'armv7' \ |
| 53 | ++ else 'armv7-a' |
| 54 | ++ toolchain_args['CMAKE_ANDROID_NDK'] = self.args.android_ndk |
| 55 | ++ toolchain_args['CMAKE_FIND_ROOT_PATH'] = self.args.cross_compile_deps_path |
| 56 | ++ # This is a workaround for a CMake 3.30+ bug, |
| 57 | ++ # https://gitlab.kitware.com/cmake/cmake/-/issues/26154, and can |
| 58 | ++ # be removed once that is fixed. |
| 59 | ++ toolchain_args['CMAKE_SHARED_LINKER_FLAGS'] = '\"\"' |
| 60 | + |
| 61 | + # We only set the actual sysroot if we are actually cross |
| 62 | + # compiling. This is important since otherwise cmake seems to change the |
| 63 | + # RUNPATH to be a relative rather than an absolute path, breaking |
| 64 | + # certain cmark tests (and maybe others). |
| 65 | +- maybe_sysroot = self.get_linux_sysroot(platform, arch) |
| 66 | +- if maybe_sysroot is not None: |
| 67 | +- toolchain_args['CMAKE_SYSROOT'] = maybe_sysroot |
| 68 | +- |
| 69 | +- target = self.get_linux_target(platform, arch) |
| 70 | ++ if platform == "linux": |
| 71 | ++ maybe_sysroot = self.get_linux_sysroot(platform, arch) |
| 72 | ++ if maybe_sysroot is not None: |
| 73 | ++ toolchain_args['CMAKE_SYSROOT'] = maybe_sysroot |
| 74 | ++ |
| 75 | ++ target = self.get_linux_target(platform, arch) |
| 76 | ++ elif platform == "android": |
| 77 | ++ target = '%s-unknown-linux-android%s' % (arch, self.args.android_api_level) |
| 78 | + if self.toolchain.cc.endswith('clang'): |
| 79 | + toolchain_args['CMAKE_C_COMPILER_TARGET'] = target |
| 80 | + if self.toolchain.cxx.endswith('clang++'): |
| 81 | +@@ -459,10 +475,30 @@ class Product(object): |
| 82 | + platform, arch, |
| 83 | + macos_deployment_version=override_macos_deployment_version) |
| 84 | + self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file) |
| 85 | +- elif platform == "linux": |
| 86 | +- toolchain_file = self.generate_linux_toolchain_file(platform, arch) |
| 87 | ++ elif platform == "linux" or platform == "android": |
| 88 | ++ # Always cross-compile for linux, but not on Android, as a native |
| 89 | ++ # compile on Android does not use the NDK and its CMake config. |
| 90 | ++ cross_compile = platform == "linux" or \ |
| 91 | ++ self.is_cross_compile_target(host_target) |
| 92 | ++ toolchain_file = self.generate_linux_toolchain_file(platform, arch, |
| 93 | ++ cross_compile) |
| 94 | + self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file) |
| 95 | + |
| 96 | ++ if cross_compile and platform == "android": |
| 97 | ++ resource_dir = None |
| 98 | ++ # build-script-impl products build before the install and use |
| 99 | ++ # the Swift stdlib from the compiler build directory instead, |
| 100 | ++ # while products built even before that currently do not support |
| 101 | ++ # cross-compiling Swift. |
| 102 | ++ if not self.is_before_build_script_impl_product() and \ |
| 103 | ++ not self.is_build_script_impl_product(): |
| 104 | ++ install_path = self.host_install_destdir(host_target) + \ |
| 105 | ++ self.args.install_prefix |
| 106 | ++ resource_dir = '%s/lib/swift' % install_path |
| 107 | ++ flags = targets.StdlibDeploymentTarget.get_target_for_name( |
| 108 | ++ host_target).platform.swift_flags(self.args, resource_dir) |
| 109 | ++ self.cmake_options.define('CMAKE_Swift_FLAGS', flags) |
| 110 | ++ |
| 111 | + return toolchain_file |
| 112 | + |
| 113 | + def get_openbsd_toolchain_file(self): |
| 114 | +diff --git a/swift/utils/swift_build_support/swift_build_support/products/swift_testing.py b/swift/utils/swift_build_support/swift_build_support/products/swift_testing.py |
| 115 | +index 417056efdd0..177ea9f0623 100644 |
| 116 | +--- a/swift/utils/swift_build_support/swift_build_support/products/swift_testing.py |
| 117 | ++++ b/swift/utils/swift_build_support/swift_build_support/products/swift_testing.py |
| 118 | +@@ -127,3 +127,11 @@ class SwiftTestingCMakeShim(cmake_product.CMakeProduct): |
| 119 | + install_prefix = install_destdir + self.args.install_prefix |
| 120 | + |
| 121 | + self.install_with_cmake(['install'], install_prefix) |
| 122 | ++ |
| 123 | ++ @classmethod |
| 124 | ++ def is_build_script_impl_product(cls): |
| 125 | ++ return False |
| 126 | ++ |
| 127 | ++ @classmethod |
| 128 | ++ def is_before_build_script_impl_product(cls): |
| 129 | ++ return False |
| 130 | +diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py |
| 131 | +index 508d6204eaf..64a862eaf0e 100644 |
| 132 | +--- a/swift/utils/swift_build_support/swift_build_support/targets.py |
| 133 | ++++ b/swift/utils/swift_build_support/swift_build_support/targets.py |
| 134 | +@@ -72,7 +72,7 @@ class Platform(object): |
| 135 | + return True |
| 136 | + return False |
| 137 | + |
| 138 | +- def swift_flags(self, args): |
| 139 | ++ def swift_flags(self, args, resource_path=None): |
| 140 | + """ |
| 141 | + Swift compiler flags for a platform, useful for cross-compiling |
| 142 | + """ |
| 143 | +@@ -154,17 +154,21 @@ class AndroidPlatform(Platform): |
| 144 | + """ |
| 145 | + return True |
| 146 | + |
| 147 | +- def swift_flags(self, args): |
| 148 | ++ def swift_flags(self, args, resource_path=None): |
| 149 | + flags = '-target %s-unknown-linux-android%s ' % (args.android_arch, |
| 150 | + args.android_api_level) |
| 151 | + |
| 152 | +- flags += '-resource-dir %s/swift-%s-%s/lib/swift ' % ( |
| 153 | +- args.build_root, self.name, args.android_arch) |
| 154 | ++ if resource_path is not None: |
| 155 | ++ flags += '-resource-dir %s ' % (resource_path) |
| 156 | ++ else: |
| 157 | ++ flags += '-resource-dir %s/swift-%s-%s/lib/swift ' % ( |
| 158 | ++ args.build_root, self.name, args.android_arch) |
| 159 | + |
| 160 | + android_toolchain_path = self.ndk_toolchain_path(args) |
| 161 | + |
| 162 | + flags += '-sdk %s/sysroot ' % (android_toolchain_path) |
| 163 | +- flags += '-tools-directory %s/bin' % (android_toolchain_path) |
| 164 | ++ flags += '-tools-directory %s/bin ' % (android_toolchain_path) |
| 165 | ++ flags += '-Xclang-linker -Wl,-z,max-page-size=16384' |
| 166 | + return flags |
| 167 | + |
| 168 | + def cmake_options(self, args): |
1 | 169 | diff --git a/swift/utils/swift_build_support/swift_build_support/cmake.py b/swift/utils/swift_build_support/swift_build_support/cmake.py
|
2 | 170 | index bfb69965890..b5e9f5349c2 100644
|
3 | 171 | --- a/swift/utils/swift_build_support/swift_build_support/cmake.py
|
|
0 commit comments