Skip to content

Commit

Permalink
[android] Add more changes to build the compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
finagolfin committed Nov 6, 2023
1 parent ad30745 commit bf137cb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion SwiftCompilerSources/Sources/Basic/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<FILE>
#endif

public struct CFileStream: TextOutputStream {
var fp: UnsafeMutablePointer<FILE>
var fp: FILEPointer

public func write(_ string: String) {
fputs(string, fp)
Expand Down
3 changes: 3 additions & 0 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/Demangling/Errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 8 additions & 3 deletions lib/Driver/UnixToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/LLVMSupport/ErrorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf137cb

Please sign in to comment.