Skip to content

Runtimes: add overlay for Android platform #80262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Runtimes/Overlay/Android/Android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions Runtimes/Overlay/Android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

add_subdirectory(clang)
add_subdirectory(Android)
add_subdirectory(Math)
17 changes: 17 additions & 0 deletions Runtimes/Overlay/Android/Math/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
40 changes: 40 additions & 0 deletions Runtimes/Overlay/Android/clang/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions Runtimes/Overlay/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
26 changes: 25 additions & 1 deletion Runtimes/Resync.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down