diff --git a/.rubocop.yml b/.rubocop.yml index 45906546..bda40660 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -68,6 +68,12 @@ Layout/EmptyLinesAroundClassBody: Layout/IndentationWidth: Width: 3 +Layout/IndentHeredoc: + Enabled: false + +Metrics/BlockLength: + Enabled: false + Naming/VariableName: EnforcedStyle: camelCase diff --git a/Patches/swift-corelibs-foundation/CFKnownLocations.patch b/Patches/swift-corelibs-foundation/CFKnownLocations.patch new file mode 100644 index 00000000..381e8fd8 --- /dev/null +++ b/Patches/swift-corelibs-foundation/CFKnownLocations.patch @@ -0,0 +1,13 @@ +diff --git a/CoreFoundation/Base.subproj/CFKnownLocations.c b/CoreFoundation/Base.subproj/CFKnownLocations.c +index c610813fdcc4ec0d0d43ba50c42f329534925fce..b2bc4550f42edffdeb6003eb35929cb43234b653 100644 +--- a/CoreFoundation/Base.subproj/CFKnownLocations.c ++++ b/CoreFoundation/Base.subproj/CFKnownLocations.c +@@ -45,7 +45,7 @@ CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUs + } + + } +-#elif !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !DEPLOYMENT_TARGET_ANDROID ++#elif !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS + + /* + Building for an OS that uses the FHS, BSD's hier(7), and/or the XDG specification for paths: diff --git a/Patches/swift-corelibs-foundation/CMakeLists.patch b/Patches/swift-corelibs-foundation/CMakeLists.patch new file mode 100644 index 00000000..e5440bdf --- /dev/null +++ b/Patches/swift-corelibs-foundation/CMakeLists.patch @@ -0,0 +1,21 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index ff47064da305032b285037bbcd6846bed15c027c..28f63dabaee5234e177ff113beb425b413e8bdfe 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -19,7 +19,7 @@ option(FOUNDATION_PATH_TO_XCTEST_BUILD "Path to XCTest build" "") + find_package(CURL REQUIRED) + find_package(ICU COMPONENTS uc i18n REQUIRED) + find_package(LibXml2 REQUIRED) +-find_package(UUID REQUIRED) ++# find_package(UUID REQUIRED) + + include(SwiftSupport) + include(GNUInstallDirs) +@@ -45,6 +45,7 @@ ExternalProject_Add(CoreFoundation + -DCF_PATH_TO_LIBDISPATCH_SOURCE=${FOUNDATION_PATH_TO_LIBDISPATCH_SOURCE} + -DCF_PATH_TO_LIBDISPATCH_BUILD=${FOUNDATION_PATH_TO_LIBDISPATCH_BUILD} + -DICU_INCLUDE_DIR=${ICU_INCLUDE_DIR} ++ -DICU_LIBRARY=${ICU_LIBRARY} + -DLIBXML2_LIBRARY=${LIBXML2_LIBRARY} + -DLIBXML2_INCLUDE_DIR=${LIBXML2_INCLUDE_DIR} + -DCURL_LIBRARY=${CURL_LIBRARY} diff --git a/Patches/swift-corelibs-foundation/CmakeSystemProcessor.patch b/Patches/swift-corelibs-foundation/CmakeSystemProcessor.patch new file mode 100644 index 00000000..2a0436f0 --- /dev/null +++ b/Patches/swift-corelibs-foundation/CmakeSystemProcessor.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake +index 52e9af116fe94769fb9b3fedd3e846968dafb59a..bff1dc2db57b1971d4e9f20080a3113eb367c02c 100644 +--- a/cmake/modules/SwiftSupport.cmake ++++ b/cmake/modules/SwiftSupport.cmake +@@ -237,6 +237,8 @@ function(get_swift_host_arch result_var_name) + set("${result_var_name}" "armv6" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l") + set("${result_var_name}" "armv7" PARENT_SCOPE) ++ elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a") ++ set("${result_var_name}" "armv7" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64") + set("${result_var_name}" "x86_64" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64") diff --git a/Patches/swift-corelibs-foundation/CompileOptions.patch b/Patches/swift-corelibs-foundation/CompileOptions.patch new file mode 100644 index 00000000..784fd9ce --- /dev/null +++ b/Patches/swift-corelibs-foundation/CompileOptions.patch @@ -0,0 +1,25 @@ +diff --git a/CoreFoundation/CMakeLists.txt b/CoreFoundation/CMakeLists.txt +index 0aa9565e3c3930e7375cc548870003c1b8432653..643e53a03e36477d71e3b0339f337a01e868c72b 100644 +--- a/CoreFoundation/CMakeLists.txt ++++ b/CoreFoundation/CMakeLists.txt +@@ -194,6 +194,7 @@ add_framework(CoreFoundation + URL.subproj/CFURLAccess.h + URL.subproj/CFURLComponents.h + SOURCES ++ ../uuid/uuid.c + # Base + Base.subproj/CFBase.c + Base.subproj/CFFileUtilities.c +@@ -405,9 +406,9 @@ if(CF_DEPLOYMENT_SWIFT) + PRIVATE + /clang:-fcf-runtime-abi=swift) + else() +- target_compile_options(CoreFoundation +- PRIVATE +- -fcf-runtime-abi=swift) ++ # target_compile_options(CoreFoundation ++ # PRIVATE ++ # -fcf-runtime-abi=swift) + endif() + endif() + diff --git a/Patches/swift-corelibs-foundation/FileManager.patch b/Patches/swift-corelibs-foundation/FileManager.patch new file mode 100644 index 00000000..da5453fb --- /dev/null +++ b/Patches/swift-corelibs-foundation/FileManager.patch @@ -0,0 +1,75 @@ +diff --git a/Foundation/FileManager.swift b/Foundation/FileManager.swift +index c51536246fc92efd82115c2217b256466b234712..a537ae8e676f4e5326d8cd4aae38a2e312b42faf 100644 +--- a/Foundation/FileManager.swift ++++ b/Foundation/FileManager.swift +@@ -91,7 +91,10 @@ open class FileManager : NSObject { + urls = mountPoints(statBuf, Int(fsCount)) + } + #else ++/* FIXME: Android compile Workaround. + #error("Requires a platform-specific implementation") ++*/ ++ urls = [] // FIXME: Android compile Workaround. + #endif + return urls + } +@@ -581,6 +584,7 @@ open class FileManager : NSObject { + var entry = dirent() + var result: UnsafeMutablePointer? = nil + ++ /* FIXME: Android compile Workaround. + while readdir_r(dir, &entry, &result) == 0 { + guard result != nil else { + return +@@ -595,6 +599,7 @@ open class FileManager : NSObject { + try closure(entryName, entryType) + } + } ++ */ + } + + /** +@@ -651,6 +656,8 @@ open class FileManager : NSObject { + This method replaces fileAttributesAtPath:traverseLink:. + */ + open func attributesOfItem(atPath path: String) throws -> [FileAttributeKey : Any] { ++ return [:] ++ /* FIXME: Android compile Workaround. + let s = try _lstatFile(atPath: path) + var result = [FileAttributeKey : Any]() + result[.size] = NSNumber(value: UInt64(s.st_size)) +@@ -698,6 +705,7 @@ open class FileManager : NSObject { + result[.groupOwnerAccountID] = NSNumber(value: UInt64(s.st_gid)) + + return result ++ */ + } + + /* attributesOfFileSystemForPath:error: returns an NSDictionary of key/value pairs containing the attributes of the filesystem containing the provided path. If this method returns 'nil', an NSError will be returned by reference in the 'error' parameter. This method does not traverse a terminal symlink. +@@ -880,6 +888,7 @@ open class FileManager : NSObject { + return + } + ++ /* FIXME: Android compile Workaround. + let fileType = FileAttributeType(statMode: stat.st_mode) + if fileType == .typeDirectory { + try createDirectory(atPath: dstPath, withIntermediateDirectories: false, attributes: nil) +@@ -903,6 +912,7 @@ open class FileManager : NSObject { + } else { + try body(srcPath, dstPath, fileType) + } ++ */ + } + + private func shouldProceedAfterError(_ error: Error, copyingItemAtPath path: String, toPath: String, isURL: Bool) -> Bool { +@@ -1413,8 +1423,10 @@ open class FileManager : NSObject { + + if file1Type == S_IFCHR || file1Type == S_IFBLK { + // For character devices, just check the major/minor pair is the same. ++ /* FIXME: Android compile Workaround. + return _dev_major(file1.st_rdev) == _dev_major(file2.st_rdev) + && _dev_minor(file1.st_rdev) == _dev_minor(file2.st_rdev) ++ */ + } + + // If both paths point to the same device/inode or they are both zero length diff --git a/Patches/swift-corelibs-foundation/ForSwiftFoundationOnly.patch b/Patches/swift-corelibs-foundation/ForSwiftFoundationOnly.patch new file mode 100644 index 00000000..3c64507c --- /dev/null +++ b/Patches/swift-corelibs-foundation/ForSwiftFoundationOnly.patch @@ -0,0 +1,13 @@ +diff --git a/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h b/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h +index 034dc502d839aafcab6c9f69e42e725ef02059d4..3950c48a2cacf16d0e5f6df64da98dd1684cfd0e 100644 +--- a/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h ++++ b/CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h +@@ -44,7 +44,7 @@ + + #include + +-#if __has_include() ++#if __has_include() && !DEPLOYMENT_TARGET_ANDROID + #include + #endif + diff --git a/Patches/swift-corelibs-foundation/NSGeometry.patch b/Patches/swift-corelibs-foundation/NSGeometry.patch new file mode 100644 index 00000000..a094948d --- /dev/null +++ b/Patches/swift-corelibs-foundation/NSGeometry.patch @@ -0,0 +1,19 @@ +diff --git a/Foundation/NSGeometry.swift b/Foundation/NSGeometry.swift +index da860ff8b580483f27748cc98e8bfac3a1b2b4b8..4b26672dd07eab50ef83be0178572dab3381a447 100644 +--- a/Foundation/NSGeometry.swift ++++ b/Foundation/NSGeometry.swift +@@ -682,10 +682,10 @@ public func NSEdgeInsetsEqual(_ aInsets: NSEdgeInsets, _ bInsets: NSEdgeInsets) + } + + public func NSInsetRect(_ aRect: NSRect, _ dX: CGFloat, _ dY: CGFloat) -> NSRect { +- let x = aRect.origin.x.native + dX.native +- let y = aRect.origin.y.native + dY.native +- let w = aRect.size.width.native - (dX.native * 2) +- let h = aRect.size.height.native - (dY.native * 2) ++ let x = CGFloat(aRect.origin.x.native + dX.native) ++ let y = CGFloat(aRect.origin.y.native + dY.native) ++ let w = CGFloat(aRect.size.width.native - (dX.native * 2)) ++ let h = CGFloat(aRect.size.height.native - (dY.native * 2)) + return NSRect(x: x, y: y, width: w, height: h) + } + diff --git a/Patches/swift-corelibs-foundation/Readme.txt b/Patches/swift-corelibs-foundation/Readme.txt index 3cf5f5f2..401924bb 100644 --- a/Patches/swift-corelibs-foundation/Readme.txt +++ b/Patches/swift-corelibs-foundation/Readme.txt @@ -1 +1 @@ -Bugreport: https://bugs.swift.org/browse/SR-9513 \ No newline at end of file +MissedLocaleHeaders - Bugreport: https://bugs.swift.org/browse/SR-9513 \ No newline at end of file diff --git a/Patches/swift-corelibs-foundation/plutil.patch b/Patches/swift-corelibs-foundation/plutil.patch new file mode 100644 index 00000000..75f3bdaf --- /dev/null +++ b/Patches/swift-corelibs-foundation/plutil.patch @@ -0,0 +1,13 @@ +diff --git a/Tools/plutil/main.swift b/Tools/plutil/main.swift +index 9c3b81602242a85f09bbb3163eb5edde5d72168b..d5a5800dcb8d6914f358300674a44a2f741b522f 100644 +--- a/Tools/plutil/main.swift ++++ b/Tools/plutil/main.swift +@@ -9,7 +9,7 @@ + #if os(macOS) || os(iOS) + import Darwin + import SwiftFoundation +-#elseif os(Linux) ++#elseif os(Linux) || os(Android) + import Foundation + import Glibc + #endif diff --git a/Patches/swift-corelibs-foundation/uuid.h.patch b/Patches/swift-corelibs-foundation/uuid.h.patch new file mode 100644 index 00000000..d92bf570 --- /dev/null +++ b/Patches/swift-corelibs-foundation/uuid.h.patch @@ -0,0 +1,13 @@ +diff --git a/uuid/uuid.h b/uuid/uuid.h +index cc997a855b5484ff33a2cfc87698308d6829dca5..a23eb95eaf383738da5d225c2cee0de7fb325e38 100644 +--- a/uuid/uuid.h ++++ b/uuid/uuid.h +@@ -33,7 +33,7 @@ + #ifndef _UUID_UUID_H + #define _UUID_UUID_H + +-#include ++#include "../CoreFoundation/Base.subproj/SwiftRuntime/TargetConditionals.h" + #if TARGET_OS_MAC + #include + #include diff --git a/Patches/swift-corelibs-libdispatch/DisableWarningsAsErrors.patch b/Patches/swift-corelibs-libdispatch/DisableWarningsAsErrors.patch new file mode 100644 index 00000000..1c197b71 --- /dev/null +++ b/Patches/swift-corelibs-libdispatch/DisableWarningsAsErrors.patch @@ -0,0 +1,12 @@ +diff --git a/cmake/modules/DispatchCompilerWarnings.cmake b/cmake/modules/DispatchCompilerWarnings.cmake +index a7b31c818210a7b6de8ba094e6e8ce6de32e97e2..081616d8dfcbf3bf6ea9e0a4b1e32766bcc3fbd2 100644 +--- a/cmake/modules/DispatchCompilerWarnings.cmake ++++ b/cmake/modules/DispatchCompilerWarnings.cmake +@@ -5,7 +5,6 @@ if("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") + endmacro() + else() + macro(dispatch_common_warnings) +- add_compile_options(-Werror) + add_compile_options(-Wall) + add_compile_options(-Wextra) + diff --git a/Patches/uuid/CMakeLists.txt b/Patches/uuid/CMakeLists.txt new file mode 100644 index 00000000..9de295b4 --- /dev/null +++ b/Patches/uuid/CMakeLists.txt @@ -0,0 +1,59 @@ +cmake_minimum_required(VERSION 3.8) + +project(uuid) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set (SOURCE_FILES + clear.c + compare.c + copy.c + gen_uuid.c + isnull.c + pack.c + parse.c + unpack.c + unparse.c + uuid_time.c + ../../lib/randutils.c + ../../lib/md5.c + ../../lib/sha1.c +) + +add_definitions( + -DHAVE_INTTYPES_H + -DHAVE_UNISTD_H + -DHAVE_ERRNO_H + -DHAVE_NETINET_IN_H + -DHAVE_SYS_IOCTL_H + -DHAVE_SYS_MMAN_H + -DHAVE_SYS_MOUNT_H + -DHAVE_SYS_PRCTL_H + -DHAVE_SYS_RESOURCE_H + -DHAVE_SYS_SELECT_H + -DHAVE_SYS_STAT_H + -DHAVE_SYS_TYPES_H + -DHAVE_STDLIB_H + -DHAVE_STRDUP + -DHAVE_MMAP + -DHAVE_UTIME_H + -DHAVE_GETPAGESIZE + -DHAVE_LSEEK64 + -DHAVE_LSEEK64_PROTOTYPE + -DHAVE_EXT2_IOCTLS + -DHAVE_LINUX_FD_H + -DHAVE_TYPE_SSIZE_T + -DHAVE_SYS_TIME_H + -DHAVE_SYS_PARAM_H + -DHAVE_SYSCONF + -DHAVE_NANOSLEEP + -DHAVE_SYS_FILE_H +) + +add_library(uuid SHARED ${SOURCE_FILES}) +target_include_directories(uuid PRIVATE ../../include) +set_target_properties(uuid PROPERTIES PUBLIC_HEADER "uuid.h") +install(TARGETS uuid + LIBRARY DESTINATION lib + PUBLIC_HEADER DESTINATION include/uuid +) diff --git a/Projects/Hello/hello.swift b/Projects/Hello/hello.swift index 8ff93f57..4c0bd1c9 100755 --- a/Projects/Hello/hello.swift +++ b/Projects/Hello/hello.swift @@ -1,57 +1,34 @@ -// This is primitive ever "Hello World"-like Project. -// Project which uses Dispatch and Foundation frameworks will be added as soon, -// as Workflow will support Dispatch and Foundation frameworks compilation. -print("Hello, This Is Swift!") - -/* -import Foundation -import Dispatch +// ~~~~~~~~~~~~~~ CORE +print("SA - SwiftCore: Works!") -let op = BlockOperation { - print("Operation") -} -let opQueue = OperationQueue() -opQueue.addOperations([op], waitUntilFinished: true) - +// ~~~~~~~~~~~~~~ DISPATCH +import Dispatch let sema = DispatchSemaphore(value: 0) let queue = DispatchQueue(label: "queueName") queue.async { - print("XYZ") + print("SA - DispatchQueue: Works!") sema.signal() } if sema.wait(timeout: .now() + 10) == .timedOut { - print("~~~~~~") + print("SA - DispatchQueue: Timeout.") } -let config = URLSessionConfiguration() -let session = URLSession(configuration: config) -if let url = URL(string: "https://www.example.com") { - let sema2 = DispatchSemaphore(value: 0) - let task = session.dataTask(with: url) { data, response, error in - if let response = response { - print(response) - } - if let error = error { - print(error) - } - if let data = data { - print(data) - } - sema2.signal() - } - print(task) - task.resume() - if sema2.wait(timeout: .now() + 10) == .timedOut { - print("~~~~~~") - } -} else { - print("bad url") + +// ~~~~~~~~~~~~~~ FOUNDATION +import Foundation + +let op = BlockOperation { + print("SA - BlockOperation: Works!") } +let opQueue = OperationQueue() +opQueue.addOperations([op], waitUntilFinished: true) -let json = ["name": "Sveta"] +// ~~~~~~~~~~~~~~~~ Serialization + +let json = ["name": "SA - JSONSerialization/JSONDecoder: Works!"] do { let data = try JSONSerialization.data(withJSONObject: json, options: []) struct Person: Decodable { @@ -64,4 +41,34 @@ do { } catch { print(error) } -*/ + +// ~~~~~~~~~~ Networking + +print("SA - URLSession: Currently disabled. Will fail with `Segmentation fault`. Seems something in Foundation classes needs to be fixed.") + +// Still works strange. `Segmentation fault` + +// let config = URLSessionConfiguration() +// let session = URLSession(configuration: config) +// if let url = URL(string: "https://www.example.com") { +// let sema2 = DispatchSemaphore(value: 0) +// let task = session.dataTask(with: url) { data, response, error in +// if let response = response { +// print(response) +// } +// if let error = error { +// print(error) +// } +// if let data = data { +// print(data) +// } +// sema2.signal() +// } +// print(task) +// task.resume() +// if sema2.wait(timeout: .now() + 10) == .timedOut { +// print("~~~~~~") +// } +// } else { +// print("bad url") +// } diff --git a/Rakefile b/Rakefile index 443a7ee0..a434d978 100755 --- a/Rakefile +++ b/Rakefile @@ -13,7 +13,9 @@ require_relative "Scripts/Builders/LLVMBuilder.rb" require_relative "Scripts/Builders/CMarkBuilder.rb" require_relative "Scripts/Builders/ClangBuilder.rb" require_relative "Scripts/Builders/CompilerRTBuilder.rb" -require_relative "Scripts/ADBHelper.rb" +require_relative "Scripts/Builders/UUIDBuilder.rb" +require_relative "Scripts/Common/ADBHelper.rb" +require_relative "Scripts/Common/Tool.rb" # References: # @@ -22,48 +24,17 @@ require_relative "Scripts/ADBHelper.rb" task default: ['usage'] -task :usage do - help = <> Seems not needed - cmd << "CPPFLAGS=\"#{archFlags} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing\"" - cmd << "CXXFLAGS=\"#{archFlags} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -frtti -fexceptions -std=c++11 -Wno-error=unused-command-line-argument\"" - cmd << "CFLAGS=\"#{archFlags} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing\"" - cmd << "LDFLAGS=\"#{ldFlags}\"" + # archFlags = "-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16" + # ldFlags = "-march=armv7-a -Wl,--fix-cortex-a8" + # cmd << "CPPFLAGS=\"#{archFlags} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing\"" + # cmd << "CXXFLAGS=\"#{archFlags} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -frtti -fexceptions -std=c++11 -Wno-error=unused-command-line-argument\"" + # cmd << "CFLAGS=\"#{archFlags} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing\"" + # cmd << "LDFLAGS=\"#{ldFlags}\"" # << return cmd end + def configure + logConfigureStarted + prepare + ndk = AndroidBuilder.new(@arch) + # Seems `-D__ANDROID_API__` not needed. See: #{@sources}/NOTES.ANDROID + execute options.join(" ") + " ./Configure -D__ANDROID_API__=#{ndk.api} --prefix=#{@installs} android-arm" + logConfigureCompleted + end + def build - execute commonArgs.join(" ") + " make -j4" - execute commonArgs.join(" ") + " make install" + logBuildStarted + prepare + execute options.join(" ") + " make" + logBuildCompleted + end + + def install + logInstallStarted + execute options.join(" ") + " make install_sw install_ssldirs" + logInstallCompleted end def make - checkout - prepare configure build + install end end diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index e0cf5eb8..080a88c1 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -40,14 +40,17 @@ def initialize(arch = Arch.default) @ndk = AndroidBuilder.new(arch) end - def compileOLD - cmd = ["cd #{@sources} &&"] - # To avoid issue: - # /usr/bin/ld.gold: fatal error: /vagrant/Sources/ndk/platforms/android-21/arch-arm/usr/lib/../lib/crtbegin_so.o: unsupported ELF machine number 40 - cmd << "env PATH=#{@ndk.install}/arm-linux-androideabi/bin:$PATH" + def llvm + return @builds + "/llvm-linux-x86_64" + end + + def swift + return @builds + "/swift-linux-x86_64" end - def configureOld + # Unused at the moment. + def configure + logConfigureStarted # See: SWIFT_GIT_ROOT/docs/WindowsBuild.md cmd = [] cmd << "cd #{@builds} &&" @@ -117,6 +120,7 @@ def configureOld end def build + logBuildStarted cmd = ["cd #{@sources} &&"] cmd << "SKIP_BUILD_SWIFT_STATIC_LIBDISPATCH=1 SKIP_BUILD_STATIC_FOUNDATION=1" cmd << "./utils/build-script --release --skip-reconfigure" @@ -133,30 +137,22 @@ def build cmd << "--android-icu-i18n #{@icu.lib}/libicui18nswift.so" cmd << "--android-icu-i18n-include #{@icu.sources}/source/i18n" cmd << "--android-icu-data #{@icu.lib}/libicudataswift.so" + cmd << '--llvm-targets-to-build="ARM;AArch64;X86"' + end + + if @arch == Arch.host + cmd << '--llvm-targets-to-build="X86"' end cmd << "--install-swift" - cmd << "--libdispatch --install-libdispatch" - cmd << "--foundation --install-foundation" + + # Even if the below is disables Swift build script still builds `libdispatch` and `foundation` for Linux. + # cmd << "--libdispatch --install-libdispatch" + # cmd << "--foundation --install-foundation" # Try without it. cmd << "--build-swift-static-stdlib --build-swift-static-sdk-overlay" - # Try it - # cmd << "--test false" - # cmd << "--skip-test-cmark --skip-test-lldb --skip-test-swift --skip-test-llbuild --skip-test-swiftpm --skip-test-xctest" - # cmd << "--skip-test-foundation --skip-test-libdispatch --skip-test-playgroundsupport --skip-test-libicu" - - # TODO: Try it - cmd << '--llvm-targets-to-build="ARM;AArch64;X86"' - # TODO: Try it - # cmd << "--skip-test-android-host" - - # cmd << "--llbuild --install-llbuild" - # cmd << "--lldb --install-lldb" - # cmd << "--swiftpm --install-swiftpm" - # cmd << "--xctest --install-xctest" - # cmd << "'--swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;license;sourcekit-inproc'" cmd << "'--swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;license'" @@ -165,40 +161,22 @@ def build cmd << "--install-destdir=#{@installs}" cmd << "--build-dir #{@builds}" execute cmd.join(" ") - removeLinkerSymLink() + setupLinkerSymLink(false) logBuildCompleted() end def prepare - removeLinkerSymLink() - execute "mkdir -p #{@builds}" + setupLinkerSymLink(false) + prepareBuilds() # Fix for missed file: `CMake Error at cmake/modules/SwiftSharedCMakeConfig.cmake:196 (include):` # execute "touch \"#{@cmark.builds}/src/CMarkExports.cmake\"" setupLinkerSymLink() end - def setupLinkerSymLink - if @arch == Arch.armv7a - targetFile = "/usr/bin/armv7-none-linux-androideabi-ld.gold" - puts "Making symbolic link to \"#{targetFile}\"..." - execute "sudo ln -svf #{@ndk.sources}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/ld.gold #{targetFile}" - execute "ls -al /usr/bin/*ld.gold" - # FIXME: Remove simlink once done. - end - end - - def removeLinkerSymLink - if @arch == Arch.armv7a - message "Removing previously created symlink..." - targetFile = "/usr/bin/armv7-none-linux-androideabi-ld.gold" - execute "sudo rm -fv #{targetFile}" - execute "ls -al /usr/bin/*ld.gold" - end - end - def make prepare build + logInstallCompleted end def checkout @@ -206,8 +184,8 @@ def checkout end def clean - execute "rm -rf #{@builds}" - execute "rm -rf #{@installs}" + removeBuilds() + removeInstalls() end end diff --git a/Scripts/Builders/UUIDBuilder.rb b/Scripts/Builders/UUIDBuilder.rb new file mode 100644 index 00000000..e6a37fde --- /dev/null +++ b/Scripts/Builders/UUIDBuilder.rb @@ -0,0 +1,73 @@ +require_relative "../Common/Builder.rb" + +class UUIDBuilder < Builder + + def initialize(arch = Arch.default) + super(Lib.uuid, arch) + @uuidSources = "#{@sources}/libuuid/src" + end + + def configure + logConfigureStarted + configurePatches(false) + configurePatches() + ndk = AndroidBuilder.new(@arch) + prepare + cmd = [] + cmd << "cd #{@builds} &&" + cmd << "cmake -G Ninja" + cmd << "-DCMAKE_BUILD_TYPE=Release" + cmd << "-DCMAKE_INSTALL_PREFIX=#{@installs}" + if @arch == Arch.host + cmd << "-DCMAKE_C_COMPILER=clang" + else + cmd << "-DCMAKE_TOOLCHAIN_FILE=#{ndk.sources}/build/cmake/android.toolchain.cmake" + cmd << "-DANDROID_NDK=#{ndk.sources}" + cmd << "-DANDROID_ABI=armeabi-v7a" + cmd << "-DANDROID_PLATFORM=android-#{ndk.api}" + cmd << "-DANDROID_STL=c++_shared" + end + cmd << @uuidSources + execute cmd.join(" ") + logConfigureCompleted + end + + def build + logBuildStarted + prepare + execute "cd #{@builds} && ninja" + logBuildCompleted + end + + def make + configure + build + install + end + + def install + logInstallStarted + removeInstalls() + execute "cd #{@builds} && ninja install" + configurePatches(false) + logInstallCompleted + end + + def configurePatches(shouldEnable = true) + addFile("#{@patches}/CMakeLists.txt", "#{@sources}/libuuid/src/CMakeLists.txt", shouldEnable) + end + + def clean + configurePatches(false) + removeBuilds() + end + + def prepare + prepareBuilds() + end + + def checkout + checkoutIfNeeded(@sources, "https://github.com/karelzak/util-linux.git", "200769b6c0dff6863089ea2a9ff4ea9ccbd15d0f") + end + +end diff --git a/Scripts/Builders/XMLBuilder.rb b/Scripts/Builders/XMLBuilder.rb index c2bdcf47..9a41614b 100644 --- a/Scripts/Builders/XMLBuilder.rb +++ b/Scripts/Builders/XMLBuilder.rb @@ -7,30 +7,31 @@ def initialize(arch = Arch.default) end def checkout - checkoutIfNeeded(@sources, "https://github.com/GNOME/libxml2.git") + checkoutIfNeeded(@sources, "https://github.com/GNOME/libxml2.git", "6fc04d714a019cb3be351bc472f7a64a08f51008") end def prepare - execute "mkdir -p #{@build}" + # Not used at the moment. + # prepareBuilds() end def configure + logConfigureStarted + prepare # Arguments took from `swift/swift-corelibs-foundation/build-android` - ndkToolchainPath = "#{Config.ndkInstallRoot}/#{@target}" - ndkToolchainBinPath = "#{ndkToolchainPath}/bin" - ndkToolchainSysPath = "#{ndkToolchainPath}/sysroot" + ndk = AndroidBuilder.new(@arch) archFlags = "-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16" ldFlags = "-march=armv7-a -Wl,--fix-cortex-a8" - cmd = ["cd #{@sourcesDir} &&"] - cmd << "PATH=#{ndkToolchainBinPath}:$PATH" - cmd << "CC=#{ndkToolchainBinPath}/arm-linux-androideabi-clang" - cmd << "CXX=#{ndkToolchainBinPath}/arm-linux-androideabi-clang++" - cmd << "AR=#{ndkToolchainBinPath}/arm-linux-androideabi-ar" - cmd << "AS=#{ndkToolchainBinPath}/arm-linux-androideabi-as" - cmd << "LD=#{ndkToolchainBinPath}/arm-linux-androideabi-ld" - cmd << "RANLIB=#{ndkToolchainBinPath}/arm-linux-androideabi-ranlib" - cmd << "NM=#{ndkToolchainBinPath}/arm-linux-androideabi-nm" - cmd << "STRIP=#{ndkToolchainBinPath}/arm-linux-androideabi-strip" + cmd = ["cd #{@sources} &&"] + cmd << "PATH=#{ndk.bin}:$PATH" + cmd << "CC=#{ndk.bin}/arm-linux-androideabi-clang" + cmd << "CXX=#{ndk.bin}/arm-linux-androideabi-clang++" + cmd << "AR=#{ndk.bin}/arm-linux-androideabi-ar" + cmd << "AS=#{ndk.bin}/arm-linux-androideabi-as" + cmd << "LD=#{ndk.bin}/arm-linux-androideabi-ld" + cmd << "RANLIB=#{ndk.bin}/arm-linux-androideabi-ranlib" + cmd << "NM=#{ndk.bin}/arm-linux-androideabi-nm" + cmd << "STRIP=#{ndk.bin}/arm-linux-androideabi-strip" cmd << "CHOST=arm-linux-androideabi" cmd << "CPPFLAGS=\"#{archFlags} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing\"" cmd << "CXXFLAGS=\"#{archFlags} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -frtti -fexceptions -std=c++11 -Wno-error=unused-command-line-argument\"" @@ -39,21 +40,29 @@ def configure execute cmd.join(" ") + " autoreconf -i" - args = "--with-sysroot=#{ndkToolchainSysPath} --with-zlib=#{ndkToolchainSysPath}/usr --prefix=#{@installDir} --host=arm-linux-androideabi --without-lzma --disable-static --enable-shared --without-http --without-html --without-ftp" + args = "--with-sysroot=#{ndk.installs}/sysroot --with-zlib=#{ndk.installs}/sysroot/usr --prefix=#{@installs} --host=arm-linux-androideabi --without-lzma --disable-static --enable-shared --without-http --without-html --without-ftp" execute cmd.join(" ") + " ./configure " + args + logConfigureCompleted end def build - execute "cd #{@sourcesDir} && make libxml2.la" - execute "cd #{@sourcesDir} && make install-libLTLIBRARIES" - execute "cd #{@sourcesDir}/include && make install" + logBuildStarted + prepare + execute "cd #{@sources} && make libxml2.la" + logBuildCompleted + end + + def install + logInstallStarted + execute "cd #{@sources} && make install-libLTLIBRARIES" + execute "cd #{@sources}/include && make install" + logInstallCompleted end def make - checkout - prepare configure build + install end end diff --git a/Scripts/Common/ADBHelper.rb b/Scripts/Common/ADBHelper.rb new file mode 100755 index 00000000..1c33a8ec --- /dev/null +++ b/Scripts/Common/ADBHelper.rb @@ -0,0 +1,69 @@ +require_relative "Tool.rb" + +class ADBHelper < Tool + + def initialize() + super() + @destinationDirPath = "/data/local/tmp/hello" + @swift = SwiftBuilder.new() + @ndk = AndroidBuilder.new() + @icu = ICUBuilder.new() + @curl = CurlBuilder.new() + @ssl = OpenSSLBuilder.new() + @xml = XMLBuilder.new() + end + + def verify() + # See: Enable adb debugging on your device – https://developer.android.com/studio/command-line/adb#Enabling + # On linux `execute "sudo apt-get install android-tools-adb"` + execute "adb devices" # To run daemon. + message "Make sure you are enabled \"USB debugging\" on Android device (See :https://developer.android.com/studio/command-line/adb#Enabling)" + execute "adb devices" # To list devices. + end + + def deployLibs() + message "Deploy of Shared Objects started." + execute "adb shell rm -rf #{@destinationDirPath}" + execute "adb shell mkdir -p #{@destinationDirPath}" + Dir["#{@swift.installs}/usr/lib/swift/android" + "/*.so"].each { |lib| + execute "adb push #{lib} #{@destinationDirPath}" + } + Dir[@icu.lib + "/*.so*"].select { |lib| !File.symlink?(lib) }.each { |lib| + destName = File.basename(lib) + destName = destName.sub("63.1", "63") # Fix for error: CANNOT LINK EXECUTABLE ... library "libicudataswift.so.63" not found + execute "adb push #{lib} #{@destinationDirPath}/#{destName}" + } + Dir[@curl.lib + "/*.so"].each { |lib| + execute "adb push #{lib} #{@destinationDirPath}" + } + Dir[@xml.lib + "/*.so"].each { |lib| + execute "adb push #{lib} #{@destinationDirPath}" + } + Dir[@ssl.lib + "/*.so*"].select { |lib| !File.symlink?(lib) }.each { |lib| + execute "adb push #{lib} #{@destinationDirPath}" + } + cxxLibPath = "#{@ndk.sources}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so" + execute "adb push #{cxxLibPath} #{@destinationDirPath}" + message "Deploy of Shared Objects completed." + end + + def deployProducts(products) + products.each { |file| + cmd = "adb push #{file} #{@destinationDirPath}" + execute cmd + } + end + + def run(binary) + execute "adb shell ls -l #{@destinationDirPath}" + fullPath = "#{@destinationDirPath}/#{binary}" + message "Starting execution of \"#{fullPath}\"..." + execute "adb shell LD_LIBRARY_PATH=#{@destinationDirPath} #{fullPath}" + message "Execution of \"#{fullPath}\" completed." + end + + def clean + execute "adb shell rm -rf #{@destinationDirPath}" + end + +end diff --git a/Scripts/Common/Arch.rb b/Scripts/Common/Arch.rb index 4de753bc..8f64cca9 100644 --- a/Scripts/Common/Arch.rb +++ b/Scripts/Common/Arch.rb @@ -4,6 +4,7 @@ def self.default return armv7a end + # Fixme. Seems `x86` can be used instead. def self.host return "host" end diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index aec74477..710c14da 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -16,6 +16,9 @@ def initialize(component, arch) @patches = "#{Config.patches}/#{component}" @builds = "#{Config.build}/#{arch}/#{component}" @installs = "#{Config.install}/#{arch}/#{component}" + @startSpacer = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + @endSpacer = "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" + @dryRun = ENV['SA_DRY_RUN'].to_s.empty? == false end def lib @@ -34,16 +37,110 @@ def usr return @installs + "/usr" end + # ------------------------------------ + + def logStarted(action) + puts "" + print(@startSpacer, 33) + print("\"#{@component}\" #{action} is started.", 36) + end + + def logCompleted(action) + print("\"#{@component}\" #{action} is completed.", 36) + print(@endSpacer, 33) + puts "" + end + + def logConfigureStarted + logStarted("Configure") + end + + def logBuildStarted + logStarted("Build") + end + + def logInstallStarted + logStarted("Install") + end + + def logSetupCompleted + logCompleted("Setup") + end + def logBuildCompleted - message "\"#{@component}\" build is completed." + logCompleted("Build") end def logConfigureCompleted - message "\"#{@component}\" configuring is completed." + logCompleted("Configure") end def logInstallCompleted - message "\"#{@component}\" install is completed." + logCompleted("Install") + end + + # ------------------------------------ + + def removeInstalls() + execute "rm -rf \"#{@installs}\"" + end + + def removeBuilds() + execute "rm -rf \"#{@builds}\"" + end + + def prepareBuilds() + execute "mkdir -p \"#{@builds}\"" + end + + def setupLinkerSymLink(shouldCreate = true) + ndk = AndroidBuilder.new(@arch) + if @arch == Arch.armv7a + targetFile = "/usr/bin/armv7-none-linux-androideabi-ld.gold" + if shouldCreate + message "Making symbolic link to \"#{targetFile}\"..." + execute "sudo ln -svf #{ndk.sources}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/ld.gold #{targetFile}" + else + message "Removing previously created symlink: \"#{targetFile}\"..." + execute "sudo rm -fv #{targetFile}" + end + execute "ls -al /usr/bin/*ld.gold" + end + end + + def addFile(replacementFile, destinationFile, shouldApply = true) + if shouldApply + if !File.exist? destinationFile + puts "Applying fix \"#{@component}\"..." + execute "cp -vf \"#{replacementFile}\" \"#{destinationFile}\"" + else + puts "File \"#{destinationFile}\" exists. Seems you already applied fix for \"#{@component}\". Skipping..." + end + else + message "Removing previously applied fix..." + if File.exist? destinationFile + execute "rm -fv #{destinationFile}" + end + end + end + + def configurePatch(originalFile, patchFile, shouldApply = true) + gitRepoRoot = "#{Config.sources}/#{@component}" + backupFile = "#{originalFile}.orig" + if shouldApply + if !File.exist? backupFile + puts "Patching \"#{@component}\"..." + execute "patch --backup #{originalFile} #{patchFile}" + else + puts "Backup file \"#{backupFile}\" exists. Seems you already patched \"#{@component}\". Skipping..." + end + else + message "Removing previously applied patch..." + execute "cd \"#{gitRepoRoot}\" && git checkout #{originalFile}" + if File.exist? backupFile + execute "rm -fv #{backupFile}" + end + end end def checkoutIfNeeded(localPath, repoURL, revision) diff --git a/Scripts/Common/Lib.rb b/Scripts/Common/Lib.rb index f268299c..90833449 100644 --- a/Scripts/Common/Lib.rb +++ b/Scripts/Common/Lib.rb @@ -36,6 +36,14 @@ def self.xml return "xml" end + def self.ssl + return "ssl" + end + + def self.uuid + return "uuid" + end + def self.dispatch return "swift-corelibs-libdispatch" end diff --git a/Scripts/Common/Tool.rb b/Scripts/Common/Tool.rb index 1d62f308..970e3df2 100755 --- a/Scripts/Common/Tool.rb +++ b/Scripts/Common/Tool.rb @@ -1,24 +1,35 @@ # See: -# - Colorized Ruby output: https://stackoverflow.com/a/11482430/1418981 +# - class Tool def execute(command) - puts "\e[32m#{command}\e[0m" # Print to console with Green color. + print(command, 32) # Green color. if system(command) != true message "Execution of command is failed:" error command puts + help = <