Skip to content

Rebase onto apple/swift master #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
72616f6
android: start adding a stub target in the build script; doesn't work…
zhuowei Dec 4, 2015
0eb0d8c
android: added target in CMakeLists - won't work since libicu is not …
zhuowei Dec 4, 2015
822581f
android: hardcode ICU path, add NDK to sysroot, started copying link/…
zhuowei Dec 6, 2015
cc95189
android: stub out some missing methods on Android, disable split dwar…
zhuowei Dec 6, 2015
8978c95
android: add path to libgcc; not working (we probably need real compi…
zhuowei Dec 7, 2015
be753ae
android: add log2 implementation from Android Support and mulodi4 fro…
zhuowei Dec 8, 2015
bff3b59
android: start working on bionic wrapper module; pass Bsymbolic to st…
zhuowei Dec 8, 2015
2aa6ce7
android: add Android to list of possible target OSes, stdlib now comp…
zhuowei Dec 9, 2015
eb8a8f4
android: load conformance data by reading /proc/self/maps, copy swift…
zhuowei Dec 10, 2015
b79d05c
android: detect NDK path from environmental variable, starting to fix…
zhuowei Dec 12, 2015
3a4a59d
android: load conformance tables in main executable properly; fixes #5
zhuowei Dec 15, 2015
1a2490b
android: add Lit config for executing tests on device
zhuowei Dec 18, 2015
86d0b5f
android: add unmodified posix_spawn implementation from FreeBSD for d…
zhuowei Dec 18, 2015
6d6a59b
android: add a modified FreeBSD posix_spawn
zhuowei Dec 18, 2015
1b61ae7
android: do not add rpaths when linking
zhuowei Dec 18, 2015
f88771a
android: Use Android bionic's arc4random_uniform (which isn't in head…
zhuowei Jan 7, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@ set(SWIFT_NATIVE_CLANG_TOOLS_PATH "" CACHE STRING
set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "" CACHE STRING
"Path to the directory that contains Swift tools that are executable on the build machine")

set(SWIFT_ANDROID_NDK_PATH "$ENV{ANDROID_NDK_HOME}" CACHE STRING
"Path to the directory that contains the Android NDK tools that are executable on the build machine")
# The following only works with the Ninja generator in CMake >= 3.0.
set(SWIFT_PARALLEL_COMPILE_JOBS "" CACHE STRING
"Define the maximum number of concurrent compilation jobs.")
if(SWIFT_PARALLEL_COMPILE_JOBS)
if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
else()
set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${SWIFT_PARALLEL_COMPILE_JOBS})
set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
endif()
endif()

set(SWIFT_PARALLEL_LINK_JOBS "1" CACHE STRING
"Define the maximum number of concurrent link jobs.")
if(SWIFT_PARALLEL_LINK_JOBS)
if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
else()
set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${SWIFT_PARALLEL_LINK_JOBS})
set(CMAKE_JOB_POOL_LINK link_job_pool)
endif()
endif()
#
# User-configurable Darwin-specific options.
#
Expand Down Expand Up @@ -391,9 +415,27 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")

# FIXME: This will not work while trying to cross-compile.
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
configure_sdk_unix(LINUX "Linux" "linux" "linux" "x86_64" "x86_64-unknown-linux-gnu")
set(SWIFT_HOST_VARIANT_ARCH "x86_64")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
set(swift_can_crosscompile_stdlib TRUE)

is_sdk_requested(LINUX swift_build_linux)
if(swift_build_linux)
configure_sdk_unix(LINUX "Linux" "linux" "linux" "x86_64" "x86_64-unknown-linux-gnu")
set(SWIFT_PRIMARY_VARIANT_SDK_default "LINUX")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64")
endif()

is_sdk_requested(ANDROID swift_build_android)
if(swift_build_android AND ${swift_can_crosscompile_stdlib})
if("${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
message(FATAL_ERROR "environmental variable ANDROID_NDK_HOME not set")
endif()
configure_sdk_unix(ANDROID "Android" "android" "android" "armv7" "armv7-none-linux-androideabi")
set(SWIFT_SDK_ANDROID_PATH "${SWIFT_ANDROID_NDK_PATH}/platforms/android-16/arch-arm")

set(SWIFT_PRIMARY_VARIANT_SDK_default "ANDROID")
set(SWIFT_PRIMARY_VARIANT_ARCH_default "armv7")
endif()
# FIXME: This only matches ARMv7l (by far the most common variant).
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l")
configure_sdk_unix(LINUX "Linux" "linux" "linux" "armv7" "armv7-unknown-linux-gnueabihf")
Expand Down
25 changes: 22 additions & 3 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ function(_add_variant_c_compile_link_flags
list(APPEND result
"-isysroot" "${SWIFT_SDK_${sdk}_PATH}")

if("${sdk}" STREQUAL "ANDROID")
list(APPEND result
"--sysroot=${SWIFT_SDK_${sdk}_PATH}")
endif()


if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
list(APPEND result
"-arch" "${arch}"
Expand Down Expand Up @@ -103,6 +109,12 @@ function(_add_variant_c_compile_flags
list(APPEND result "-DNDEBUG")
endif()

if("${sdk}" STREQUAL "ANDROID")
list(APPEND result
"-I${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libcxx/include"
"-I${SWIFT_ANDROID_NDK_PATH}/sources/android/support/include")
endif()

set("${result_var_name}" "${result}" PARENT_SCOPE)
endfunction()

Expand Down Expand Up @@ -159,9 +171,16 @@ function(_add_variant_link_flags
result)

if("${sdk}" STREQUAL "LINUX")
list(APPEND result "-lpthread" "-ldl")
list(APPEND result "-lpthread" "-ldl" "${BSD_LIBRARIES}")
elseif("${sdk}" STREQUAL "FREEBSD")
list(APPEND result "-lpthread")
elseif("${sdk}" STREQUAL "ANDROID")
list(APPEND result
"-Wl,-Bsymbolic"
"-ldl"
"-L${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.8"
"${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so"
"-L${CMAKE_SOURCE_DIR}/../libiconv-libicu-android/armeabi-v7a")
else()
list(APPEND result "-lobjc")
endif()
Expand Down Expand Up @@ -903,7 +922,7 @@ function(_add_swift_library_single target name)
set_target_properties("${target}"
PROPERTIES
INSTALL_NAME_DIR "${install_name_dir}")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND NOT "${SWIFTLIB_SINGLE_SDK}" STREQUAL "ANDROID")
set_target_properties("${target}"
PROPERTIES
INSTALL_RPATH "$ORIGIN:/usr/lib/swift/linux")
Expand Down Expand Up @@ -1062,7 +1081,7 @@ function(_add_swift_library_single target name)
# isn't the standard library. The standard library uses a
# linker script that isn't supported by the gold linker.
if(NOT SWIFTLIB_SINGLE_IS_STDLIB)
list(APPEND link_flags "-fuse-ld=gold")
list(APPEND link_flags "-fuse-ld=gold -Wl,--gdb-index")
endif()
endif()
endif()
Expand Down
5 changes: 5 additions & 0 deletions cmake/modules/FindICU.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Find libicu's libraries

# Android FIXME: ICU

include(FindPackageHandleStandardArgs)

find_package(PkgConfig)
Expand All @@ -24,6 +26,9 @@ foreach(MODULE ${ICU_FIND_COMPONENTS})
set(ICU_${MODULE}_LIBRARIES ${ICU_${MODULE}_LIBRARY})
endif()
endforeach()
message("FIXME Android: ICU")
set(ICU_I18N_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../icu/source/i18n")
set(ICU_UC_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../icu/source/common")

find_package_handle_standard_args(ICU DEFAULT_MSG ${ICU_REQUIRED})
mark_as_advanced(${ICU_REQUIRED})
5 changes: 4 additions & 1 deletion lib/Basic/LangOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const std::vector<std::string> LangOptions::SupportedOSBuildConfigArguments = {
"watchOS",
"iOS",
"Linux",
"FreeBSD"
"FreeBSD",
"Android"
};

const std::vector<std::string> LangOptions::SupportedArchBuildConfigArguments = {
Expand Down Expand Up @@ -97,6 +98,8 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
addTargetConfigOption("os", "watchOS");
else if (triple.isiOS())
addTargetConfigOption("os", "iOS");
else if (triple.isAndroid())
addTargetConfigOption("os", "Android");
else if (triple.isOSLinux())
addTargetConfigOption("os", "Linux");
else if (triple.isOSFreeBSD())
Expand Down
4 changes: 4 additions & 0 deletions lib/Basic/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
return "watchos";
}

if (triple.isAndroid()) {
return "android";
}

if (triple.isMacOSX())
return "macosx";

Expand Down
10 changes: 10 additions & 0 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,16 @@ void Driver::buildOutputInfo(const ToolChain &TC, const DerivedArgList &Args,
});
}
}
} else if (TC.getTriple().isAndroid()) {
const char* ndkhome = getenv("ANDROID_NDK_HOME");
if (!ndkhome) {
llvm::errs() <<
"ANDROID_NDK_HOME environmental variable not set; "
"won't be able to build Android programs. Please "
"set it to the path of the NDK\n";
} else {
OI.SDKPath = std::string(ndkhome) + "/platforms/android-16/arch-arm";
}
}

if (!OI.SDKPath.empty()) {
Expand Down
39 changes: 33 additions & 6 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,12 +1112,39 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
Arguments.push_back(context.Args.MakeArgString(LibProfile));
}

// FIXME: We probably shouldn't be adding an rpath here unless we know ahead
// of time the standard library won't be copied.
Arguments.push_back("-Xlinker");
Arguments.push_back("-rpath");
Arguments.push_back("-Xlinker");
Arguments.push_back(context.Args.MakeArgString(RuntimeLibPath));
if (getTriple().isAndroid()) {
// FIXME: Android: hard-coded paths to arm; needs to fix for arm64, x86
Arguments.push_back("-target");
Arguments.push_back("armv7-none-linux-androideabi");
//Arguments.push_back(context.Args.MakeArgString(getTriple().str()));

const char* ndkhome = getenv("ANDROID_NDK_HOME");
assert(ndkhome && "ANDROID_NDK_HOME needs to be set to NDK "
"install directory for linking");

auto libgccpath = Twine(ndkhome) + "/toolchains/"
"arm-linux-androideabi-4.8/prebuilt/linux-x86_64/"
"lib/gcc/arm-linux-androideabi/4.8";
Arguments.push_back("-L");
Arguments.push_back(context.Args.MakeArgString(libgccpath));

auto libcxxpath = Twine(ndkhome) + "/sources/"
"cxx-stl/llvm-libc++/libs/armeabi-v7a";
Arguments.push_back("-L");
Arguments.push_back(context.Args.MakeArgString(libcxxpath));

Arguments.push_back("-lgcc");
Arguments.push_back("-lc");
} else {
// rpaths are not supported on Android.

// FIXME: We probably shouldn't be adding an rpath here unless we know ahead
// of time the standard library won't be copied.
Arguments.push_back("-Xlinker");
Arguments.push_back("-rpath");
Arguments.push_back("-Xlinker");
Arguments.push_back(context.Args.MakeArgString(RuntimeLibPath));
}

// Always add the stdlib
Arguments.push_back("-lswiftCore");
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibUnittest/RaceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import SwiftPrivate
import SwiftPrivatePthreadExtras
#if os(OSX) || os(iOS)
import Darwin
#elseif os(Linux) || os(FreeBSD)
#elseif os(Linux) || os(FreeBSD) || os(Android)
import Glibc
#endif

Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/StdlibUnittest/StdlibCoreExtras.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import SwiftPrivate
import SwiftPrivateDarwinExtras
#if os(OSX) || os(iOS)
import Darwin
#elseif os(Linux) || os(FreeBSD)
#elseif os(Linux) || os(FreeBSD) || os(Android)
import Glibc
#endif

Expand Down
19 changes: 18 additions & 1 deletion stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import SwiftPrivateDarwinExtras

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD)
#elseif os(Linux) || os(FreeBSD) || os(Android)
import Glibc
#endif

Expand Down Expand Up @@ -1036,6 +1036,7 @@ public enum OSVersion : CustomStringConvertible {
case watchOSSimulator
case Linux
case FreeBSD
case Android

public var description: String {
switch self {
Expand All @@ -1057,6 +1058,8 @@ public enum OSVersion : CustomStringConvertible {
return "Linux"
case FreeBSD:
return "FreeBSD"
case Android:
return "Android"
}
}
}
Expand Down Expand Up @@ -1091,6 +1094,8 @@ func _getOSVersion() -> OSVersion {
return .Linux
#elseif os(FreeBSD)
return .FreeBSD
#elseif os(Android)
return .Android
#else
let productVersion = _stdlib_getSystemVersionPlistProperty("ProductVersion")!
let (major, minor, bugFix) = _parseDottedVersionTriple(productVersion)
Expand Down Expand Up @@ -1159,6 +1164,7 @@ public enum TestRunPredicate : CustomStringConvertible {
case watchOSSimulatorAny(/*reason:*/ String)

case LinuxAny(reason: String)
case AndroidAny(reason: String)

case FreeBSDAny(reason: String)

Expand Down Expand Up @@ -1232,6 +1238,9 @@ public enum TestRunPredicate : CustomStringConvertible {

case FreeBSDAny(reason: let reason):
return "FreeBSDAny(*, reason: \(reason))"

case AndroidAny(reason: let reason):
return "AndroidAny(*, reason: \(reason))"
}
}

Expand Down Expand Up @@ -1471,6 +1480,14 @@ public enum TestRunPredicate : CustomStringConvertible {
default:
return false
}

case AndroidAny:
switch _getRunningOSVersion() {
case .Android:
return true
default:
return false
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion stdlib/private/SwiftPrivateDarwinExtras/Subprocess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
import SwiftPrivate
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD)
#elseif os(Linux) || os(FreeBSD) || os(Android)
import Glibc
#endif

// FIXME: Android: prefix with swift_ in Android version

// swift_posix_spawn isn't available in the public watchOS SDK, we sneak by the
// unavailable attribute declaration here of the APIs that we need.

Expand Down Expand Up @@ -47,6 +49,7 @@ func swift_posix_spawn(
_ argv: UnsafePointer<UnsafeMutablePointer<Int8>>,
_ envp: UnsafePointer<UnsafeMutablePointer<Int8>>) -> CInt


/// Calls POSIX `pipe()`.
func posixPipe() -> (readFD: CInt, writeFD: CInt) {
var fds: [CInt] = [ -1, -1 ]
Expand Down Expand Up @@ -234,6 +237,8 @@ internal func _getEnviron() -> UnsafeMutablePointer<UnsafeMutablePointer<CChar>>
return _NSGetEnviron().memory
#elseif os(FreeBSD)
return environ;
#elseif os(Android)
return environ
#else
return __environ
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
import SwiftPrivate
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD)
#elseif os(Linux) || os(FreeBSD) || os(Android)
import Glibc
#endif

public func _stdlib_mkstemps(inout template: String, _ suffixlen: CInt) -> CInt {
#if os(Android)
preconditionFailure("mkstemps doesn't work on Android")
#else
var utf8 = template.nulTerminatedUTF8
let (fd, fileName) = utf8.withUnsafeMutableBufferPointer {
(utf8) -> (CInt, String) in
Expand All @@ -27,6 +30,7 @@ public func _stdlib_mkstemps(inout template: String, _ suffixlen: CInt) -> CInt
}
template = fileName
return fd
#endif
}

public var _stdlib_FD_SETSIZE: CInt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD)
#elseif os(Linux) || os(FreeBSD) || os(Android)
import Glibc
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
#elseif os(Linux) || os(FreeBSD)
#elseif os(Linux) || os(FreeBSD) || os(Android)
import Glibc
#endif

Expand Down
Loading