-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathswift-android.patch
171 lines (163 loc) · 8.61 KB
/
swift-android.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl
index 16e05052609..7ab8cebfab8 100755
--- a/swift/utils/build-script-impl
+++ b/swift/utils/build-script-impl
@@ -2622,6 +2622,7 @@ for host in "${ALL_HOSTS[@]}"; do
echo "Cleaning the libdispatch build directory"
call rm -rf "${LIBDISPATCH_BUILD_DIR}"
fi
+ call ln -sf "${SWIFT_BUILD_PATH}/lib/swift" "${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib"
cmake_options=(
-DENABLE_SWIFT=YES
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
index 324d1a77eea..e88601a8701 100644
--- 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
@@ -13,6 +13,9 @@
import os
from build_swift.build_swift.versions import Version
+from ..host_specific_configuration \
+ import HostSpecificConfiguration
+from ..targets import StdlibDeploymentTarget
from . import cmake_product
from . import product
@@ -115,6 +117,22 @@ class SwiftTestingCMakeShim(cmake_product.CMakeProduct):
# FIXME: If we build macros for the builder, specify the path.
self.cmake_options.define('SwiftTesting_MACRO', 'NO')
+ if host_target.startswith('android') and self.is_cross_compile_target(host_target):
+ host_config = HostSpecificConfiguration(host_target, self.args)
+ self.cmake_options.extend(host_config.cmake_options)
+ flags = '-target %s-unknown-linux-android%s ' % (self.args.android_arch,
+ self.args.android_api_level)
+
+ flags += '-resource-dir %s/lib/swift ' % (
+ self.host_install_destdir(host_target) + self.args.install_prefix)
+
+ ndk_path = StdlibDeploymentTarget.get_target_for_name(host_target).platform.ndk_toolchain_path(self.args)
+ flags += '-sdk %s/sysroot ' % (ndk_path)
+ flags += '-tools-directory %s/bin' % (ndk_path)
+ self.cmake_options.define('CMAKE_Swift_FLAGS', flags)
+ self.cmake_options.define('CMAKE_CXX_COMPILER_WORKS', 'True')
+ self.cmake_options.define('CMAKE_FIND_ROOT_PATH', self.args.cross_compile_deps_path)
+
self.generate_toolchain_file_for_darwin_or_linux(
host_target, override_macos_deployment_version=override_deployment_version)
self.build_with_cmake([], self.args.build_variant, [],
diff --git a/swift-corelibs-foundation/CMakeLists.txt b/swift-corelibs-foundation/CMakeLists.txt
index 7f290d16..95366592 100644
--- a/swift-corelibs-foundation/CMakeLists.txt
+++ b/swift-corelibs-foundation/CMakeLists.txt
@@ -51,6 +51,7 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
endif()
endif()
+set(CMAKE_SHARED_LINKER_FLAGS "")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
diff --git a/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt b/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
index 016bf294..5c42986a 100644
--- a/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
+++ b/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
@@ -162,6 +162,10 @@ if(NOT BUILD_SHARED_LIBS)
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend _FoundationICU>")
target_compile_options(Foundation PRIVATE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend swiftSynchronization>")
+ if(${CMAKE_SYSTEM_NAME} STREQUAL Android)
+ target_compile_options(Foundation PRIVATE
+ "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend android-spawn>")
+ endif()
endif()
set_target_properties(Foundation PROPERTIES
@@ -174,6 +174,12 @@
target_link_libraries(Foundation PUBLIC
swiftDispatch)
endif()
+ if(${CMAKE_SYSTEM_NAME} STREQUAL Android)
+ target_link_libraries(Foundation PRIVATE android-spawn)
+ list(GET CMAKE_FIND_ROOT_PATH 0 SPAWN_DIR)
+ target_include_directories(Foundation PUBLIC ${SPAWN_DIR}/usr/include)
+ target_link_directories(Foundation PUBLIC ${SPAWN_DIR}/usr/lib)
+ endif()
if(LINKER_SUPPORTS_BUILD_ID)
target_link_options(Foundation PRIVATE "LINKER:--build-id=sha1")
diff --git a/swift-corelibs-foundation/Sources/Foundation/Process.swift b/swift-corelibs-foundation/Sources/Foundation/Process.swift
index 758dd1df..02970992 100644
--- a/swift-corelibs-foundation/Sources/Foundation/Process.swift
+++ b/swift-corelibs-foundation/Sources/Foundation/Process.swift
@@ -927,8 +927,8 @@ open class Process: NSObject, @unchecked Sendable {
}
let useFallbackChdir: Bool
if let dir = currentDirectoryURL?.path {
- let chdirResult = _CFPosixSpawnFileActionsChdir(fileActions, dir)
- useFallbackChdir = chdirResult == ENOSYS
+ // let chdirResult = _CFPosixSpawnFileActionsChdir(fileActions, dir)
+ useFallbackChdir = true ; let chdirResult = ENOSYS
if !useFallbackChdir {
try _throwIfPosixError(chdirResult)
}
@@ -944,7 +944,7 @@ open class Process: NSObject, @unchecked Sendable {
var spawnAttrs: posix_spawnattr_t = posix_spawnattr_t()
#endif
try _throwIfPosixError(posix_spawnattr_init(&spawnAttrs))
-#if os(Android)
+#if os(Windows)
guard var spawnAttrs else {
throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno),
userInfo: [NSURLErrorKey:self.executableURL!])
diff --git a/swift-foundation/cmake/modules/SwiftFoundationSwiftSupport.cmake b/swift-foundation/cmake/modules/SwiftFoundationSwiftSupport.cmake
index cbdfc2a..bb4121d 100644
--- a/swift-foundation/cmake/modules/SwiftFoundationSwiftSupport.cmake
+++ b/swift-foundation/cmake/modules/SwiftFoundationSwiftSupport.cmake
@@ -37,6 +37,10 @@ function(_swift_foundation_install_target module)
set(module_triple_command "${CMAKE_Swift_COMPILER}" -print-target-info)
if(CMAKE_Swift_COMPILER_TARGET)
list(APPEND module_triple_command -target ${CMAKE_Swift_COMPILER_TARGET})
+ else()
+ set(arg_list ${CMAKE_Swift_FLAGS})
+ separate_arguments(arg_list)
+ list(APPEND module_triple_command ${arg_list})
endif()
execute_process(COMMAND ${module_triple_command} OUTPUT_VARIABLE target_info_json)
string(JSON module_triple GET "${target_info_json}" "target" "moduleTriple")
diff --git a/swift-testing/CMakeLists.txt b/swift-testing/CMakeLists.txt
index 1be9a4b..bd7b1bd 100644
--- a/swift-testing/CMakeLists.txt
+++ b/swift-testing/CMakeLists.txt
@@ -28,6 +28,7 @@ list(APPEND CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake/modules
${PROJECT_SOURCE_DIR}/cmake/modules/shared)
+set(CMAKE_SHARED_LINKER_FLAGS "")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
diff --git a/swift-testing/Sources/Testing/CMakeLists.txt b/swift-testing/Sources/Testing/CMakeLists.tx
index e40cb1b..ff2f920 100644
--- a/swift-testing/Sources/Testing/CMakeLists.txt
+++ b/swift-testing/Sources/Testing/CMakeLists.txt
@@ -110,7 +110,10 @@ target_link_libraries(Testing PRIVATE
if(NOT APPLE)
if(NOT CMAKE_SYSTEM_NAME STREQUAL WASI)
target_link_libraries(Testing PUBLIC
- dispatch)
+ dispatch android-execinfo)
+ list(GET CMAKE_FIND_ROOT_PATH 0 BT_DIR)
+ target_include_directories(Testing PUBLIC ${BT_DIR}/usr/include)
+ target_link_directories(Testing PUBLIC ${BT_DIR}/usr/lib)
endif()
target_link_libraries(Testing PUBLIC
Foundation)
diff --git a/swift-testing/cmake/modules/TargetTriple.cmake b/swift-testing/cmake/modules/TargetTriple.cmake
index e087cc4..02f3a95 100644
--- a/swift-testing/cmake/modules/TargetTriple.cmake
+++ b/swift-testing/cmake/modules/TargetTriple.cmake
@@ -10,6 +10,10 @@
set(SWT_TARGET_INFO_COMMAND "${CMAKE_Swift_COMPILER}" -print-target-info)
if(CMAKE_Swift_COMPILER_TARGET)
list(APPEND SWT_TARGET_INFO_COMMAND -target ${CMAKE_Swift_COMPILER_TARGET})
+else()
+ set(arg_list ${CMAKE_Swift_FLAGS})
+ separate_arguments(arg_list)
+ list(APPEND SWT_TARGET_INFO_COMMAND ${arg_list})
endif()
execute_process(COMMAND ${SWT_TARGET_INFO_COMMAND} OUTPUT_VARIABLE SWT_TARGET_INFO_JSON)
string(JSON SWT_TARGET_TRIPLE GET "${SWT_TARGET_INFO_JSON}" "target" "unversionedTriple")