Skip to content

Commit bf137cb

Browse files
committed
[android] Add more changes to build the compiler
1 parent ad30745 commit bf137cb

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
@@ -405,9 +405,9 @@ set(SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY
405405

406406

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

865865
if(SWIFT_BUILD_SWIFT_SYNTAX)
866866
# Only "HOSTTOOLS" is supported in Linux when Swift parser integration is enabled.
867-
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
867+
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
868868
message(WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled")
869869
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
870870
endif()
@@ -1194,6 +1194,7 @@ if(SWIFT_INCLUDE_TOOLS)
11941194
message(STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS}")
11951195
message(STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO}")
11961196
message(STATUS " Bootstrapping: ${BOOTSTRAPPING_MODE}")
1197+
message(STATUS " C++ Bridging: ${BRIDGING_MODE}")
11971198
message(STATUS " Swift parser: ${SWIFT_BUILD_SWIFT_SYNTAX}")
11981199
message(STATUS "")
11991200
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
@@ -607,6 +607,9 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
607607
endif()
608608
endif()
609609
endif()
610+
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND SWIFT_USE_LINKER STREQUAL "lld")
611+
target_link_options(${target} PRIVATE "SHELL:-Xlinker -z -Xlinker nostart-stop-gc")
612+
endif()
610613
endif()
611614
612615
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)