diff --git a/lib/ClangImporter/ClangIncludePaths.cpp b/lib/ClangImporter/ClangIncludePaths.cpp index f5183091bde37..f76fd229c549c 100644 --- a/lib/ClangImporter/ClangIncludePaths.cpp +++ b/lib/ClangImporter/ClangIncludePaths.cpp @@ -180,7 +180,7 @@ createClangArgs(const ASTContext &ctx, clang::driver::Driver &clangDriver) { static SmallVector, 2> getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName, - std::optional maybeHeaderFileName, + std::optional> maybeHeaderFileNames, const llvm::IntrusiveRefCntPtr &vfs) { const llvm::Triple &triple = ctx.LangOpts.Target; @@ -220,18 +220,20 @@ getLibcFileMapping(ASTContext &ctx, StringRef modulemapFileName, SmallVector, 2> vfsMappings{ {std::string(injectedModuleMapPath), std::string(actualModuleMapPath)}}; - if (maybeHeaderFileName) { - // TODO: remove the SwiftGlibc.h header and reference all Glibc headers - // directly from the modulemap. - Path actualHeaderPath = actualModuleMapPath; - llvm::sys::path::remove_filename(actualHeaderPath); - llvm::sys::path::append(actualHeaderPath, maybeHeaderFileName.value()); + if (maybeHeaderFileNames) { + for (const auto &filename : *maybeHeaderFileNames) { + // TODO: remove the SwiftGlibc.h header and reference all Glibc headers + // directly from the modulemap. + Path actualHeaderPath = actualModuleMapPath; + llvm::sys::path::remove_filename(actualHeaderPath); + llvm::sys::path::append(actualHeaderPath, filename); - Path injectedHeaderPath(libcDir); - llvm::sys::path::append(injectedHeaderPath, maybeHeaderFileName.value()); + Path injectedHeaderPath(libcDir); + llvm::sys::path::append(injectedHeaderPath, filename); - vfsMappings.push_back( - {std::string(injectedHeaderPath), std::string(actualHeaderPath)}); + vfsMappings.push_back( + {std::string(injectedHeaderPath), std::string(actualHeaderPath)}); + } } return vfsMappings; @@ -552,9 +554,14 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping( } else if (triple.isMusl()) { libcFileMapping = getLibcFileMapping(ctx, "musl.modulemap", StringRef("SwiftMusl.h"), vfs); + } else if (triple.isAndroid()) { + // Android uses the android-specific module map that overlays the NDK. + StringRef headerFiles[] = {"SwiftAndroidNDK.h", "SwiftBionic.h"}; + libcFileMapping = + getLibcFileMapping(ctx, "android.modulemap", headerFiles, vfs); } else if (triple.isOSGlibc() || triple.isOSOpenBSD() || - triple.isOSFreeBSD() || triple.isAndroid()) { - // Android/BSD/Linux Mappings + triple.isOSFreeBSD()) { + // BSD/Linux Mappings libcFileMapping = getLibcFileMapping(ctx, "glibc.modulemap", StringRef("SwiftGlibc.h"), vfs); diff --git a/stdlib/cmake/modules/AddSwiftStdlib.cmake b/stdlib/cmake/modules/AddSwiftStdlib.cmake index 863aba45041ca..497a5b7989879 100644 --- a/stdlib/cmake/modules/AddSwiftStdlib.cmake +++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake @@ -1761,6 +1761,9 @@ endfunction() # SWIFT_MODULE_DEPENDS_WASI # Swift modules this library depends on when built for WASI. # +# SWIFT_MODULE_DEPENDS_ANDROID +# Swift modules this library depends on when built for Android. +# # FRAMEWORK_DEPENDS # System frameworks this library depends on. # @@ -1923,6 +1926,7 @@ function(add_swift_target_library name) SWIFT_COMPILE_FLAGS_XROS SWIFT_COMPILE_FLAGS_LINUX SWIFT_MODULE_DEPENDS + SWIFT_MODULE_DEPENDS_ANDROID SWIFT_MODULE_DEPENDS_CYGWIN SWIFT_MODULE_DEPENDS_FREEBSD SWIFT_MODULE_DEPENDS_FREESTANDING @@ -2150,12 +2154,15 @@ function(add_swift_target_library name) elseif(sdk STREQUAL "OPENBSD") list(APPEND swiftlib_module_depends_flattened ${SWIFTLIB_SWIFT_MODULE_DEPENDS_OPENBSD}) - elseif(sdk STREQUAL "LINUX" OR sdk STREQUAL "ANDROID") + elseif(sdk STREQUAL "LINUX") list(APPEND swiftlib_module_depends_flattened ${SWIFTLIB_SWIFT_MODULE_DEPENDS_LINUX}) elseif(sdk STREQUAL "LINUX_STATIC") list(APPEND swiftlib_module_depends_flattened ${SWIFTLIB_SWIFT_MODULE_DEPENDS_LINUX_STATIC}) + elseif(sdk STREQUAL "ANDROID") + list(APPEND swiftlib_module_depends_flattened + ${SWIFTLIB_SWIFT_MODULE_DEPENDS_ANDROID}) elseif(sdk STREQUAL "CYGWIN") list(APPEND swiftlib_module_depends_flattened ${SWIFTLIB_SWIFT_MODULE_DEPENDS_CYGWIN}) @@ -2999,6 +3006,7 @@ function(add_swift_target_executable name) DEPENDS LINK_LIBRARIES SWIFT_MODULE_DEPENDS + SWIFT_MODULE_DEPENDS_ANDROID SWIFT_MODULE_DEPENDS_CYGWIN SWIFT_MODULE_DEPENDS_FREEBSD SWIFT_MODULE_DEPENDS_FREESTANDING @@ -3112,12 +3120,15 @@ function(add_swift_target_executable name) elseif(sdk STREQUAL "OPENBSD") list(APPEND swiftexe_module_depends_flattened ${SWIFTEXE_TARGET_SWIFT_MODULE_DEPENDS_OPENBSD}) - elseif(sdk STREQUAL "LINUX" OR sdk STREQUAL "ANDROID") + elseif(sdk STREQUAL "LINUX") list(APPEND swiftexe_module_depends_flattened ${SWIFTEXE_TARGET_SWIFT_MODULE_DEPENDS_LINUX}) elseif(sdk STREQUAL "LINUX_STATIC") list(APPEND swiftexe_module_depends_flattened ${SWIFTEXE_TARGET_SWIFT_MODULE_DEPENDS_LINUX_STATIC}) + elseif(sdk STREQUAL "ANDROID") + list(APPEND swiftexe_module_depends_flattened + ${SWIFTEXE_TARGET_SWIFT_MODULE_DEPENDS_ANDROID}) elseif(sdk STREQUAL "CYGWIN") list(APPEND swiftexe_module_depends_flattened ${SWIFTEXE_TARGET_SWIFT_MODULE_DEPENDS_CYGWIN}) diff --git a/stdlib/private/RuntimeUnittest/CMakeLists.txt b/stdlib/private/RuntimeUnittest/CMakeLists.txt index e23d3a155c869..992f90ad33d2a 100644 --- a/stdlib/private/RuntimeUnittest/CMakeLists.txt +++ b/stdlib/private/RuntimeUnittest/CMakeLists.txt @@ -8,6 +8,7 @@ add_swift_target_library(swiftRuntimeUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES ExclusivityTests.cpp SWIFT_MODULE_DEPENDS StdlibUnittest + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_FREEBSD Glibc SWIFT_MODULE_DEPENDS_OPENBSD Glibc diff --git a/stdlib/private/StdlibCollectionUnittest/CMakeLists.txt b/stdlib/private/StdlibCollectionUnittest/CMakeLists.txt index 12fc845a887ef..e063340a4e638 100644 --- a/stdlib/private/StdlibCollectionUnittest/CMakeLists.txt +++ b/stdlib/private/StdlibCollectionUnittest/CMakeLists.txt @@ -19,6 +19,7 @@ add_swift_target_library(swiftStdlibCollectionUnittest ${SWIFT_STDLIB_LIBRARY_BU WriteBackMutableSlice.swift SWIFT_MODULE_DEPENDS StdlibUnittest + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_FREEBSD Glibc SWIFT_MODULE_DEPENDS_OPENBSD Glibc diff --git a/stdlib/private/StdlibUnicodeUnittest/CMakeLists.txt b/stdlib/private/StdlibUnicodeUnittest/CMakeLists.txt index 6914812465a54..44920a8f62fa8 100644 --- a/stdlib/private/StdlibUnicodeUnittest/CMakeLists.txt +++ b/stdlib/private/StdlibUnicodeUnittest/CMakeLists.txt @@ -10,6 +10,7 @@ add_swift_target_library(swiftStdlibUnicodeUnittest ${SWIFT_STDLIB_LIBRARY_BUILD WordBreaking.swift SWIFT_MODULE_DEPENDS StdlibUnittest + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_FREEBSD Glibc SWIFT_MODULE_DEPENDS_OPENBSD Glibc diff --git a/stdlib/private/StdlibUnittest/CMakeLists.txt b/stdlib/private/StdlibUnittest/CMakeLists.txt index 711ee520376c0..dfcbb067d8ff7 100644 --- a/stdlib/private/StdlibUnittest/CMakeLists.txt +++ b/stdlib/private/StdlibUnittest/CMakeLists.txt @@ -62,6 +62,7 @@ add_swift_target_library(swiftStdlibUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} SWIFT_MODULE_DEPENDS_XROS ${swift_stdlib_unittest_darwin_dependencies} SWIFT_MODULE_DEPENDS_MACCATALYST ${swift_stdlib_unittest_darwin_dependencies} SWIFT_MODULE_DEPENDS_FREESTANDING "${SWIFT_FREESTANDING_TEST_DEPENDENCIES}" + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_FREEBSD Glibc SWIFT_MODULE_DEPENDS_OPENBSD Glibc diff --git a/stdlib/private/StdlibUnittest/RaceTest.swift b/stdlib/private/StdlibUnittest/RaceTest.swift index d3aab9cd252fd..0a94d4da05ffb 100644 --- a/stdlib/private/StdlibUnittest/RaceTest.swift +++ b/stdlib/private/StdlibUnittest/RaceTest.swift @@ -45,6 +45,8 @@ import Darwin import Glibc #elseif canImport(Musl) import Musl +#elseif canImport(Android) +import Android #elseif os(WASI) import WASILibc #elseif os(Windows) diff --git a/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift b/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift index 9b5ef8be2e81a..3afef278d4cd5 100644 --- a/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift +++ b/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift @@ -18,6 +18,8 @@ import Darwin import Glibc #elseif canImport(Musl) import Musl +#elseif canImport(Android) +import Android #elseif os(WASI) import WASILibc #elseif os(Windows) diff --git a/stdlib/private/StdlibUnittest/StdlibUnittest.swift b/stdlib/private/StdlibUnittest/StdlibUnittest.swift index 11e60e1dbad41..55171a7114414 100644 --- a/stdlib/private/StdlibUnittest/StdlibUnittest.swift +++ b/stdlib/private/StdlibUnittest/StdlibUnittest.swift @@ -24,6 +24,8 @@ import Darwin import Glibc #elseif canImport(Musl) import Musl +#elseif canImport(Android) +import Android #elseif os(WASI) import WASILibc #elseif os(Windows) diff --git a/stdlib/private/SwiftPrivate/CMakeLists.txt b/stdlib/private/SwiftPrivate/CMakeLists.txt index 480781284ebb7..1e0bbfea54e13 100644 --- a/stdlib/private/SwiftPrivate/CMakeLists.txt +++ b/stdlib/private/SwiftPrivate/CMakeLists.txt @@ -27,6 +27,7 @@ add_swift_target_library(swiftSwiftPrivate ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I SWIFT_MODULE_DEPENDS_WATCHOS ${swift_swiftprivate_darwin_depencencies} SWIFT_MODULE_DEPENDS_MACCATALYST ${swift_swiftprivate_darwin_depencencies} SWIFT_MODULE_DEPENDS_FREESTANDING "${SWIFT_FREESTANDING_TEST_DEPENDENCIES}" + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_LINUX_STATIC Musl SWIFT_MODULE_DEPENDS_FREEBSD Glibc diff --git a/stdlib/private/SwiftPrivate/IO.swift b/stdlib/private/SwiftPrivate/IO.swift index 9e0f3c5ddfe75..e8bf2c659fa0d 100644 --- a/stdlib/private/SwiftPrivate/IO.swift +++ b/stdlib/private/SwiftPrivate/IO.swift @@ -23,6 +23,8 @@ import Darwin import Glibc #elseif canImport(Musl) import Musl +#elseif canImport(Android) +import Android #elseif canImport(WASILibc) import WASILibc #endif diff --git a/stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt b/stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt index db317dcdf6882..927eae491caa5 100644 --- a/stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt +++ b/stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt @@ -38,6 +38,7 @@ add_swift_target_library(swiftSwiftPrivateLibcExtras ${SWIFT_STDLIB_LIBRARY_BUIL SWIFT_MODULE_DEPENDS_XROS ${swift_private_libc_extras_darwin_depencencies} SWIFT_MODULE_DEPENDS_MACCATALYST ${swift_private_libc_extras_darwin_depencencies} SWIFT_MODULE_DEPENDS_FREESTANDING "${SWIFT_FREESTANDING_TEST_DEPENDENCIES}" + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_LINUX_STATIC Musl SWIFT_MODULE_DEPENDS_FREEBSD Glibc diff --git a/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift b/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift index 47e8972a276c2..ad15200ac7518 100644 --- a/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift +++ b/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift @@ -17,6 +17,8 @@ import Darwin import Glibc #elseif canImport(Musl) import Musl +#elseif canImport(Android) +import Android #elseif os(WASI) import WASILibc #elseif os(Windows) diff --git a/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift b/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift index 146cc404931e2..27ee869f70609 100644 --- a/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift +++ b/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift @@ -17,6 +17,8 @@ import Darwin import Glibc #elseif canImport(Musl) import Musl +#elseif canImport(Android) +import Android #elseif os(WASI) import WASILibc #elseif os(Windows) diff --git a/stdlib/private/SwiftPrivateThreadExtras/CMakeLists.txt b/stdlib/private/SwiftPrivateThreadExtras/CMakeLists.txt index d0a791ad8a47f..4002af837db10 100644 --- a/stdlib/private/SwiftPrivateThreadExtras/CMakeLists.txt +++ b/stdlib/private/SwiftPrivateThreadExtras/CMakeLists.txt @@ -19,6 +19,7 @@ add_swift_target_library(swiftSwiftPrivateThreadExtras ${SWIFT_STDLIB_LIBRARY_BU SWIFT_MODULE_DEPENDS_XROS ${swift_private_thread_extras_darwin_depencencies} SWIFT_MODULE_DEPENDS_MACCATALYST ${swift_private_thread_extras_darwin_depencencies} SWIFT_MODULE_DEPENDS_FREESTANDING "${SWIFT_FREESTANDING_TEST_DEPENDENCIES}" + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_LINUX_STATIC Musl SWIFT_MODULE_DEPENDS_FREEBSD Glibc diff --git a/stdlib/private/SwiftPrivateThreadExtras/SwiftPrivateThreadExtras.swift b/stdlib/private/SwiftPrivateThreadExtras/SwiftPrivateThreadExtras.swift index 20d5cdf214087..4ddf17a803136 100644 --- a/stdlib/private/SwiftPrivateThreadExtras/SwiftPrivateThreadExtras.swift +++ b/stdlib/private/SwiftPrivateThreadExtras/SwiftPrivateThreadExtras.swift @@ -21,6 +21,8 @@ import Darwin import Glibc #elseif canImport(Musl) import Musl +#elseif canImport(Android) +import Android #elseif os(WASI) import WASILibc #elseif os(Windows) diff --git a/stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift b/stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift index 97a5439d9ed4d..e7c43bf02567f 100644 --- a/stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift +++ b/stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift @@ -16,6 +16,8 @@ import Darwin import Glibc #elseif canImport(Musl) import Musl +#elseif canImport(Android) +import Android #elseif os(WASI) import WASILibc #elseif os(Windows) diff --git a/stdlib/private/SwiftReflectionTest/CMakeLists.txt b/stdlib/private/SwiftReflectionTest/CMakeLists.txt index f28b657be7d30..8ad688393765e 100644 --- a/stdlib/private/SwiftReflectionTest/CMakeLists.txt +++ b/stdlib/private/SwiftReflectionTest/CMakeLists.txt @@ -14,6 +14,7 @@ if (SWIFT_INCLUDE_TESTS AND SWIFT_BUILD_DYNAMIC_STDLIB) SWIFT_MODULE_DEPENDS_TVOS ${swift_reflection_test_darwin_depencencies} SWIFT_MODULE_DEPENDS_WATCHOS ${swift_reflection_test_darwin_depencencies} SWIFT_MODULE_DEPENDS_XROS ${swift_reflection_test_darwin_depencencies} + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_LINUX_STATIC Musl SWIFT_MODULE_DEPENDS_FREEBSD Glibc diff --git a/stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift b/stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift index 44175a187da1b..041206cd4244e 100644 --- a/stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift +++ b/stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift @@ -131,6 +131,8 @@ import SwiftShims import Glibc #elseif canImport(Musl) import Musl +#elseif canImport(Android) +import Android #endif let rtldDefault: UnsafeMutableRawPointer? = nil diff --git a/stdlib/public/Concurrency/CMakeLists.txt b/stdlib/public/Concurrency/CMakeLists.txt index 20a9575f4f337..26186699534b1 100644 --- a/stdlib/public/Concurrency/CMakeLists.txt +++ b/stdlib/public/Concurrency/CMakeLists.txt @@ -151,6 +151,7 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I ${SWIFT_RUNTIME_CONCURRENCY_C_SOURCES} ${SWIFT_RUNTIME_CONCURRENCY_SWIFT_SOURCES} + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_FREEBSD Glibc SWIFT_MODULE_DEPENDS_OPENBSD Glibc diff --git a/stdlib/public/Cxx/std/CMakeLists.txt b/stdlib/public/Cxx/std/CMakeLists.txt index 85087204882ae..be5807902e877 100644 --- a/stdlib/public/Cxx/std/CMakeLists.txt +++ b/stdlib/public/Cxx/std/CMakeLists.txt @@ -45,6 +45,7 @@ add_swift_target_library(swiftCxxStdlib STATIC NO_LINK_NAME IS_STDLIB IS_SWIFT_O SWIFT_MODULE_DEPENDS_WATCHOS ${swift_cxxstdlib_darwin_dependencies} SWIFT_MODULE_DEPENDS_XROS ${swift_cxxstdlib_darwin_dependencies} SWIFT_MODULE_DEPENDS_MACCATALYST ${swift_cxxstdlib_darwin_dependencies} + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_COMPILE_FLAGS ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} -cxx-interoperability-mode=default @@ -56,7 +57,7 @@ add_swift_target_library(swiftCxxStdlib STATIC NO_LINK_NAME IS_STDLIB IS_SWIFT_O DEPLOYMENT_VERSION_OSX ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX} LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" - TARGET_SDKS ALL_APPLE_PLATFORMS LINUX WINDOWS + TARGET_SDKS ALL_APPLE_PLATFORMS LINUX WINDOWS ANDROID INSTALL_IN_COMPONENT compiler INSTALL_WITH_SHARED DEPENDS libstdcxx-modulemap libcxxshim_modulemap CxxStdlib-apinotes) diff --git a/stdlib/public/Differentiation/CMakeLists.txt b/stdlib/public/Differentiation/CMakeLists.txt index 64e0ec3ee15e8..16a296bbbe772 100644 --- a/stdlib/public/Differentiation/CMakeLists.txt +++ b/stdlib/public/Differentiation/CMakeLists.txt @@ -42,6 +42,7 @@ add_swift_target_library(swift_Differentiation ${SWIFT_STDLIB_LIBRARY_BUILD_TYPE SWIFT_MODULE_DEPENDS_TVOS ${swiftDifferentiationDarwinDependencies} SWIFT_MODULE_DEPENDS_WATCHOS ${swiftDifferentiationDarwinDependencies} SWIFT_MODULE_DEPENDS_XROS ${swiftDifferentiationDarwinDependencies} + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_LINUX_STATIC Musl SWIFT_MODULE_DEPENDS_FREEBSD Glibc diff --git a/stdlib/public/Differentiation/TgmathDerivatives.swift.gyb b/stdlib/public/Differentiation/TgmathDerivatives.swift.gyb index a517dade14502..52600d71be9ee 100644 --- a/stdlib/public/Differentiation/TgmathDerivatives.swift.gyb +++ b/stdlib/public/Differentiation/TgmathDerivatives.swift.gyb @@ -18,12 +18,14 @@ import Swift import Darwin.C.tgmath #elseif canImport(Musl) import Musl -#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) +#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Cygwin) || os(Haiku) import Glibc #elseif os(WASI) import WASILibc #elseif os(Windows) import CRT +#elseif canImport(Android) + import Android #else #error("Unsupported platform") #endif diff --git a/stdlib/public/Distributed/CMakeLists.txt b/stdlib/public/Distributed/CMakeLists.txt index 3a0dcb21d9832..5dbea7d12f822 100644 --- a/stdlib/public/Distributed/CMakeLists.txt +++ b/stdlib/public/Distributed/CMakeLists.txt @@ -34,6 +34,7 @@ add_swift_target_library(swiftDistributed ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS SWIFT_MODULE_DEPENDS_OSX ${swift_distributed_darwin_depencencies} SWIFT_MODULE_DEPENDS_TVOS ${swift_distributed_darwin_depencencies} SWIFT_MODULE_DEPENDS_WATCHOS ${swift_distributed_darwin_depencencies} + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_FREEBSD Glibc SWIFT_MODULE_DEPENDS_OPENBSD Glibc diff --git a/stdlib/public/Distributed/LocalTestingDistributedActorSystem.swift b/stdlib/public/Distributed/LocalTestingDistributedActorSystem.swift index 47e31d9019800..33c208bff38ea 100644 --- a/stdlib/public/Distributed/LocalTestingDistributedActorSystem.swift +++ b/stdlib/public/Distributed/LocalTestingDistributedActorSystem.swift @@ -18,6 +18,8 @@ import Darwin import Glibc #elseif canImport(Musl) import Musl +#elseif canImport(Android) +import Android #elseif os(Windows) import WinSDK #endif diff --git a/stdlib/public/Platform/Android.swift b/stdlib/public/Platform/Android.swift new file mode 100644 index 0000000000000..cb15c356a8d12 --- /dev/null +++ b/stdlib/public/Platform/Android.swift @@ -0,0 +1,13 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +@_exported import SwiftAndroid // Clang module diff --git a/stdlib/public/Platform/CMakeLists.txt b/stdlib/public/Platform/CMakeLists.txt index 31419b092c057..7e709923ffcd0 100644 --- a/stdlib/public/Platform/CMakeLists.txt +++ b/stdlib/public/Platform/CMakeLists.txt @@ -127,9 +127,9 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB) endforeach() endif() -set(swiftGlibc_target_sdks ANDROID CYGWIN FREEBSD OPENBSD LINUX HAIKU) +set(swiftGlibc_target_sdks CYGWIN FREEBSD OPENBSD LINUX HAIKU) if(SWIFT_FREESTANDING_FLAVOR STREQUAL "linux") - set(swiftGlibc_target_sdks ANDROID CYGWIN FREEBSD OPENBSD LINUX HAIKU FREESTANDING) + set(swiftGlibc_target_sdks CYGWIN FREEBSD OPENBSD LINUX HAIKU FREESTANDING) endif() add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY ${swift_platform_sources} @@ -273,12 +273,42 @@ add_custom_target(musl_modulemap DEPENDS ${musl_modulemap_target_list}) set_property(TARGET musl_modulemap PROPERTY FOLDER "Miscellaneous") add_dependencies(sdk-overlay musl_modulemap) +# Add a system 'math' module overlay, which applies only to platforms that +# have a top level '_math' module. +add_swift_target_library(swift_math ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY + Math.swift + + SWIFT_COMPILE_FLAGS + ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} + ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} + ${swift_platform_compile_flags} + LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" + TARGET_SDKS "ANDROID" + INSTALL_IN_COMPONENT sdk-overlay + DEPENDS android_modulemap) + +add_swift_target_library(swiftAndroid ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY + Android.swift + ${swift_platform_sources} + POSIXError.swift + + GYB_SOURCES + ${swift_platform_gyb_sources} + + SWIFT_COMPILE_FLAGS + ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} + ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} + ${swift_platform_compile_flags} + LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" + TARGET_SDKS "ANDROID" + INSTALL_IN_COMPONENT sdk-overlay + DEPENDS android_modulemap) + set(glibc_modulemap_target_list) foreach(sdk ${SWIFT_SDKS}) if(NOT "${sdk}" STREQUAL "LINUX" AND NOT "${sdk}" STREQUAL "FREEBSD" AND NOT "${sdk}" STREQUAL "OPENBSD" AND - NOT "${sdk}" STREQUAL "ANDROID" AND NOT "${sdk}" STREQUAL "CYGWIN" AND NOT "${sdk}" STREQUAL "HAIKU") continue() @@ -334,11 +364,9 @@ foreach(sdk ${SWIFT_SDKS}) ${copy_glibc_modulemap_header_static}) endif() - # If this SDK is a target for a non-native host, except if it's for Android - # with its own native sysroot, create a native modulemap without a sysroot - # prefix. This is the one we'll install instead. - if(NOT "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${arch}_PATH}" STREQUAL "/" AND - NOT (sdk STREQUAL "ANDROID" AND NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "")) + # If this SDK is a target for a non-native host, create a native modulemap + # without a sysroot prefix. This is the one we'll install instead. + if(NOT "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${arch}_PATH}" STREQUAL "/") set(glibc_sysroot_relative_modulemap_out "${module_dir}/sysroot-relative-modulemaps/glibc.modulemap") handle_gyb_source_single(glibc_modulemap_native_target @@ -376,6 +404,79 @@ add_custom_target(glibc_modulemap DEPENDS ${glibc_modulemap_target_list}) set_property(TARGET glibc_modulemap PROPERTY FOLDER "Miscellaneous") add_dependencies(sdk-overlay glibc_modulemap) +set(android_modulemap_target_list) +if("ANDROID" IN_LIST SWIFT_SDKS) + set(android_modulemap_source "android.modulemap") + set(android_ndk_header_source "SwiftAndroidNDK.h") + set(android_bionic_header_source "SwiftBionic.h") + + foreach(arch ${SWIFT_SDK_ANDROID_ARCHITECTURES}) + set(arch_subdir "${SWIFT_SDK_ANDROID_LIB_SUBDIR}/${arch}") + set(module_dir "${SWIFTLIB_DIR}/${arch_subdir}") + set(module_dir_static "${SWIFTSTATICLIB_DIR}/${arch_subdir}") + + add_custom_command_target( + copy_android_modulemap_resource + COMMAND + "${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir} ${module_dir_static} + COMMAND + "${CMAKE_COMMAND}" "-E" "copy_if_different" + "${CMAKE_CURRENT_SOURCE_DIR}/${android_modulemap_source}" ${module_dir} + COMMAND + "${CMAKE_COMMAND}" "-E" "copy_if_different" + "${CMAKE_CURRENT_SOURCE_DIR}/${android_modulemap_source}" ${module_dir_static} + OUTPUT ${module_dir}/${android_modulemap_source} ${module_dir_static}/${android_modulemap_source} + COMMENT "Copying Android modulemap to resource directories") + add_custom_command_target( + copy_android_ndk_header_resource + COMMAND + "${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir} ${module_dir_static} + COMMAND + "${CMAKE_COMMAND}" "-E" "copy_if_different" + "${CMAKE_CURRENT_SOURCE_DIR}/${android_ndk_header_source}" ${module_dir} + COMMAND + "${CMAKE_COMMAND}" "-E" "copy_if_different" + "${CMAKE_CURRENT_SOURCE_DIR}/${android_ndk_header_source}" ${module_dir_static} + OUTPUT ${module_dir}/${android_ndk_header_source} ${module_dir_static}/${android_ndk_header_source} + COMMENT "Copying Android NDK header to resource directories") + add_custom_command_target( + copy_android_bionic_header_resource + COMMAND + "${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir} ${module_dir_static} + COMMAND + "${CMAKE_COMMAND}" "-E" "copy_if_different" + "${CMAKE_CURRENT_SOURCE_DIR}/${android_bionic_header_source}" ${module_dir} + COMMAND + "${CMAKE_COMMAND}" "-E" "copy_if_different" + "${CMAKE_CURRENT_SOURCE_DIR}/${android_bionic_header_source}" ${module_dir_static} + OUTPUT ${module_dir}/${android_bionic_header_source} ${module_dir_static}/${android_bionic_header_source} + COMMENT "Copying Android NDK header to resource directories") + + add_dependencies(sdk-overlay ${copy_android_modulemap_resource} + ${copy_android_ndk_header_resource} + ${copy_android_bionic_header_resource}) + list(APPEND android_modulemap_target_list ${copy_android_modulemap_resource} + ${copy_android_ndk_header_resource} + ${copy_android_bionic_header_resource}) + + swift_install_in_component(FILES "${android_modulemap_source}" + "${android_ndk_header_source}" + "${android_bionic_header_source}" + DESTINATION "lib/swift/${arch_subdir}" + COMPONENT sdk-overlay) + if(SWIFT_BUILD_STATIC_STDLIB) + swift_install_in_component(FILES "${android_modulemap_source}" + "${android_ndk_header_source}" + "${android_bionic_header_source}" + DESTINATION "lib/swift_static/${arch_subdir}" + COMPONENT sdk-overlay) + endif() + endforeach() +endif() +add_custom_target(android_modulemap DEPENDS ${android_modulemap_target_list}) +set_property(TARGET android_modulemap PROPERTY FOLDER "Miscellaneous") +add_dependencies(sdk-overlay android_modulemap) + set(wasilibc_modulemap_target_list) if("WASI" IN_LIST SWIFT_SDKS) set(wasilibc_modulemap_source "wasi-libc.modulemap") diff --git a/stdlib/public/Platform/Math.swift b/stdlib/public/Platform/Math.swift new file mode 100644 index 0000000000000..545a6cca36a89 --- /dev/null +++ b/stdlib/public/Platform/Math.swift @@ -0,0 +1,17 @@ +@_exported import _math + +// Constants defined by +@available(swift, deprecated: 3.0, message: "Please use 'Double.pi' or '.pi' to get the value of correct type and avoid casting.") +public let M_PI = Double.pi + +@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 2' or '.pi / 2' to get the value of correct type and avoid casting.") +public let M_PI_2 = Double.pi / 2 + +@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 4' or '.pi / 4' to get the value of correct type and avoid casting.") +public let M_PI_4 = Double.pi / 4 + +@available(swift, deprecated: 3.0, message: "Please use '2.squareRoot()'.") +public let M_SQRT2 = 2.squareRoot() + +@available(swift, deprecated: 3.0, message: "Please use '0.5.squareRoot()'.") +public let M_SQRT1_2 = 0.5.squareRoot() diff --git a/stdlib/public/Platform/SwiftAndroidNDK.h b/stdlib/public/Platform/SwiftAndroidNDK.h new file mode 100644 index 0000000000000..325d4295b50e1 --- /dev/null +++ b/stdlib/public/Platform/SwiftAndroidNDK.h @@ -0,0 +1,156 @@ +//===--- SwiftAndroidNDK.h ------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +#ifndef SWIFT_ANDROID_NDK_MODULE +#define SWIFT_ANDROID_NDK_MODULE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __cplusplus +// The Android r26 NDK contains an old libc++ modulemap that requires C++23 +// for 'stdatomic', which can't be imported unless we're using C++23. Thus, +// import stdatomic from the NDK directly, bypassing the stdatomic from the libc++. +#pragma clang module import _stdatomic +#else +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// C headers that are included with the compiler. +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#endif // SWIFT_ANDROID_NDK_MODULE diff --git a/stdlib/public/Platform/SwiftBionic.h b/stdlib/public/Platform/SwiftBionic.h new file mode 100644 index 0000000000000..af4652d5ca7e6 --- /dev/null +++ b/stdlib/public/Platform/SwiftBionic.h @@ -0,0 +1,45 @@ +//===--- SwiftBionic.h ----------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +#ifndef SWIFT_BIONIC_MODULE +#define SWIFT_BIONIC_MODULE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef __cplusplus +// The Android r26 NDK contains an old libc++ modulemap that requires C++23 +// for 'stdatomic', which can't be imported unless we're using C++23. Thus, +// import stdatomic from the NDK directly, bypassing the stdatomic from the libc++. +#pragma clang module import _stdatomic +#else +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // SWIFT_BIONIC_MODULE diff --git a/stdlib/public/Platform/android.modulemap b/stdlib/public/Platform/android.modulemap new file mode 100644 index 0000000000000..78e7bda99767c --- /dev/null +++ b/stdlib/public/Platform/android.modulemap @@ -0,0 +1,687 @@ +//===--- android.modulemap ------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// +// The module map for the Android NDK. +// A portion of the modules in this file are prefixed +// with an underscore, to discourage users from importing them from +// Swift directly, as these modules might be overriden by the C++ stdlib. +// Instead, users should import 'Android' or another +// umbrella module that includes these headers. + +// The top level 'Android' module can be included from Swift. +module SwiftAndroid [system] { + header "SwiftAndroidNDK.h" + export * +} + +// The top level 'Bionic' module is the C standard library +// used in the Android NDK. +module Bionic [system] { + header "SwiftBionic.h" + export * +} + +// The individual modules for the Bionic C standard library used +// by the Android NDK. +module _assert [system] { + // 's use of NDEBUG requires textual inclusion. + textual header "assert.h" +} +module _complex [system] { + header "complex.h" + export * +} +module _ctype [system] { + header "ctype.h" + export * +} +module _errno [system] { + header "errno.h" + export * +} +module _fenv [system] { + header "fenv.h" + export * +} +// Use 'no_undeclared_includes' to avoid pulling in the libc++ headers. +// FIXME: this can be dropped once NDK's libc++ 'std' module is split +// into individual submodules. +module _inttypes [system] [no_undeclared_includes] { + header "inttypes.h" + export * + use _stdint + use _sys_cdefs +} +module _limits [system] { + header "limits.h" + export * + explicit module posix_limits { + header "bits/posix_limits.h" + export * + } +} +module _locale [system] { + header "locale.h" + export * +} +module _malloc [system] { + header "malloc.h" + export * +} +module _math [system] { + header "math.h" + export * + link "m" +} +module _setjmp [system] { + header "setjmp.h" + export * +} +module _signal [system] { + header "signal.h" + // The 'signal.h' header unfortunately has a circular include + // with 'sys/ucontext.h' and thus it must be part of this module. + header "sys/ucontext.h" + export * + explicit module bits_signaltypes { + header "bits/signal_types.h" + export * + } +} +module _stdatomic [system] { + header "stdatomic.h" + export * +} +module _stdint [system] { + header "stdint.h" + export * +} +module _stdio [system] { + header "stdio.h" + export * + explicit module stdio_ext { + header "stdio_ext.h" + export * + } +} +module _stdlib [system] { + header "stdlib.h" + export * +} +module _string [system] { + header "string.h" + export * +} +module _threads [system] { + header "threads.h" + export * + explicit module threads_inlines { + header "bits/threads_inlines.h" + export * + } +} +module _time [system] { + header "time.h" + export * + explicit module sys_time { + header "sys/time.h" + export * + } + explicit module sys_times { + header "sys/times.h" + export * + } +} +module _uchar [system] { + header "uchar.h" + export * +} +module _wchar [system] { + header "wchar.h" + export * + explicit module mbstate_t { + header "bits/mbstate_t.h" + export * + } +} + +// POSIX and another android NDK headers. +module alloca [system] { + header "alloca.h" + export * +} + +module ar [system] { + header "ar.h" + export * +} + +module cpio [system] { + header "cpio.h" + export * +} + +module posix_filesystem [system] { + // This module groups all file, paths and filesystem + // operations into one module. + explicit module dirent { + header "dirent.h" + export * + } + explicit module fcntl { + header "fcntl.h" + // Note: Do not re-export imported modules + // to prevent exporting constants from linux/stat.h . + } + explicit module fnmatch { + header "fnmatch.h" + export * + } + explicit module fts { + header "fts.h" + export * + } + explicit module ftw { + header "ftw.h" + export * + } + explicit module glob { + header "glob.h" + export * + } + explicit module mntent { + header "mntent.h" + export * + } + explicit module libgen { + header "libgen.h" + export * + } + explicit module nl_types { + header "nl_types.h" + export * + } + explicit module paths { + header "paths.h" + export * + } + explicit module poll { + header "poll.h" + export * + } + explicit module pwd { + header "pwd.h" + export * + } + explicit module utime { + header "utime.h" + export * + } + explicit module bits_ioctl { + header "bits/ioctl.h" + export * + } + explicit module linux_stat { + private header "linux/stat.h" + export * + } + explicit module sys_epoll { + header "sys/epoll.h" + export * + } + explicit module sys_eventfd { + header "sys/eventfd.h" + export * + } + explicit module sys_fcntl { + header "sys/fcntl.h" + export * + } + explicit module sys_file { + header "sys/file.h" + export * + } + explicit module sys_inotify { + header "sys/inotify.h" + export * + } + explicit module sys_ioctl { + header "sys/ioctl.h" + export * + } + explicit module sys_mount { + header "sys/mount.h" + export * + } + explicit module sys_sendfile { + header "sys/sendfile.h" + export * + } + explicit module sys_stat { + header "sys/stat.h" + // Note: Do not re-export imported modules + // to prevent exporting constants from linux/stat.h . + } + explicit module sys_statvfs { + header "sys/statvfs.h" + export * + } + explicit module sys_vfs { + header "sys/vfs.h" + export * + } + explicit module sys_uio { + header "sys/uio.h" + export * + } + explicit module sys_xattr { + header "sys/xattr.h" + export * + } +} + +module dl [system] { + // This module groups all dl* based operations + // into one module. + explicit module dlfcn { + header "dlfcn.h" + export * + } + explicit module link_ { + header "link.h" + export * + } +} + +module error [system] { + header "error.h" + export * + explicit module err { + header "err.h" + export * + } +} + +module execinfo [system] { + header "execinfo.h" + export * +} + +module features [system] { + header "features.h" + export * +} + +module getopt [system] { + header "getopt.h" + export * +} + +module grp [system] { + header "grp.h" + export * +} + +module iconv [system] { + header "iconv.h" + export * +} + +module inet [system] { + // This module groups headers related to inet + // and networking. + explicit module ifaddrs { + header "ifaddrs.h" + export * + } + explicit module netdb { + header "netdb.h" + export * + } + explicit module arpa_inet { + header "arpa/inet.h" + export * + } + explicit module net_if { + header "net/if.h" + export * + } + explicit module netinet_in { + header "netinet/in.h" + export * + } + explicit module netinet_in6 { + header "netinet/in6.h" + export * + } + explicit module netinet_tcp { + header "netinet/tcp.h" + export * + } + explicit module bits_ip_mreq_source { + header "bits/ip_mreq_source.h" + export * + } + explicit module bits_ip_msfilter { + header "bits/ip_msfilter.h" + export * + } + explicit module bits_in_addr { + header "bits/in_addr.h" + export * + } + explicit module linux_if { + header "linux/if.h" + export * + } + explicit module sys_socket { + header "sys/socket.h" + export * + } +} + +module jni [system] { + header "jni.h" + export * +} + +module langinfo [system] { + header "langinfo.h" + export * +} + +module pthread [system] { + header "pthread.h" + export * +} + +module pty [system] { + header "pty.h" + export * +} + +module regex [system] { + header "regex.h" + export * +} + +module resolv [system] { + header "resolv.h" + export * +} + +module sched [system] { + header "sched.h" + export * +} + +module search [system] { + header "search.h" + export * +} + +module semaphore [system] { + header "semaphore.h" + export * +} + +module spawn [system] { + header "spawn.h" + export * +} + +module strings [system] { + header "strings.h" + export * +} + +module sys [system] { + explicit module syscall { + header "syscall.h" + export * + } + explicit module sysexits { + header "sysexits.h" + export * + } + explicit module syslog { + header "syslog.h" + export * + } +} + +module tar [system] { + header "tar.h" + export * +} + +module termio [system] { + explicit module termio { + header "termio.h" + export * + } + explicit module termios { + header "termios.h" + export * + } +} + +module uconfig_local [system] { + header "uconfig_local.h" + export * +} + +module ucontext [system] { + header "ucontext.h" + export * +} + +module unistd [system] { + header "unistd.h" + export * + explicit module sys_unistd { + header "sys/unistd.h" + export * + } +} + +module utmp [system] { + explicit module utmp { + header "utmp.h" + export * + } + explicit module utmpx { + header "utmpx.h" + export * + } +} + +module wait [system] { + header "wait.h" + export * + explicit module sys_wait { + header "sys/wait.h" + export * + } +} + +module xlocale [system] { + header "xlocale.h" + export * +} + +// Additional modules in the 'android' subdirectory. +module android_defs [system] { + explicit module ndk_version { + header "android/ndk-version.h" + export * + } + explicit module versioning { + header "android/versioning.h" + export * + } +} + +module android_apis [system] { + explicit module asset_manager_jni { + header "android/asset_manager_jni.h" + export * + } + explicit module asset_manager { + header "android/asset_manager.h" + export * + } + explicit module log { + header "android/log.h" + export * + } + explicit module trace { + header "android/trace.h" + export * + } +} + +// Additional modules in the 'bits' subdirectory. +module _bits_sa_family_t [system] { + // Note: this module is not part of 'inet' + // to prevent a circular modular dependency. + header "bits/sa_family_t.h" + export * +} +module _bits_stdatomic [system] { + // Note: this module is not part of 'stdatomic' + // as it depends on libc++ and forcing it to + // be in the same module breaks that modularization + // chain. + header "bits/stdatomic.h" + export * +} + +// Additional modules in the 'linux' subdirectory. +module _linux_time [system] { + // Note: this module is not part of '_time' + // to prevent a circular modular dependency + // between linux_time and sys modules. + header "linux/time.h" + header "linux/time_types.h" + export * + explicit module bits_timespec { + header "bits/timespec.h" + export * + } +} + +// Additional modules in the 'sys' subdirectory. +module _sys_cdefs [system] { + header "sys/cdefs.h" + // Circular included header, so combine them + // into the same module. + header "android/api-level.h" + export * +} +module _sys_core [system] { + explicit module endian { + header "sys/endian.h" + export * + } + explicit module errno { + header "sys/errno.h" + export * + } + explicit module ifunc { + header "sys/ifunc.h" + export * + } + explicit module ipc { + header "sys/ipc.h" + export * + } + explicit module mman { + header "sys/mman.h" + export * + } + explicit module mman_common { + header "asm-generic/mman-common.h" + export * + } + explicit module msg { + header "sys/msg.h" + export * + } + explicit module random { + header "sys/random.h" + export * + } + explicit module resource { + header "sys/resource.h" + export * + } + explicit module sem { + header "sys/sem.h" + export * + } + explicit module shm { + header "sys/shm.h" + export * + } + explicit module un { + header "sys/un.h" + export * + } + explicit module utsname { + header "sys/utsname.h" + export * + } +} +module _sys_select [system] { + // Note: this module is not part of + // 'sys_core' to prevent circular dependency error. + header "sys/select.h" + export * +} +// Use 'no_undeclared_includes' to avoid pulling in the libc++ module. +// This module depends on 'stdint.h', which is defined in libc++. +// We can't import libc++ as that would cause circular dependency +// between libc++ and this module. Using 'no_undeclared_includes' +// ensures that we include 'stdint.h' from usr/include instead of libc++. +module _sys_types [system] [no_undeclared_includes] { + header "sys/types.h" + // The 'sys/types.h' header has a circular include + // with 'bits/pthread_types.h' and thus it must be in the same module. + header "bits/pthread_types.h" + export * + use _stdint + use _sys_cdefs + use _Builtin_stddef +} +// Use 'no_undeclared_includes' to avoid pulling in the libc++ module. +// This module depends on 'stdint.h', which is defined in libc++. +// We can't import libc++ as that would cause circular dependency +// between libc++ and this module. Using 'no_undeclared_includes' +// ensures that we include 'stdint.h' from usr/include instead of libc++. +module _sys_user [system] [no_undeclared_includes] { + header "sys/user.h" + export * + use _stdint + use _sys_cdefs + use _Builtin_stddef +} + +// Module for zlib headers. +module zlib [system] { + header "zlib.h" + explicit module zconf { + header "zconf.h" + export * + } + export * + link "z" +} diff --git a/stdlib/public/RegexBuilder/CMakeLists.txt b/stdlib/public/RegexBuilder/CMakeLists.txt index 8db5dae116602..117cb57ee7f60 100644 --- a/stdlib/public/RegexBuilder/CMakeLists.txt +++ b/stdlib/public/RegexBuilder/CMakeLists.txt @@ -27,6 +27,7 @@ message(STATUS "Using Experimental String Processing library for RegexBuilder ($ add_swift_target_library(swiftRegexBuilder ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB "${REGEX_BUILDER_SOURCES}" + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_FREEBSD Glibc SWIFT_MODULE_DEPENDS_OPENBSD Glibc diff --git a/stdlib/public/StringProcessing/CMakeLists.txt b/stdlib/public/StringProcessing/CMakeLists.txt index 408e019e46644..c767dcff59f42 100644 --- a/stdlib/public/StringProcessing/CMakeLists.txt +++ b/stdlib/public/StringProcessing/CMakeLists.txt @@ -41,6 +41,7 @@ message(STATUS "Using Experimental String Processing library for _StringProcessi add_swift_target_library(swift_StringProcessing ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB "${STRING_PROCESSING_SOURCES}" + SWIFT_MODULE_DEPENDS_ANDROID Android SWIFT_MODULE_DEPENDS_LINUX Glibc SWIFT_MODULE_DEPENDS_FREEBSD Glibc SWIFT_MODULE_DEPENDS_OPENBSD Glibc diff --git a/stdlib/public/Synchronization/CMakeLists.txt b/stdlib/public/Synchronization/CMakeLists.txt index e363916f4737f..88cc673522ad1 100644 --- a/stdlib/public/Synchronization/CMakeLists.txt +++ b/stdlib/public/Synchronization/CMakeLists.txt @@ -46,7 +46,7 @@ set(SWIFT_SYNCHRONIZATION_DARWIN_SOURCES Mutex/Mutex.swift ) -# Linux sources +# Linux and Android sources set(SWIFT_SYNCHRONIZATION_LINUX_SOURCES Mutex/LinuxImpl.swift @@ -115,6 +115,8 @@ add_swift_target_library(swiftSynchronization ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES ${SWIFT_SYNCHRONIZATION_DARWIN_DEPENDENCIES} SWIFT_MODULE_DEPENDS_LINUX Glibc + SWIFT_MODULE_DEPENDS_ANDROID + Android SWIFT_MODULE_DEPENDS_WINDOWS WinSDK diff --git a/stdlib/public/Synchronization/Mutex/LinuxImpl.swift b/stdlib/public/Synchronization/Mutex/LinuxImpl.swift index ffb05b4f45b31..23536b2345fd4 100644 --- a/stdlib/public/Synchronization/Mutex/LinuxImpl.swift +++ b/stdlib/public/Synchronization/Mutex/LinuxImpl.swift @@ -11,7 +11,11 @@ //===----------------------------------------------------------------------===// import _SynchronizationShims +#if canImport(Android) +import Android +#else import Glibc +#endif extension Atomic where Value == UInt32 { // This returns 'false' on success and 'true' on error. Check 'errno' for the diff --git a/stdlib/public/runtime/Paths.cpp b/stdlib/public/runtime/Paths.cpp index 131a24ed40502..174140238ba5d 100644 --- a/stdlib/public/runtime/Paths.cpp +++ b/stdlib/public/runtime/Paths.cpp @@ -49,6 +49,11 @@ #include #endif +#ifdef __linux__ +// Needed for 'readlink'. +#include +#endif + #include #include #include diff --git a/test/AutoDiff/SILOptimizer/vjp_and_pullback_inlining.swift b/test/AutoDiff/SILOptimizer/vjp_and_pullback_inlining.swift index 53ec00ddb5ad0..53a41255420f1 100644 --- a/test/AutoDiff/SILOptimizer/vjp_and_pullback_inlining.swift +++ b/test/AutoDiff/SILOptimizer/vjp_and_pullback_inlining.swift @@ -8,6 +8,8 @@ import _Differentiation #if canImport(Glibc) import Glibc +#elseif canImport(Android) +import Android #else import Foundation #endif diff --git a/test/AutoDiff/compiler_crashers_fixed/issue-56600-symbol-in-ir-file-not-tbd-file.swift b/test/AutoDiff/compiler_crashers_fixed/issue-56600-symbol-in-ir-file-not-tbd-file.swift index fe65a165c4f53..7a5e395dd6551 100644 --- a/test/AutoDiff/compiler_crashers_fixed/issue-56600-symbol-in-ir-file-not-tbd-file.swift +++ b/test/AutoDiff/compiler_crashers_fixed/issue-56600-symbol-in-ir-file-not-tbd-file.swift @@ -12,6 +12,8 @@ import _Differentiation import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT #else diff --git a/test/AutoDiff/stdlib/tgmath_derivatives.swift.gyb b/test/AutoDiff/stdlib/tgmath_derivatives.swift.gyb index 39535f5f1fb55..a4a81a6a28ac8 100644 --- a/test/AutoDiff/stdlib/tgmath_derivatives.swift.gyb +++ b/test/AutoDiff/stdlib/tgmath_derivatives.swift.gyb @@ -5,6 +5,8 @@ import Darwin.C.tgmath #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT #else diff --git a/test/AutoDiff/validation-test/custom_derivatives.swift b/test/AutoDiff/validation-test/custom_derivatives.swift index f28a233dd34b6..233c5819f40dd 100644 --- a/test/AutoDiff/validation-test/custom_derivatives.swift +++ b/test/AutoDiff/validation-test/custom_derivatives.swift @@ -6,6 +6,8 @@ import StdlibUnittest import Darwin.C #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT #else diff --git a/test/AutoDiff/validation-test/separate_tangent_type.swift b/test/AutoDiff/validation-test/separate_tangent_type.swift index 3770e240777e6..87796d5da6b5a 100644 --- a/test/AutoDiff/validation-test/separate_tangent_type.swift +++ b/test/AutoDiff/validation-test/separate_tangent_type.swift @@ -6,6 +6,8 @@ import StdlibUnittest import Darwin.C #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT #else diff --git a/test/ClangImporter/clang_builtins.swift b/test/ClangImporter/clang_builtins.swift index 4b73e96a45be1..24b83bcd6abd8 100644 --- a/test/ClangImporter/clang_builtins.swift +++ b/test/ClangImporter/clang_builtins.swift @@ -4,6 +4,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif os(WASI) import WASILibc #elseif os(Windows) diff --git a/test/Concurrency/Runtime/async.swift b/test/Concurrency/Runtime/async.swift index ad787c0d874ea..965819cbdf078 100644 --- a/test/Concurrency/Runtime/async.swift +++ b/test/Concurrency/Runtime/async.swift @@ -16,6 +16,8 @@ import StdlibUnittest import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #endif var asyncTests = TestSuite("Async") diff --git a/test/Concurrency/Runtime/async_task_locals_copy_to_sync.swift b/test/Concurrency/Runtime/async_task_locals_copy_to_sync.swift index c0f7bda2805d7..bdb37734d35c0 100644 --- a/test/Concurrency/Runtime/async_task_locals_copy_to_sync.swift +++ b/test/Concurrency/Runtime/async_task_locals_copy_to_sync.swift @@ -18,6 +18,8 @@ import Dispatch import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) +import Android #endif enum TL { diff --git a/test/Concurrency/Runtime/async_task_withUnsafeCurrentTask.swift b/test/Concurrency/Runtime/async_task_withUnsafeCurrentTask.swift index 8ac4ad2f1579e..d22049945b751 100644 --- a/test/Concurrency/Runtime/async_task_withUnsafeCurrentTask.swift +++ b/test/Concurrency/Runtime/async_task_withUnsafeCurrentTask.swift @@ -10,6 +10,8 @@ import Glibc #elseif os(Windows) import MSVCRT +#elseif canImport(Android) +import Android #else import Darwin #endif @@ -36,4 +38,4 @@ func test_withUnsafeCurrentTask() async { static func main() async { await test_withUnsafeCurrentTask() } -} \ No newline at end of file +} diff --git a/test/Concurrency/Runtime/cancellation_handler.swift b/test/Concurrency/Runtime/cancellation_handler.swift index ba221c8592687..3cefaa5134469 100644 --- a/test/Concurrency/Runtime/cancellation_handler.swift +++ b/test/Concurrency/Runtime/cancellation_handler.swift @@ -12,6 +12,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif canImport(WASILibc) import WASILibc #elseif os(Windows) diff --git a/test/Concurrency/Runtime/data_race_detection_crash.swift b/test/Concurrency/Runtime/data_race_detection_crash.swift index 47238ede23127..2ab3ec805aa46 100644 --- a/test/Concurrency/Runtime/data_race_detection_crash.swift +++ b/test/Concurrency/Runtime/data_race_detection_crash.swift @@ -24,6 +24,8 @@ import Dispatch import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) +import Android #endif @MainActor func onMainActor() { diff --git a/test/Concurrency/Runtime/data_race_detection_legacy_warning.swift b/test/Concurrency/Runtime/data_race_detection_legacy_warning.swift index dc891057d22f2..d7c270be925c4 100644 --- a/test/Concurrency/Runtime/data_race_detection_legacy_warning.swift +++ b/test/Concurrency/Runtime/data_race_detection_legacy_warning.swift @@ -25,6 +25,8 @@ import Dispatch import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) +import Android #endif @MainActor func onMainActor() { @@ -66,14 +68,14 @@ actor MyActor { struct Runner { static func main() async { print("Launching a main-actor task") - // CHECK: data race detected: @MainActor function at main/data_race_detection_legacy_warning.swift:30 was not called on the main thread + // CHECK: data race detected: @MainActor function at main/data_race_detection_legacy_warning.swift:32 was not called on the main thread launchFromMainThread() sleep(1) let actor = MyActor() let actorFn = await actor.getTaskOnMyActor() print("Launching an actor-instance task") - // CHECK: data race detected: actor-isolated function at main/data_race_detection_legacy_warning.swift:59 was not called on the same actor + // CHECK: data race detected: actor-isolated function at main/data_race_detection_legacy_warning.swift:61 was not called on the same actor launchTask(actorFn) sleep(1) diff --git a/test/Concurrency/Runtime/exclusivity.swift b/test/Concurrency/Runtime/exclusivity.swift index 7e07776900f35..6bd44273e6bb0 100644 --- a/test/Concurrency/Runtime/exclusivity.swift +++ b/test/Concurrency/Runtime/exclusivity.swift @@ -31,6 +31,8 @@ var global3: Int = 7 import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) +import Android #elseif canImport(CRT) import CRT #endif diff --git a/test/Concurrency/Runtime/exclusivity_custom_executors.swift b/test/Concurrency/Runtime/exclusivity_custom_executors.swift index 5e5d62fe495c1..f9f44d87aa6ec 100644 --- a/test/Concurrency/Runtime/exclusivity_custom_executors.swift +++ b/test/Concurrency/Runtime/exclusivity_custom_executors.swift @@ -26,6 +26,8 @@ import StdlibUnittest import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) +import Android #elseif canImport(CRT) import CRT #endif diff --git a/test/Concurrency/Runtime/executor_deinit3.swift b/test/Concurrency/Runtime/executor_deinit3.swift index 302ab4c67e91c..f6063c985157b 100644 --- a/test/Concurrency/Runtime/executor_deinit3.swift +++ b/test/Concurrency/Runtime/executor_deinit3.swift @@ -14,6 +14,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #endif @available(SwiftStdlib 5.1, *) diff --git a/test/Concurrency/async_task_base_priority.swift b/test/Concurrency/async_task_base_priority.swift index 76febb58c5887..763ef3ad14a14 100644 --- a/test/Concurrency/async_task_base_priority.swift +++ b/test/Concurrency/async_task_base_priority.swift @@ -21,6 +21,8 @@ import Dispatch import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) +import Android #elseif os(WASI) import WASILibc #elseif os(Windows) diff --git a/test/IRGen/builtin_math.swift b/test/IRGen/builtin_math.swift index 3426c1ee085c4..956b2e2e0c5b2 100644 --- a/test/IRGen/builtin_math.swift +++ b/test/IRGen/builtin_math.swift @@ -6,6 +6,8 @@ import Glibc #elseif os(WASI) import WASILibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT #else diff --git a/test/IRGen/sanitize_coverage.swift b/test/IRGen/sanitize_coverage.swift index af28df7424155..e7090acaab692 100644 --- a/test/IRGen/sanitize_coverage.swift +++ b/test/IRGen/sanitize_coverage.swift @@ -15,6 +15,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT #else diff --git a/test/Interop/Cxx/libc/include-glibc.swift b/test/Interop/Cxx/libc/include-libc.swift similarity index 58% rename from test/Interop/Cxx/libc/include-glibc.swift rename to test/Interop/Cxx/libc/include-libc.swift index 2d1dcdc6ea227..807e5681cc558 100644 --- a/test/Interop/Cxx/libc/include-glibc.swift +++ b/test/Interop/Cxx/libc/include-libc.swift @@ -3,12 +3,18 @@ // REQUIRES: executable_test // REQUIRES: OS=linux-gnu || OS=linux-android +#if canImport(Glibc) import Glibc +#elseif canImport(Android) +import Android +#else +#error ("unsupported platform") +#endif import StdlibUnittest -var GlibcTests = TestSuite("GlibcTests") +var LibcTests = TestSuite("LibcTests") -GlibcTests.test("abs") { +LibcTests.test("abs") { expectEqual(42, abs(-42)) } diff --git a/test/Interop/Cxx/stdlib/android-and-std-module.swift b/test/Interop/Cxx/stdlib/android-and-std-module.swift new file mode 100644 index 0000000000000..cff4db5e70ae8 --- /dev/null +++ b/test/Interop/Cxx/stdlib/android-and-std-module.swift @@ -0,0 +1,29 @@ +// RUN: %empty-directory(%t) +// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++14 -Xcc -fmodules-cache-path=%t +// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t +// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t + +// RUN: find %t | %FileCheck %s + +// RUN: %empty-directory(%t) + +// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB +// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB + +// REQUIRES: OS=linux-android + +import Android +import Bionic + +#if ADD_CXXSTDLIB +import CxxStdlib +#endif + +func test() { +#if ADD_CXXSTDLIB + let _ = std.string() +#endif +} + +// CHECK-DAG: Android{{.*}}.pcm +// CHECK-DAG: std{{.*}}.pcm diff --git a/test/Interpreter/dynamicReplacement_property_observer.swift b/test/Interpreter/dynamicReplacement_property_observer.swift index 9c3313e36c144..bbf47ecf410fe 100644 --- a/test/Interpreter/dynamicReplacement_property_observer.swift +++ b/test/Interpreter/dynamicReplacement_property_observer.swift @@ -17,6 +17,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT import WinSDK diff --git a/test/Interpreter/dynamic_replacement.swift b/test/Interpreter/dynamic_replacement.swift index 80f572e634fce..426532a1951d5 100644 --- a/test/Interpreter/dynamic_replacement.swift +++ b/test/Interpreter/dynamic_replacement.swift @@ -109,6 +109,8 @@ import StdlibUnittest import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT import WinSDK diff --git a/test/Interpreter/dynamic_replacement_chaining.swift b/test/Interpreter/dynamic_replacement_chaining.swift index bd5579ed88528..940a361072bd2 100644 --- a/test/Interpreter/dynamic_replacement_chaining.swift +++ b/test/Interpreter/dynamic_replacement_chaining.swift @@ -30,6 +30,8 @@ import StdlibUnittest import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT import WinSDK diff --git a/test/Interpreter/dynamic_replacement_without_previous_calls.swift b/test/Interpreter/dynamic_replacement_without_previous_calls.swift index a9dc7254d836a..233f52a6aa572 100644 --- a/test/Interpreter/dynamic_replacement_without_previous_calls.swift +++ b/test/Interpreter/dynamic_replacement_without_previous_calls.swift @@ -16,6 +16,8 @@ import StdlibUnittest import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT import WinSDK diff --git a/test/Prototypes/BigInt.swift b/test/Prototypes/BigInt.swift index 532f926bffb7b..ca7725cede255 100644 --- a/test/Prototypes/BigInt.swift +++ b/test/Prototypes/BigInt.swift @@ -22,6 +22,8 @@ import StdlibUnittest import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT #else diff --git a/test/SILOptimizer/c_string_optimization.swift b/test/SILOptimizer/c_string_optimization.swift index f859063c77d6d..2173bd0b4d122 100644 --- a/test/SILOptimizer/c_string_optimization.swift +++ b/test/SILOptimizer/c_string_optimization.swift @@ -10,6 +10,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT #else diff --git a/test/multifile/protocol-conformance-redundant.swift b/test/multifile/protocol-conformance-redundant.swift index f27a8a346b5d6..9a8814221e264 100644 --- a/test/multifile/protocol-conformance-redundant.swift +++ b/test/multifile/protocol-conformance-redundant.swift @@ -17,6 +17,8 @@ import StdlibUnittest import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) +import Android #else #error("Unsupported platform") #endif diff --git a/test/stdlib/FloatConstants.swift b/test/stdlib/FloatConstants.swift index 3ed928a9d8848..0067e7df79cb0 100644 --- a/test/stdlib/FloatConstants.swift +++ b/test/stdlib/FloatConstants.swift @@ -6,6 +6,8 @@ import Glibc #elseif os(WASI) import WASILibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT #else diff --git a/test/stdlib/MathConstants.swift b/test/stdlib/MathConstants.swift index 9cc0cd776a07f..bef16ab430d6b 100644 --- a/test/stdlib/MathConstants.swift +++ b/test/stdlib/MathConstants.swift @@ -6,6 +6,8 @@ import Glibc #elseif os(WASI) import WASILibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT #else diff --git a/test/stdlib/POSIX.swift b/test/stdlib/POSIX.swift index c60aa771c0000..42b9edb5f4123 100644 --- a/test/stdlib/POSIX.swift +++ b/test/stdlib/POSIX.swift @@ -9,6 +9,8 @@ import SwiftPrivateLibcExtras import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #else #error("Unsupported platform") #endif diff --git a/test/stdlib/PrintFloat.swift.gyb b/test/stdlib/PrintFloat.swift.gyb index 78d51cd67abae..5377a6d2b2467 100644 --- a/test/stdlib/PrintFloat.swift.gyb +++ b/test/stdlib/PrintFloat.swift.gyb @@ -19,6 +19,8 @@ import SwiftPrivateLibcExtras import Glibc #elseif os(WASI) import WASILibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT #else diff --git a/test/stdlib/Runtime.swift.gyb b/test/stdlib/Runtime.swift.gyb index c4f872f1961e7..6d5ef26e90559 100644 --- a/test/stdlib/Runtime.swift.gyb +++ b/test/stdlib/Runtime.swift.gyb @@ -17,6 +17,8 @@ import SwiftShims import Glibc #elseif os(WASI) import WASILibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT import WinSDK diff --git a/test/stdlib/VarArgs.swift b/test/stdlib/VarArgs.swift index 139f66c8bfb90..b3f65d0bd6b03 100644 --- a/test/stdlib/VarArgs.swift +++ b/test/stdlib/VarArgs.swift @@ -27,6 +27,9 @@ runAllTests() #elseif os(WASI) import WASILibc typealias CGFloat = Double +#elseif canImport(Android) + import Android + typealias CGFloat = Double #elseif os(Windows) import CRT #if arch(x86_64) || arch(arm64) diff --git a/test/stdlib/mmap.swift b/test/stdlib/mmap.swift index cf335bf81810f..2695875543911 100644 --- a/test/stdlib/mmap.swift +++ b/test/stdlib/mmap.swift @@ -8,6 +8,10 @@ import StdlibUnittest import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android + // MAP_FAILED is not available on android. + let MAP_FAILED = UnsafeMutableRawPointer(bitPattern: -1) #else #error("Unsupported platform") #endif diff --git a/test/stdlib/tgmath_optimized.swift b/test/stdlib/tgmath_optimized.swift index 1d6de6ba3b7ee..369a7e8ab1266 100644 --- a/test/stdlib/tgmath_optimized.swift +++ b/test/stdlib/tgmath_optimized.swift @@ -10,6 +10,8 @@ import Glibc #elseif os(WASI) import WASILibc +#elseif canImport(Android) + import Android #elseif os(Windows) import CRT #else diff --git a/validation-test/StdlibUnittest/ChildProcessShutdown/FailIfChildCrashesDuringShutdown.swift b/validation-test/StdlibUnittest/ChildProcessShutdown/FailIfChildCrashesDuringShutdown.swift index b596a2015b9b3..0408bc81bf5ee 100644 --- a/validation-test/StdlibUnittest/ChildProcessShutdown/FailIfChildCrashesDuringShutdown.swift +++ b/validation-test/StdlibUnittest/ChildProcessShutdown/FailIfChildCrashesDuringShutdown.swift @@ -10,6 +10,8 @@ import StdlibUnittest import Glibc #elseif os(Windows) import MSVCRT +#elseif canImport(Android) + import Android #else #error("Unsupported platform") #endif diff --git a/validation-test/StdlibUnittest/ChildProcessShutdown/FailIfChildExitsDuringShutdown.swift b/validation-test/StdlibUnittest/ChildProcessShutdown/FailIfChildExitsDuringShutdown.swift index 888274eb243d9..e024a0e070810 100644 --- a/validation-test/StdlibUnittest/ChildProcessShutdown/FailIfChildExitsDuringShutdown.swift +++ b/validation-test/StdlibUnittest/ChildProcessShutdown/FailIfChildExitsDuringShutdown.swift @@ -8,6 +8,8 @@ import StdlibUnittest import Glibc #elseif os(Windows) import MSVCRT +#elseif canImport(Android) + import Android #else #error("Unsupported platform") #endif diff --git a/validation-test/StdlibUnittest/ChildProcessShutdown/PassIfChildCrashedDuringTestExecution.swift b/validation-test/StdlibUnittest/ChildProcessShutdown/PassIfChildCrashedDuringTestExecution.swift index 77af5601fd0be..8687bde2c1843 100644 --- a/validation-test/StdlibUnittest/ChildProcessShutdown/PassIfChildCrashedDuringTestExecution.swift +++ b/validation-test/StdlibUnittest/ChildProcessShutdown/PassIfChildCrashedDuringTestExecution.swift @@ -8,6 +8,8 @@ import StdlibUnittest import Glibc #elseif os(Windows) import MSVCRT +#elseif canImport(Android) + import Android #else #error("Unsupported platform") #endif diff --git a/validation-test/StdlibUnittest/ChildProcessShutdown/RequireOwnProcess.swift b/validation-test/StdlibUnittest/ChildProcessShutdown/RequireOwnProcess.swift index 2bfa62c5252bd..a74e4a25165d8 100644 --- a/validation-test/StdlibUnittest/ChildProcessShutdown/RequireOwnProcess.swift +++ b/validation-test/StdlibUnittest/ChildProcessShutdown/RequireOwnProcess.swift @@ -8,6 +8,8 @@ import StdlibUnittest import Glibc #elseif os(Windows) import MSVCRT +#elseif canImport(Android) + import Android #else #error("Unsupported platform") #endif diff --git a/validation-test/StdlibUnittest/Stdin.swift b/validation-test/StdlibUnittest/Stdin.swift index 056a92c9ca04e..a6c144e56eabd 100644 --- a/validation-test/StdlibUnittest/Stdin.swift +++ b/validation-test/StdlibUnittest/Stdin.swift @@ -10,6 +10,8 @@ import StdlibUnittest import Glibc #elseif os(Windows) import MSVCRT +#elseif canImport(Android) + import Android #else #error("Unsupported platform") #endif diff --git a/validation-test/stdlib/Glibc.swift b/validation-test/stdlib/Glibc.swift index 70276d29e0b81..1b004367078a8 100644 --- a/validation-test/stdlib/Glibc.swift +++ b/validation-test/stdlib/Glibc.swift @@ -6,7 +6,7 @@ // UNSUPPORTED: OS=tvos // UNSUPPORTED: OS=watchos -// REQUIRES: OS=linux-gnu || OS=linux-androideabi || OS=linux-android +// REQUIRES: OS=linux-gnu import Swift import StdlibUnittest diff --git a/validation-test/stdlib/POSIXErrorCode.swift b/validation-test/stdlib/POSIXErrorCode.swift index 2d3a442cd125e..5f126a314ffcb 100644 --- a/validation-test/stdlib/POSIXErrorCode.swift +++ b/validation-test/stdlib/POSIXErrorCode.swift @@ -10,6 +10,8 @@ import StdlibUnittest import Darwin #elseif canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #else #error("Unsupported platform") #endif diff --git a/validation-test/stdlib/String.swift b/validation-test/stdlib/String.swift index 32de3fa68542c..cc2219af7e73f 100644 --- a/validation-test/stdlib/String.swift +++ b/validation-test/stdlib/String.swift @@ -1235,6 +1235,8 @@ StringTests.test("Conversions") { #if canImport(Glibc) import Glibc +#elseif canImport(Android) + import Android #endif StringTests.test("lowercased()") {