Skip to content

Commit 406d533

Browse files
authored
Merge pull request #69538 from finagolfin/android
[android] Add more changes to build the compiler
2 parents 35b3971 + bf137cb commit 406d533

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,9 @@ set(SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY
401401

402402

403403
if(BRIDGING_MODE STREQUAL "DEFAULT" OR NOT BRIDGING_MODE)
404-
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))
404+
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))
405405
# In debug builds, to workaround a problem with LLDB's `po` command (rdar://115770255).
406-
# On windows to workaround a build problem.
406+
# On Windows and Android, to workaround a build problem.
407407
# If the host Swift version is less than 5.8, use pure mode to workaround a C++ interop compiler crash.
408408
set(BRIDGING_MODE "PURE")
409409
else()
@@ -868,7 +868,7 @@ endif()
868868

869869
if(SWIFT_BUILD_SWIFT_SYNTAX)
870870
# Only "HOSTTOOLS" is supported in Linux when Swift parser integration is enabled.
871-
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
871+
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
872872
message(WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled")
873873
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
874874
endif()
@@ -1199,6 +1199,7 @@ if(SWIFT_INCLUDE_TOOLS)
11991199
message(STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS}")
12001200
message(STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO}")
12011201
message(STATUS " Bootstrapping: ${BOOTSTRAPPING_MODE}")
1202+
message(STATUS " C++ Bridging: ${BRIDGING_MODE}")
12021203
message(STATUS " Swift parser: ${SWIFT_BUILD_SWIFT_SYNTAX}")
12031204
message(STATUS "")
12041205
else()

SwiftCompilerSources/Sources/Basic/Utils.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@ public extension NoReflectionChildren {
5454

5555
public var standardError = CFileStream(fp: stderr)
5656

57+
#if os(Android) || canImport(Musl)
58+
public typealias FILEPointer = OpaquePointer
59+
#else
60+
public typealias FILEPointer = UnsafeMutablePointer<FILE>
61+
#endif
62+
5763
public struct CFileStream: TextOutputStream {
58-
var fp: UnsafeMutablePointer<FILE>
64+
var fp: FILEPointer
5965

6066
public func write(_ string: String) {
6167
fputs(string, fp)

cmake/modules/AddSwift.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,9 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
601601
endif()
602602
endif()
603603
endif()
604+
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND SWIFT_USE_LINKER STREQUAL "lld")
605+
target_link_options(${target} PRIVATE "SHELL:-Xlinker -z -Xlinker nostart-stop-gc")
606+
endif()
604607
endif()
605608
606609
set_property(TARGET ${target} PROPERTY BUILD_WITH_INSTALL_RPATH YES)

lib/Demangling/Errors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static void reportNow(uint32_t flags, const char *message) {
103103
#endif
104104
#if SWIFT_STDLIB_HAS_ASL
105105
asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", message);
106-
#elif defined(__ANDROID__)
106+
#elif defined(__ANDROID__) && !defined(__TERMUX__)
107107
__android_log_print(ANDROID_LOG_FATAL, "SwiftDemangle", "%s", message);
108108
#endif
109109
}

lib/Driver/UnixToolChains.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,15 @@ bool toolchains::GenericUnix::addRuntimeRPath(const llvm::Triple &T,
158158

159159
// Honour the user's request to add a rpath to the binary. This defaults to
160160
// `true` on non-android and `false` on android since the library must be
161-
// copied into the bundle.
161+
// copied into the bundle. An exception is made for the Termux app as it
162+
// builds and runs natively like a Unix environment on Android.
163+
#if defined(__TERMUX__)
164+
bool apply_rpath = true;
165+
#else
166+
bool apply_rpath = !T.isAndroid();
167+
#endif
162168
return Args.hasFlag(options::OPT_toolchain_stdlib_rpath,
163-
options::OPT_no_toolchain_stdlib_rpath,
164-
!T.isAndroid());
169+
options::OPT_no_toolchain_stdlib_rpath, apply_rpath);
165170
}
166171

167172
ToolChain::InvocationInfo

stdlib/public/LLVMSupport/ErrorHandling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void error(const char *prefix, const char *msg, const char *file = nullptr, unsi
4242

4343
#if SWIFT_STDLIB_HAS_ASL
4444
asl_log(nullptr, nullptr, ASL_LEVEL_ERR, "%s", buffer);
45-
#elif defined(__ANDROID__)
45+
#elif defined(__ANDROID__) && !defined(__TERMUX__)
4646
__android_log_print(ANDROID_LOG_FATAL, "SwiftRuntime", "%s", buffer);
4747
#elif defined(_WIN32)
4848
#define STDERR_FILENO 2

0 commit comments

Comments
 (0)