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