diff --git a/CMakeLists.txt b/CMakeLists.txt index 81b71d4ea1f2f..ae0ebbce5d6bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -405,9 +405,9 @@ set(SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY if(BRIDGING_MODE STREQUAL "DEFAULT" OR NOT BRIDGING_MODE) - if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR (CMAKE_Swift_COMPILER AND CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.8)) + if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR "${SWIFT_HOST_VARIANT_SDK}" MATCHES "WINDOWS|ANDROID" OR (CMAKE_Swift_COMPILER AND CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.8)) # In debug builds, to workaround a problem with LLDB's `po` command (rdar://115770255). - # On windows to workaround a build problem. + # On Windows and Android, to workaround a build problem. # If the host Swift version is less than 5.8, use pure mode to workaround a C++ interop compiler crash. set(BRIDGING_MODE "PURE") else() @@ -864,7 +864,7 @@ endif() if(SWIFT_BUILD_SWIFT_SYNTAX) # Only "HOSTTOOLS" is supported in Linux when Swift parser integration is enabled. - if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS") + if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS") message(WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled") set(BOOTSTRAPPING_MODE "HOSTTOOLS") endif() @@ -1194,6 +1194,7 @@ if(SWIFT_INCLUDE_TOOLS) message(STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS}") message(STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO}") message(STATUS " Bootstrapping: ${BOOTSTRAPPING_MODE}") + message(STATUS " C++ Bridging: ${BRIDGING_MODE}") message(STATUS " Swift parser: ${SWIFT_BUILD_SWIFT_SYNTAX}") message(STATUS "") else() diff --git a/SwiftCompilerSources/Sources/Basic/Utils.swift b/SwiftCompilerSources/Sources/Basic/Utils.swift index 0ae2eaf3614cc..6e878309f9335 100644 --- a/SwiftCompilerSources/Sources/Basic/Utils.swift +++ b/SwiftCompilerSources/Sources/Basic/Utils.swift @@ -54,8 +54,14 @@ public extension NoReflectionChildren { public var standardError = CFileStream(fp: stderr) +#if os(Android) || canImport(Musl) + public typealias FILEPointer = OpaquePointer +#else + public typealias FILEPointer = UnsafeMutablePointer +#endif + public struct CFileStream: TextOutputStream { - var fp: UnsafeMutablePointer + var fp: FILEPointer public func write(_ string: String) { fputs(string, fp) diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index 2a86741180092..bc6563197d903 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -607,6 +607,9 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping) endif() endif() endif() + if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND SWIFT_USE_LINKER STREQUAL "lld") + target_link_options(${target} PRIVATE "SHELL:-Xlinker -z -Xlinker nostart-stop-gc") + endif() endif() set_property(TARGET ${target} PROPERTY BUILD_WITH_INSTALL_RPATH YES) diff --git a/lib/Demangling/Errors.cpp b/lib/Demangling/Errors.cpp index ee87fa81513c5..ef37e16976f47 100644 --- a/lib/Demangling/Errors.cpp +++ b/lib/Demangling/Errors.cpp @@ -103,7 +103,7 @@ static void reportNow(uint32_t flags, const char *message) { #endif #if SWIFT_STDLIB_HAS_ASL asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", message); -#elif defined(__ANDROID__) +#elif defined(__ANDROID__) && !defined(__TERMUX__) __android_log_print(ANDROID_LOG_FATAL, "SwiftDemangle", "%s", message); #endif } diff --git a/lib/Driver/UnixToolChains.cpp b/lib/Driver/UnixToolChains.cpp index a146f08b10893..f6856c17e1639 100644 --- a/lib/Driver/UnixToolChains.cpp +++ b/lib/Driver/UnixToolChains.cpp @@ -158,10 +158,15 @@ bool toolchains::GenericUnix::addRuntimeRPath(const llvm::Triple &T, // Honour the user's request to add a rpath to the binary. This defaults to // `true` on non-android and `false` on android since the library must be - // copied into the bundle. + // copied into the bundle. An exception is made for the Termux app as it + // builds and runs natively like a Unix environment on Android. +#if defined(__TERMUX__) + bool apply_rpath = true; +#else + bool apply_rpath = !T.isAndroid(); +#endif return Args.hasFlag(options::OPT_toolchain_stdlib_rpath, - options::OPT_no_toolchain_stdlib_rpath, - !T.isAndroid()); + options::OPT_no_toolchain_stdlib_rpath, apply_rpath); } ToolChain::InvocationInfo diff --git a/stdlib/public/LLVMSupport/ErrorHandling.cpp b/stdlib/public/LLVMSupport/ErrorHandling.cpp index 9112024282ad8..30cf8a85a397f 100644 --- a/stdlib/public/LLVMSupport/ErrorHandling.cpp +++ b/stdlib/public/LLVMSupport/ErrorHandling.cpp @@ -42,7 +42,7 @@ void error(const char *prefix, const char *msg, const char *file = nullptr, unsi #if SWIFT_STDLIB_HAS_ASL asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", buffer); -#elif defined(__ANDROID__) +#elif defined(__ANDROID__) && !defined(__TERMUX__) __android_log_print(ANDROID_LOG_FATAL, "SwiftRuntime", "%s", buffer); #elif defined(_WIN32) #define STDERR_FILENO 2