Skip to content

Commit 716ef96

Browse files
authored
Merge pull request #80262 from compnerd/android-overlay
Runtimes: add overlay for Android platform
2 parents 911ae5f + 4b37602 commit 716ef96

File tree

6 files changed

+114
-1
lines changed

6 files changed

+114
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
gyb_expand(tgmath.swift.gyb tgmath.swift)
3+
4+
add_library(swiftAndroid
5+
tgmath.swift
6+
Android.swift
7+
Platform.swift
8+
POSIXError.swift
9+
TiocConstants.swift)
10+
set_target_properties(swiftAndroid PROPERTIES
11+
Swift_MODULE_NAME Android)
12+
target_compile_definitions(swiftAndroid PRIVATE
13+
$<$<BOOL:${SwiftOverlay_ENABLE_REFLECTION}>:SWIFT_ENABLE_REFLECTION>)
14+
target_link_libraries(swiftAndroid PRIVATE
15+
SwiftAndroid
16+
swiftCore)
17+
18+
install(TARGETS swiftAndroid
19+
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
20+
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
21+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
22+
emit_swift_interface(swiftAndroid)
23+
install_swift_interface(swiftAndroid)
24+
25+
embed_manifest(swiftAndroid)
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
add_subdirectory(clang)
3+
add_subdirectory(Android)
4+
add_subdirectory(Math)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
add_library(swift_math
3+
Math.swift)
4+
set_target_properties(swift_math PROPERTIES
5+
Swift_MODULE_NAME math)
6+
target_link_libraries(swift_math PRIVATE
7+
SwiftAndroid
8+
swiftCore)
9+
10+
install(TARGETS swift_math
11+
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
12+
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
13+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
14+
emit_swift_interface(swift_math)
15+
install_swift_interface(swift_math)
16+
17+
embed_manifest(swift_math)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
# FIXME: how do we determine the sysroot? `CMAKE_SYSROOT` does not contain the sysroot.
3+
file(CONFIGURE
4+
OUTPUT android-ndk-overlay.yaml
5+
CONTENT [[
6+
---
7+
version: 0
8+
case-sensitive: false
9+
use-external-names: false
10+
roots:
11+
- name: "@CMAKE_ANDROID_NDK@/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include"
12+
type: directory
13+
contents:
14+
- name: module.modulemap
15+
type: file
16+
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/android.modulemap"
17+
- name: SwiftAndroidNDK.h
18+
type: file
19+
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/SwiftAndroidNDK.h"
20+
- name: SwiftBionic.h
21+
type: file
22+
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/SwiftBionic.h"
23+
]]
24+
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)
25+
26+
add_library(SwiftAndroid INTERFACE)
27+
target_compile_options(SwiftAndroid INTERFACE
28+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc --sysroot=\"${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/sysroot\">"
29+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-vfsoverlay ${CMAKE_CURRENT_BINARY_DIR}/android-ndk-overlay.yaml>")
30+
31+
install(FILES
32+
android.modulemap
33+
SwiftAndroidNDK.h
34+
SwiftBionic.h
35+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${SwiftOverlay_PLATFORM_SUBDIR}/${SwiftOverlay_ARCH_SUBDIR})
36+
37+
install(FILES
38+
posix_filesystem.apinotes
39+
spawn.apinotes
40+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/apinotes)

Runtimes/Overlay/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ add_compile_options(
5050
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>")
5151

5252
add_subdirectory(clang)
53+
if(ANDROID)
54+
add_subdirectory(Android)
55+
endif()
5356
if(WIN32)
5457
add_subdirectory(Windows)
5558
endif()

Runtimes/Resync.cmake

+25-1
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,35 @@ copy_library_sources("linker-support" "" "Overlay")
104104
message(STATUS "Clang[${StdlibSources}/public/ClangOverlays] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/clang")
105105
copy_files(public/ClangOverlays Overlay/clang FILES float.swift.gyb)
106106

107+
# Android Overlay
108+
message(STATUS "Android modulemaps[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Android/clang")
109+
copy_files(public/Platform Overlay/Android/clang
110+
FILES
111+
android.modulemap
112+
posix_filesystem.apinotes
113+
spawn.apinotes
114+
SwiftAndroidNDK.h
115+
SwiftBionic.h)
116+
117+
message(STATUS "Android Android[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Android/Android")
118+
copy_files(public/Platform Overlay/Android/Android
119+
FILES
120+
Android.swift
121+
Platform.swift
122+
POSIXError.swift
123+
TiocConstants.swift
124+
tgmath.swift.gyb)
125+
126+
message(STATUS "Android Math[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Android/Math")
127+
copy_files(public/Platform Overlay/Android/Math
128+
FILES
129+
Math.swift)
130+
107131
# Windows Overlay
108132
message(STATUS "WinSDK[${StdlibSources}/public/Windows] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/WinSDK")
109133
copy_files(public/Windows Overlay/Windows/WinSDK FILES WinSDK.swift)
110134

111-
message(STATUS "Windows Modulemaps[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang")
135+
message(STATUS "Windows modulemaps[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang")
112136
copy_files(public/Platform Overlay/Windows/clang
113137
FILES
114138
ucrt.modulemap

0 commit comments

Comments
 (0)