Runtimes: add overlay for Android platform

This introduces the Android and Math modules for Android in the platform
specific overlay.
This commit is contained in:
Saleem Abdulrasool
2025-03-23 20:09:14 -07:00
parent 2c335eef5a
commit 4b376025ce
6 changed files with 114 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
gyb_expand(tgmath.swift.gyb tgmath.swift)
add_library(swiftAndroid
tgmath.swift
Android.swift
Platform.swift
POSIXError.swift
TiocConstants.swift)
set_target_properties(swiftAndroid PROPERTIES
Swift_MODULE_NAME Android)
target_compile_definitions(swiftAndroid PRIVATE
$<$<BOOL:${SwiftOverlay_ENABLE_REFLECTION}>:SWIFT_ENABLE_REFLECTION>)
target_link_libraries(swiftAndroid PRIVATE
SwiftAndroid
swiftCore)
install(TARGETS swiftAndroid
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
emit_swift_interface(swiftAndroid)
install_swift_interface(swiftAndroid)
embed_manifest(swiftAndroid)

View File

@@ -0,0 +1,4 @@
add_subdirectory(clang)
add_subdirectory(Android)
add_subdirectory(Math)

View File

@@ -0,0 +1,17 @@
add_library(swift_math
Math.swift)
set_target_properties(swift_math PROPERTIES
Swift_MODULE_NAME math)
target_link_libraries(swift_math PRIVATE
SwiftAndroid
swiftCore)
install(TARGETS swift_math
ARCHIVE DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${SwiftOverlay_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
emit_swift_interface(swift_math)
install_swift_interface(swift_math)
embed_manifest(swift_math)

View File

@@ -0,0 +1,40 @@
# FIXME: how do we determine the sysroot? `CMAKE_SYSROOT` does not contain the sysroot.
file(CONFIGURE
OUTPUT android-ndk-overlay.yaml
CONTENT [[
---
version: 0
case-sensitive: false
use-external-names: false
roots:
- name: "@CMAKE_ANDROID_NDK@/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include"
type: directory
contents:
- name: module.modulemap
type: file
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/android.modulemap"
- name: SwiftAndroidNDK.h
type: file
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/SwiftAndroidNDK.h"
- name: SwiftBionic.h
type: file
external-contents: "@CMAKE_CURRENT_SOURCE_DIR@/SwiftBionic.h"
]]
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)
add_library(SwiftAndroid INTERFACE)
target_compile_options(SwiftAndroid INTERFACE
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc --sysroot=\"${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/sysroot\">"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-vfsoverlay ${CMAKE_CURRENT_BINARY_DIR}/android-ndk-overlay.yaml>")
install(FILES
android.modulemap
SwiftAndroidNDK.h
SwiftBionic.h
DESTINATION ${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${SwiftOverlay_PLATFORM_SUBDIR}/${SwiftOverlay_ARCH_SUBDIR})
install(FILES
posix_filesystem.apinotes
spawn.apinotes
DESTINATION ${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/apinotes)

View File

@@ -50,6 +50,9 @@ add_compile_options(
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>")
add_subdirectory(clang)
if(ANDROID)
add_subdirectory(Android)
endif()
if(WIN32)
add_subdirectory(Windows)
endif()

View File

@@ -104,11 +104,35 @@ copy_library_sources("linker-support" "" "Overlay")
message(STATUS "Clang[${StdlibSources}/public/ClangOverlays] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/clang")
copy_files(public/ClangOverlays Overlay/clang FILES float.swift.gyb)
# Android Overlay
message(STATUS "Android modulemaps[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Android/clang")
copy_files(public/Platform Overlay/Android/clang
FILES
android.modulemap
posix_filesystem.apinotes
spawn.apinotes
SwiftAndroidNDK.h
SwiftBionic.h)
message(STATUS "Android Android[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Android/Android")
copy_files(public/Platform Overlay/Android/Android
FILES
Android.swift
Platform.swift
POSIXError.swift
TiocConstants.swift
tgmath.swift.gyb)
message(STATUS "Android Math[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Android/Math")
copy_files(public/Platform Overlay/Android/Math
FILES
Math.swift)
# Windows Overlay
message(STATUS "WinSDK[${StdlibSources}/public/Windows] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/WinSDK")
copy_files(public/Windows Overlay/Windows/WinSDK FILES WinSDK.swift)
message(STATUS "Windows Modulemaps[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang")
message(STATUS "Windows modulemaps[${StdlibSources}/Platform] -> ${CMAKE_CURRENT_LIST_DIR}/Overlay/Windows/clang")
copy_files(public/Platform Overlay/Windows/clang
FILES
ucrt.modulemap