From a4b3c7d74adb9712028584bf333068274f8bb462 Mon Sep 17 00:00:00 2001 From: Amr Aboelela Date: Wed, 27 Sep 2017 10:44:48 -0700 Subject: [PATCH 1/4] Added build-android --- .gitignore | 3 + CoreFoundation/Base.subproj/CFPlatform.c | 2 + .../Base.subproj/ForSwiftFoundationOnly.h | 3 + CoreFoundation/URL.subproj/CFURL.c | 2 + Foundation/Host.swift | 19 +- Foundation/NSNotification.swift | 6 +- Foundation/Thread.swift | 8 + build-android | 179 ++++++++++++++++++ 8 files changed, 217 insertions(+), 5 deletions(-) create mode 100755 build-android diff --git a/.gitignore b/.gitignore index f050b65a5e..397209ba01 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ Build *.swp *.orig .arcconfig + +*.tgz +build.ninjae diff --git a/CoreFoundation/Base.subproj/CFPlatform.c b/CoreFoundation/Base.subproj/CFPlatform.c index 896193f662..ba2500455f 100644 --- a/CoreFoundation/Base.subproj/CFPlatform.c +++ b/CoreFoundation/Base.subproj/CFPlatform.c @@ -1325,10 +1325,12 @@ CF_SWIFT_EXPORT void _CFThreadSetName(const char *_Nullable name) { } CF_SWIFT_EXPORT int _CFThreadGetName(char *buf, int length) { +#if !TARGET_OS_ANDROID #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI return pthread_getname_np(pthread_self(), buf, length); #elif DEPLOYMENT_TARGET_LINUX return pthread_getname_np(pthread_self(), buf, length); +#endif #endif return -1; } diff --git a/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h b/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h index 2d208567ba..55c4a53f85 100644 --- a/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h +++ b/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h @@ -27,7 +27,10 @@ #include #include #include + +#if !TARGET_OS_ANDROID #include +#endif #if __has_include() #include diff --git a/CoreFoundation/URL.subproj/CFURL.c b/CoreFoundation/URL.subproj/CFURL.c index 191e713c04..13e40d9cf2 100644 --- a/CoreFoundation/URL.subproj/CFURL.c +++ b/CoreFoundation/URL.subproj/CFURL.c @@ -28,8 +28,10 @@ #if __has_include() #include #else +#if !TARGET_OS_ANDROID #include #endif +#endif #include #endif diff --git a/Foundation/Host.swift b/Foundation/Host.swift index 3c09f7c38f..c3384d30a4 100644 --- a/Foundation/Host.swift +++ b/Foundation/Host.swift @@ -28,6 +28,14 @@ open class Host: NSObject { internal var _names = [String]() internal var _addresses = [String]() + #if os(Android) + static internal let NI_MAXHOST = 1025 + internal let AI_PASSIVE: Int32 = 0x00000001 /* get address to use bind() */ + internal let AI_CANONNAME: Int32 = 0x00000002 /* fill ai_canonname */ + internal let AI_NUMERICHOST: Int32 = 0x00000004 /* prevent host name resolution */ + internal let AI_NUMERICSERV: Int32 = 0x00000008 /* prevent service name resolution */ + #endif + static internal let _current = Host(currentHostName(), .current) internal init(_ info: String?, _ type: ResolveType) { @@ -36,7 +44,7 @@ open class Host: NSObject { } static internal func currentHostName() -> String { - let hname = UnsafeMutablePointer.allocate(capacity: Int(NI_MAXHOST)) + let hname = UnsafeMutablePointer.allocate(capacity: Int(NI_MAXHOST)) defer { hname.deinitialize() hname.deallocate(capacity: Int(NI_MAXHOST)) @@ -65,6 +73,9 @@ open class Host: NSObject { } internal func _resolveCurrent() { + #if os(Android) + return + #else var ifaddr: UnsafeMutablePointer? = nil if getifaddrs(&ifaddr) != 0 { return @@ -88,9 +99,13 @@ open class Host: NSObject { } ifa = ifaValue.ifa_next } + #endif } internal func _resolve() { +#if os(Android) + return +#else if _resolved { return } @@ -148,7 +163,7 @@ open class Host: NSObject { res = info.ai_next } } - +#endif } open var name: String? { diff --git a/Foundation/NSNotification.swift b/Foundation/NSNotification.swift index b848d6d443..3926ee8a72 100644 --- a/Foundation/NSNotification.swift +++ b/Foundation/NSNotification.swift @@ -169,7 +169,7 @@ open class NotificationCenter: NSObject { } } - open func post(name aName: NSNotification.Name, object anObject: Any?, userInfo aUserInfo: [AnyHashable : Any]? = nil) { + open func post(name aName: Notification.Name, object anObject: Any?, userInfo aUserInfo: [AnyHashable : Any]? = nil) { let notification = Notification(name: aName, object: anObject, userInfo: aUserInfo) post(notification) } @@ -189,11 +189,11 @@ open class NotificationCenter: NSObject { } @available(*,obsoleted:4.0,renamed:"addObserver(forName:object:queue:using:)") - open func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, usingBlock block: @escaping (Notification) -> Void) -> NSObjectProtocol { + open func addObserver(forName name: Notification.Name?, object obj: Any?, queue: OperationQueue?, usingBlock block: @escaping (Notification) -> Void) -> NSObjectProtocol { return addObserver(forName: name, object: obj, queue: queue, using: block) } - open func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) -> NSObjectProtocol { + open func addObserver(forName name: Notification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) -> NSObjectProtocol { let object = NSObject() let newObserver = NSNotificationReceiver() diff --git a/Foundation/Thread.swift b/Foundation/Thread.swift index 402294da41..77daf5a123 100644 --- a/Foundation/Thread.swift +++ b/Foundation/Thread.swift @@ -256,7 +256,11 @@ open class Thread : NSObject { let maxSupportedStackDepth = 128; let addrs = UnsafeMutablePointer.allocate(capacity: maxSupportedStackDepth) defer { addrs.deallocate(capacity: maxSupportedStackDepth) } + #if os(Android) + let count = maxSupportedStackDepth + #else let count = backtrace(addrs, Int32(maxSupportedStackDepth)) + #endif let addressCount = max(0, min(Int(count), maxSupportedStackDepth)) return body(addrs, addressCount) } @@ -270,6 +274,9 @@ open class Thread : NSObject { } open class var callStackSymbols: [String] { + #if os(Android) + return [] + #else return backtraceAddresses({ (addrs, count) in var symbols: [String] = [] if let bs = backtrace_symbols(addrs, Int32(count)) { @@ -283,6 +290,7 @@ open class Thread : NSObject { } return symbols }) + #endif } } diff --git a/build-android b/build-android new file mode 100755 index 0000000000..c92253f0f5 --- /dev/null +++ b/build-android @@ -0,0 +1,179 @@ +#!/usr/bin/env bash +# +# build-android +# +# This source file is part of the Swift.org open source project +# +# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +# Licensed under Apache License v2.0 with Runtime Library Exception +# +# See https://swift.org/LICENSE.txt for license information +# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors + +cd "$(dirname $0)/.." || exit 1 +SWIFT_PATH=$PWD + +ANDROID_NDK_PATH="${ANDROID_NDK_PATH:?Please set the Android NDK path in the ANDROID_NDK_PATH environment variable}" +ANDROID_ICU_PATH=${SWIFT_PATH}/libiconv-libicu-android + +SWIFT_ANDROID_TOOLCHAIN_PATH="${SWIFT_PATH}/swift-android-toolchain" +SWIFT_ANDROID_BUILD_PATH="${SWIFT_PATH}/build/Ninja-ReleaseAssert" + +cd ${SWIFT_PATH}/swift-corelibs-foundation + +mkdir -p .build +cd .build + +ANDROID_STANDALONE_TOOLCHAIN=`realpath ./android-standalone-toolchain` +ANDROID_STANDALONE_SYSROOT=$ANDROID_STANDALONE_TOOLCHAIN/sysroot + +if [ ! -d android-standalone-toolchain ]; then + echo Creating Android standalone toolchain ... + $ANDROID_NDK_PATH/build/tools/make_standalone_toolchain.py --api 21 --arch arm --stl libc++ --install-dir $ANDROID_STANDALONE_TOOLCHAIN --force -v +fi +export PATH=$ANDROID_STANDALONE_TOOLCHAIN/bin:$PATH +export CC=$ANDROID_STANDALONE_TOOLCHAIN/bin/arm-linux-androideabi-clang +export CXX=$ANDROID_STANDALONE_TOOLCHAIN/bin/arm-linux-androideabi-clang++ +export AR=$ANDROID_STANDALONE_TOOLCHAIN/bin/arm-linux-androideabi-ar +export AS=$ANDROID_STANDALONE_TOOLCHAIN/bin/arm-linux-androideabi-as +export LD=$ANDROID_STANDALONE_TOOLCHAIN/bin/arm-linux-androideabi-ld +export RANLIB=$ANDROID_STANDALONE_TOOLCHAIN/bin/arm-linux-androideabi-ranlib +export NM=$ANDROID_STANDALONE_TOOLCHAIN/bin/arm-linux-androideabi-nm +export STRIP=$ANDROID_STANDALONE_TOOLCHAIN/bin/arm-linux-androideabi-strip +export CHOST=arm-linux-androideabi +export ARCH_FLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16" +export ARCH_LINK="-march=armv7-a -Wl,--fix-cortex-a8" +export CPPFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing " +export CXXFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -frtti -fexceptions -std=c++11 -Wno-error=unused-command-line-argument " +export CFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing " +export LDFLAGS=" ${ARCH_LINK} " + +if [ ! -d openssl-1.0.2l ]; then + wget https://www.openssl.org/source/openssl-1.0.2-latest.tar.gz + tar -xvf openssl-1.0.2-latest.tar.gz + rm openssl-1.0.2-latest.tar.gz +fi +if [ ! -f $ANDROID_STANDALONE_SYSROOT/usr/lib/libssl.a ]; then + pushd openssl-1.0.2l + # -mandroid option seems to be only for gcc compilers. It was causing troubles with clang + sed "s/-mandroid //g" Configure > Configure.new && chmod +x Configure.new + ./Configure.new android-armv7 no-asm no-shared zlib --static --with-zlib-include=$ANDROID_STANDALONE_SYSROOT/usr --with-zlib-lib=$ANDROID_STANDALONE_SYSROOT/usr --prefix=$ANDROID_STANDALONE_SYSROOT/usr --sysroot=$ANDROID_STANDALONE_SYSROOT + pushd crypto + make buildinf.h + popd + make depend build_crypto build_ssl -j 4 + # for some reason we have to call this again to make the install work correctly + make depend build_crypto build_ssl -j 4 + # This subproject is causing issues with install_sw target. We don't need the binaries. + rm -r apps + # Create fake empty files to complete installation succesfully + touch libcrypto.pc libssl.pc openssl.pc + make install_sw + popd +fi +if [ ! -d curl ]; then + git clone https://github.com/curl/curl.git +fi +if [ ! -f $ANDROID_STANDALONE_SYSROOT/usr/lib/libcurl.so ]; then + pushd curl + autoreconf -i + ./configure --host=arm-linux-androideabi --enable-shared --disable-static --disable-dependency-tracking --with-zlib=$ANDROID_STANDALONE_SYSROOT/usr --with-ssl=$ANDROID_STANDALONE_SYSROOT/usr --without-ca-bundle --without-ca-path --enable-ipv6 --enable-http --enable-ftp --disable-file --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smtp --disable-gopher --disable-sspi --disable-manual --target=arm-linux-androideabi --build=x86_64-unknown-linux-gnu --prefix=$ANDROID_STANDALONE_SYSROOT/usr + make + make install + popd +fi +if [ ! -d libxml2 ]; then + git clone git://git.gnome.org/libxml2 +fi +if [ ! -f $ANDROID_STANDALONE_SYSROOT/usr/lib/libxml2.so ]; then + pushd libxml2 + autoreconf -i + ./configure --with-sysroot=$ANDROID_STANDALONE_SYSROOT --with-zlib=$ANDROID_STANDALONE_SYSROOT/usr --prefix=$ANDROID_STANDALONE_SYSROOT/usr --host=$CHOST --without-lzma --disable-static --enable-shared --without-http --without-html --without-ftp + make libxml2.la + make install-libLTLIBRARIES + pushd include + make install + popd + popd +fi +if [ ! -f libFoundation.so ]; then + pushd $ANDROID_STANDALONE_SYSROOT + + # Move dispatch public and private headers to the directory foundation is expecting to get it + mkdir -p $ANDROID_STANDALONE_SYSROOT/usr/include/dispatch + cp $SWIFT_PATH/swift-corelibs-libdispatch/dispatch/*.h $ANDROID_STANDALONE_SYSROOT/usr/include/dispatch + cp $SWIFT_PATH/swift-corelibs-libdispatch/private/*.h $ANDROID_STANDALONE_SYSROOT/usr/include/dispatch + + # Build foundation + # Remove default foundation implementation and fetch the version with android support + + pushd $SWIFT_PATH + pushd swift-corelibs-foundation + # Libfoundation script is not completely prepared to handle cross compilation yet. + ln -s $SWIFT_ANDROID_BUILD_PATH/swift-linux-x86_64/lib/swift $ANDROID_STANDALONE_SYSROOT/usr/lib/ + cp $SWIFT_ANDROID_BUILD_PATH/swift-linux-x86_64/lib/swift/android/armv7/* $SWIFT_ANDROID_BUILD_PATH/swift-linux-x86_64/lib/swift/android/ + #cp $ANDROID_NDK_PATH/sysroot/usr/include/ifaddrs.h $ANDROID_NDK_PATH/platforms/android-21/arch-arm/usr/include/ + + # Search path for curl seems to be wrong in foundation + ln -s $ANDROID_STANDALONE_SYSROOT/usr/include/curl $ANDROID_STANDALONE_SYSROOT/usr/include/curl/curl + + ln -s $ANDROID_STANDALONE_SYSROOT/usr/include/libxml2/libxml $ANDROID_STANDALONE_SYSROOT/usr/include/libxml + + #SDKROOT=$ANDROID_STANDALONE_SYSROOT/usr \ + + env \ + SWIFTC="$SWIFT_ANDROID_BUILD_PATH/swift-linux-x86_64/bin/swiftc" \ + CLANG="$SWIFT_ANDROID_BUILD_PATH/llvm-linux-x86_64/bin/clang" \ + SWIFT="$SWIFT_ANDROID_BUILD_PATH/swift-linux-x86_64/bin/swift" \ + SDKROOT="$SWIFT_ANDROID_BUILD_PATH/swift-linux-x86_64" \ + BUILD_DIR="$SWIFT_ANDROID_BUILD_PATH/foundation-linux-x86_64" \ + DSTROOT="/" \ + PREFIX="/usr" \ + CFLAGS="-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH --sysroot=$ANDROID_NDK_PATH/platforms/android-21/arch-arm -I$ANDROID_ICU_PATH/armeabi-v7a/include -I${SDKROOT}/lib/swift -I$ANDROID_NDK_PATH/sources/android/support/include -I$ANDROID_STANDALONE_SYSROOT/usr/include -I$SWIFT_PATH/swift-corelibs-foundation/closure" \ + SWIFTCFLAGS="-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH -I$ANDROID_NDK_PATH/platforms/android-21/arch-arm/usr/include" \ + LDFLAGS="-fuse-ld=gold --sysroot=$ANDROID_NDK_PATH/platforms/android-21/arch-arm -L$ANDROID_NDK_PATH/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x -L$ANDROID_ICU_PATH/armeabi-v7a -L$ANDROID_STANDALONE_SYSROOT/usr/lib -ldispatch " \ + ./configure \ + Release \ + --target=armv7-none-linux-androideabi \ + --sysroot=$ANDROID_STANDALONE_SYSROOT \ + -DXCTEST_BUILD_DIR=$SWIFT_ANDROID_BUILD_PATH/xctest-linux-x86_64 \ + -DLIBDISPATCH_SOURCE_DIR=$SWIFT_PATH/swift-corelibs-libdispatch \ + -DLIBDISPATCH_BUILD_DIR=$SWIFT_PATH/swift-corelibs-libdispatch && + + # Prepend SYSROOT env variable to ninja.build script + # SYSROOT is not being passed from build.py / script.py to the ninja file yet + #echo "SYSROOT=$ANDROID_STANDALONE_SYSROOT" > build.ninja.new + #cat build.ninja >> build.ninja.new + #rm build.ninja + #mv build.ninja.new build.ninja + cp -r /usr/include/uuid $ANDROID_STANDALONE_SYSROOT/usr/include + sed -ie "s/-I.\/ -I\/usr\/include\/x86_64-linux-gnu -I\/usr\/include\/x86_64-linux-gnu -I\/usr\/include\/libxml2//" build.ninja + sed -ie "s/-licui18n/-licui18nswift/g" build.ninja + sed -ie "s/-licuuc/-licuucswift/g" build.ninja + sed -ie "s/-licudata/-licudataswift/g" build.ninja + + ninja || exit 1 + + # There's no installation script for foundation yet, so the installation needs to be done manually. + # Apparently the installation for the main script is in swift repo. + rsync -av $SWIFT_ANDROID_BUILD_PATH/foundation-linux-x86_64/Foundation/Foundation.swift* $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift/android/armv7/ + #cp $SWIFT_ANDROID_BUILD_PATH/foundation-linux-x86_64/Foundation/Foundation.swift* $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift/android/armv7 + #cp $SWIFT_ANDROID_BUILD_PATH/foundation-linux-x86_64/Foundation/libFoundation.so $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift/android/armv7 + + rsync -av $ANDROID_STANDALONE_SYSROOT/usr/lib/libxml2.* $ANDROID_STANDALONE_SYSROOT/usr/lib/libcurl.* $ANDROID_ICU_PATH/armeabi-v7a/libicu{uc,i18n,data}swift.so $ANDROID_NDK_PATH/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so $SWIFT_ANDROID_BUILD_PATH/foundation-linux-x86_64/Foundation/libFoundation.so $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift/android/armv7 + #for i in $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift/android/libicu*.so; do $ANDROID_NDK_PATH/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/strip $i; mv $i ${i/libicu/libscu}; done + #rpl -R -e libicu libscu $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift/android/lib*.so && + #rsync -av $SWIFT_ANDROID_BUILD_PATH/foundation-linux-x86_64/Foundation/usr/lib/swift/CoreFoundation $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift + + # Undo those nasty changes + #rm $SWIFT_ANDROID_BUILD_PATH/swift-linux-x86_64/lib/swift/linux/armv7 + + # prep install so it can be used to build foundation + #cp -r $ANDROID_STANDALONE_SYSROOT/usr/include/dispatch $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift + cp -r $SWIFT_PATH/swift-corelibs-foundation/.build/libxml2/include/libxml $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift + cp -r $SWIFT_PATH/swift-corelibs-foundation/.build/curl/include/curl $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift + popd + popd + + popd +fi From 814746cb534cc9b072c7a4d587ffdbb8eda955f1 Mon Sep 17 00:00:00 2001 From: Amr Aboelela Date: Wed, 27 Sep 2017 10:52:22 -0700 Subject: [PATCH 2/4] Cleanup --- .gitignore | 1 - Foundation/Host.swift | 6 +----- build-android | 23 ----------------------- 3 files changed, 1 insertion(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 397209ba01..7aaa88d5ca 100644 --- a/.gitignore +++ b/.gitignore @@ -21,5 +21,4 @@ Build *.orig .arcconfig -*.tgz build.ninjae diff --git a/Foundation/Host.swift b/Foundation/Host.swift index c3384d30a4..0d2f01e6f4 100644 --- a/Foundation/Host.swift +++ b/Foundation/Host.swift @@ -30,10 +30,6 @@ open class Host: NSObject { #if os(Android) static internal let NI_MAXHOST = 1025 - internal let AI_PASSIVE: Int32 = 0x00000001 /* get address to use bind() */ - internal let AI_CANONNAME: Int32 = 0x00000002 /* fill ai_canonname */ - internal let AI_NUMERICHOST: Int32 = 0x00000004 /* prevent host name resolution */ - internal let AI_NUMERICSERV: Int32 = 0x00000008 /* prevent service name resolution */ #endif static internal let _current = Host(currentHostName(), .current) @@ -44,7 +40,7 @@ open class Host: NSObject { } static internal func currentHostName() -> String { - let hname = UnsafeMutablePointer.allocate(capacity: Int(NI_MAXHOST)) + let hname = UnsafeMutablePointer.allocate(capacity: Int(NI_MAXHOST)) defer { hname.deinitialize() hname.deallocate(capacity: Int(NI_MAXHOST)) diff --git a/build-android b/build-android index c92253f0f5..61a2d967b2 100755 --- a/build-android +++ b/build-android @@ -104,23 +104,16 @@ if [ ! -f libFoundation.so ]; then cp $SWIFT_PATH/swift-corelibs-libdispatch/dispatch/*.h $ANDROID_STANDALONE_SYSROOT/usr/include/dispatch cp $SWIFT_PATH/swift-corelibs-libdispatch/private/*.h $ANDROID_STANDALONE_SYSROOT/usr/include/dispatch - # Build foundation - # Remove default foundation implementation and fetch the version with android support - pushd $SWIFT_PATH pushd swift-corelibs-foundation # Libfoundation script is not completely prepared to handle cross compilation yet. ln -s $SWIFT_ANDROID_BUILD_PATH/swift-linux-x86_64/lib/swift $ANDROID_STANDALONE_SYSROOT/usr/lib/ cp $SWIFT_ANDROID_BUILD_PATH/swift-linux-x86_64/lib/swift/android/armv7/* $SWIFT_ANDROID_BUILD_PATH/swift-linux-x86_64/lib/swift/android/ - #cp $ANDROID_NDK_PATH/sysroot/usr/include/ifaddrs.h $ANDROID_NDK_PATH/platforms/android-21/arch-arm/usr/include/ # Search path for curl seems to be wrong in foundation ln -s $ANDROID_STANDALONE_SYSROOT/usr/include/curl $ANDROID_STANDALONE_SYSROOT/usr/include/curl/curl - ln -s $ANDROID_STANDALONE_SYSROOT/usr/include/libxml2/libxml $ANDROID_STANDALONE_SYSROOT/usr/include/libxml - #SDKROOT=$ANDROID_STANDALONE_SYSROOT/usr \ - env \ SWIFTC="$SWIFT_ANDROID_BUILD_PATH/swift-linux-x86_64/bin/swiftc" \ CLANG="$SWIFT_ANDROID_BUILD_PATH/llvm-linux-x86_64/bin/clang" \ @@ -140,12 +133,6 @@ if [ ! -f libFoundation.so ]; then -DLIBDISPATCH_SOURCE_DIR=$SWIFT_PATH/swift-corelibs-libdispatch \ -DLIBDISPATCH_BUILD_DIR=$SWIFT_PATH/swift-corelibs-libdispatch && - # Prepend SYSROOT env variable to ninja.build script - # SYSROOT is not being passed from build.py / script.py to the ninja file yet - #echo "SYSROOT=$ANDROID_STANDALONE_SYSROOT" > build.ninja.new - #cat build.ninja >> build.ninja.new - #rm build.ninja - #mv build.ninja.new build.ninja cp -r /usr/include/uuid $ANDROID_STANDALONE_SYSROOT/usr/include sed -ie "s/-I.\/ -I\/usr\/include\/x86_64-linux-gnu -I\/usr\/include\/x86_64-linux-gnu -I\/usr\/include\/libxml2//" build.ninja sed -ie "s/-licui18n/-licui18nswift/g" build.ninja @@ -157,19 +144,9 @@ if [ ! -f libFoundation.so ]; then # There's no installation script for foundation yet, so the installation needs to be done manually. # Apparently the installation for the main script is in swift repo. rsync -av $SWIFT_ANDROID_BUILD_PATH/foundation-linux-x86_64/Foundation/Foundation.swift* $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift/android/armv7/ - #cp $SWIFT_ANDROID_BUILD_PATH/foundation-linux-x86_64/Foundation/Foundation.swift* $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift/android/armv7 - #cp $SWIFT_ANDROID_BUILD_PATH/foundation-linux-x86_64/Foundation/libFoundation.so $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift/android/armv7 - rsync -av $ANDROID_STANDALONE_SYSROOT/usr/lib/libxml2.* $ANDROID_STANDALONE_SYSROOT/usr/lib/libcurl.* $ANDROID_ICU_PATH/armeabi-v7a/libicu{uc,i18n,data}swift.so $ANDROID_NDK_PATH/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so $SWIFT_ANDROID_BUILD_PATH/foundation-linux-x86_64/Foundation/libFoundation.so $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift/android/armv7 - #for i in $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift/android/libicu*.so; do $ANDROID_NDK_PATH/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/strip $i; mv $i ${i/libicu/libscu}; done - #rpl -R -e libicu libscu $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift/android/lib*.so && - #rsync -av $SWIFT_ANDROID_BUILD_PATH/foundation-linux-x86_64/Foundation/usr/lib/swift/CoreFoundation $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift - - # Undo those nasty changes - #rm $SWIFT_ANDROID_BUILD_PATH/swift-linux-x86_64/lib/swift/linux/armv7 # prep install so it can be used to build foundation - #cp -r $ANDROID_STANDALONE_SYSROOT/usr/include/dispatch $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift cp -r $SWIFT_PATH/swift-corelibs-foundation/.build/libxml2/include/libxml $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift cp -r $SWIFT_PATH/swift-corelibs-foundation/.build/curl/include/curl $SWIFT_ANDROID_TOOLCHAIN_PATH/usr/lib/swift popd From 27d9a747f3c484b9a82e6912af44b2a728bfced9 Mon Sep 17 00:00:00 2001 From: Amr Aboelela Date: Wed, 27 Sep 2017 10:58:53 -0700 Subject: [PATCH 3/4] Reverted back NSNotification.swift --- Foundation/NSNotification.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Foundation/NSNotification.swift b/Foundation/NSNotification.swift index 3926ee8a72..b848d6d443 100644 --- a/Foundation/NSNotification.swift +++ b/Foundation/NSNotification.swift @@ -169,7 +169,7 @@ open class NotificationCenter: NSObject { } } - open func post(name aName: Notification.Name, object anObject: Any?, userInfo aUserInfo: [AnyHashable : Any]? = nil) { + open func post(name aName: NSNotification.Name, object anObject: Any?, userInfo aUserInfo: [AnyHashable : Any]? = nil) { let notification = Notification(name: aName, object: anObject, userInfo: aUserInfo) post(notification) } @@ -189,11 +189,11 @@ open class NotificationCenter: NSObject { } @available(*,obsoleted:4.0,renamed:"addObserver(forName:object:queue:using:)") - open func addObserver(forName name: Notification.Name?, object obj: Any?, queue: OperationQueue?, usingBlock block: @escaping (Notification) -> Void) -> NSObjectProtocol { + open func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, usingBlock block: @escaping (Notification) -> Void) -> NSObjectProtocol { return addObserver(forName: name, object: obj, queue: queue, using: block) } - open func addObserver(forName name: Notification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) -> NSObjectProtocol { + open func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) -> NSObjectProtocol { let object = NSObject() let newObserver = NSNotificationReceiver() From 1772e62cf0fe6ca41a9a6734910a01b28c32583a Mon Sep 17 00:00:00 2001 From: Amr Aboelela Date: Wed, 27 Sep 2017 11:50:21 -0700 Subject: [PATCH 4/4] small changes --- build-android | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build-android b/build-android index 61a2d967b2..f837e3de89 100755 --- a/build-android +++ b/build-android @@ -10,6 +10,8 @@ # See https://swift.org/LICENSE.txt for license information # See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +#set -e + cd "$(dirname $0)/.." || exit 1 SWIFT_PATH=$PWD @@ -78,7 +80,7 @@ if [ ! -f $ANDROID_STANDALONE_SYSROOT/usr/lib/libcurl.so ]; then pushd curl autoreconf -i ./configure --host=arm-linux-androideabi --enable-shared --disable-static --disable-dependency-tracking --with-zlib=$ANDROID_STANDALONE_SYSROOT/usr --with-ssl=$ANDROID_STANDALONE_SYSROOT/usr --without-ca-bundle --without-ca-path --enable-ipv6 --enable-http --enable-ftp --disable-file --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smtp --disable-gopher --disable-sspi --disable-manual --target=arm-linux-androideabi --build=x86_64-unknown-linux-gnu --prefix=$ANDROID_STANDALONE_SYSROOT/usr - make + make || exit 1 make install popd fi @@ -89,8 +91,8 @@ if [ ! -f $ANDROID_STANDALONE_SYSROOT/usr/lib/libxml2.so ]; then pushd libxml2 autoreconf -i ./configure --with-sysroot=$ANDROID_STANDALONE_SYSROOT --with-zlib=$ANDROID_STANDALONE_SYSROOT/usr --prefix=$ANDROID_STANDALONE_SYSROOT/usr --host=$CHOST --without-lzma --disable-static --enable-shared --without-http --without-html --without-ftp - make libxml2.la - make install-libLTLIBRARIES + make libxml2.la || exit 1 + make install-libLTLIBRARIES || exit 1 pushd include make install popd