|
| 1 | +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 |
| 2 | +index d88c3c242ad..fcafd7676f5 100644 |
| 3 | +--- a/swift/utils/swift_build_support/swift_build_support/products/product.py |
| 4 | ++++ b/swift/utils/swift_build_support/swift_build_support/products/product.py |
| 5 | +@@ -409,18 +409,31 @@ class Product(object): |
| 6 | + toolchain_args = {} |
| 7 | + |
| 8 | + if crosscompiling: |
| 9 | +- toolchain_args['CMAKE_SYSTEM_NAME'] = 'Linux' |
| 10 | +- toolchain_args['CMAKE_SYSTEM_PROCESSOR'] = arch |
| 11 | ++ if platform == "linux": |
| 12 | ++ toolchain_args['CMAKE_SYSTEM_NAME'] = 'Linux' |
| 13 | ++ toolchain_args['CMAKE_SYSTEM_PROCESSOR'] = arch |
| 14 | ++ elif platform == "android": |
| 15 | ++ toolchain_args['CMAKE_SYSTEM_NAME'] = 'Android' |
| 16 | ++ toolchain_args['CMAKE_SYSTEM_VERSION'] = self.args.android_api_level |
| 17 | ++ toolchain_args['CMAKE_SYSTEM_PROCESSOR'] = self.args.android_arch if not \ |
| 18 | ++ self.args.android_arch == 'armv7' else 'armv7-a' |
| 19 | ++ toolchain_args['CMAKE_ANDROID_NDK'] = self.args.android_ndk |
| 20 | ++ toolchain_args['CMAKE_FIND_ROOT_PATH'] = self.args.cross_compile_deps_path |
| 21 | ++ toolchain_args['CMAKE_SHARED_LINKER_FLAGS'] = '\"\"' |
| 22 | + |
| 23 | + # We only set the actual sysroot if we are actually cross |
| 24 | + # compiling. This is important since otherwise cmake seems to change the |
| 25 | + # RUNPATH to be a relative rather than an absolute path, breaking |
| 26 | + # certain cmark tests (and maybe others). |
| 27 | +- maybe_sysroot = self.get_linux_sysroot(platform, arch) |
| 28 | +- if maybe_sysroot is not None: |
| 29 | +- toolchain_args['CMAKE_SYSROOT'] = maybe_sysroot |
| 30 | +- |
| 31 | +- target = self.get_linux_target(platform, arch) |
| 32 | ++ if platform == "linux": |
| 33 | ++ maybe_sysroot = self.get_linux_sysroot(platform, arch) |
| 34 | ++ if maybe_sysroot is not None: |
| 35 | ++ toolchain_args['CMAKE_SYSROOT'] = maybe_sysroot |
| 36 | ++ |
| 37 | ++ target = self.get_linux_target(platform, arch) |
| 38 | ++ elif platform == "android": |
| 39 | ++ target = '%s-unknown-linux-android%s' % (self.args.android_arch, |
| 40 | ++ self.args.android_api_level) |
| 41 | + if self.toolchain.cc.endswith('clang'): |
| 42 | + toolchain_args['CMAKE_C_COMPILER_TARGET'] = target |
| 43 | + if self.toolchain.cxx.endswith('clang++'): |
| 44 | +@@ -466,9 +479,19 @@ class Product(object): |
| 45 | + platform, arch, |
| 46 | + macos_deployment_version=override_macos_deployment_version) |
| 47 | + self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file) |
| 48 | +- elif platform == "linux": |
| 49 | +- toolchain_file = self.generate_linux_toolchain_file(platform, arch) |
| 50 | ++ elif platform == "linux" or platform == "android": |
| 51 | ++ # Always cross-compile for linux, but not on Android, as a native |
| 52 | ++ # compile on Android does not use the NDK and the CMake config. |
| 53 | ++ cross_compile = platform == "linux" or self.is_cross_compile_target(host_target) |
| 54 | ++ toolchain_file = self.generate_linux_toolchain_file(platform, arch, cross_compile) |
| 55 | + self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file) |
| 56 | ++ if cross_compile and platform == "android": |
| 57 | ++ resource_dir = None |
| 58 | ++ if not self.is_before_build_script_impl_product() and not self.is_build_script_impl_product(): |
| 59 | ++ install_path = self.host_install_destdir(host_target) + self.args.install_prefix |
| 60 | ++ resource_dir = '%s/lib/swift' % install_path |
| 61 | ++ flags = targets.StdlibDeploymentTarget.get_target_for_name(host_target).platform.swift_flags(self.args, resource_dir) |
| 62 | ++ self.cmake_options.define('CMAKE_Swift_FLAGS', flags) |
| 63 | + |
| 64 | + return toolchain_file |
| 65 | + |
| 66 | +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 |
| 67 | +index 417056efdd0..177ea9f0623 100644 |
| 68 | +--- a/swift/utils/swift_build_support/swift_build_support/products/swift_testing.py |
| 69 | ++++ b/swift/utils/swift_build_support/swift_build_support/products/swift_testing.py |
| 70 | +@@ -127,3 +127,11 @@ class SwiftTestingCMakeShim(cmake_product.CMakeProduct): |
| 71 | + install_prefix = install_destdir + self.args.install_prefix |
| 72 | + |
| 73 | + self.install_with_cmake(['install'], install_prefix) |
| 74 | ++ |
| 75 | ++ @classmethod |
| 76 | ++ def is_build_script_impl_product(cls): |
| 77 | ++ return False |
| 78 | ++ |
| 79 | ++ @classmethod |
| 80 | ++ def is_before_build_script_impl_product(cls): |
| 81 | ++ return False |
| 82 | +diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py |
| 83 | +index fba09416ddb..67b81daba12 100644 |
| 84 | +--- a/swift/utils/swift_build_support/swift_build_support/targets.py |
| 85 | ++++ b/swift/utils/swift_build_support/swift_build_support/targets.py |
| 86 | +@@ -72,7 +72,7 @@ class Platform(object): |
| 87 | + return True |
| 88 | + return False |
| 89 | + |
| 90 | +- def swift_flags(self, args): |
| 91 | ++ def swift_flags(self, args, resource_path=None): |
| 92 | + """ |
| 93 | + Swift compiler flags for a platform, useful for cross-compiling |
| 94 | + """ |
| 95 | +@@ -154,12 +154,15 @@ class AndroidPlatform(Platform): |
| 96 | + """ |
| 97 | + return True |
| 98 | + |
| 99 | +- def swift_flags(self, args): |
| 100 | ++ def swift_flags(self, args, resource_path=None): |
| 101 | + flags = '-target %s-unknown-linux-android%s ' % (args.android_arch, |
| 102 | + args.android_api_level) |
| 103 | + |
| 104 | +- flags += '-resource-dir %s/swift-%s-%s/lib/swift ' % ( |
| 105 | +- args.build_root, self.name, args.android_arch) |
| 106 | ++ if resource_path is not None: |
| 107 | ++ flags += '-resource-dir %s ' % (resource_path) |
| 108 | ++ else: |
| 109 | ++ flags += '-resource-dir %s/swift-%s-%s/lib/swift ' % ( |
| 110 | ++ args.build_root, self.name, args.android_arch) |
| 111 | + |
| 112 | + android_toolchain_path = self.ndk_toolchain_path(args) |
| 113 | + |
0 commit comments