From a5aa239e77b18cc04ab983e9cd04104d337cb7fe Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Wed, 12 Dec 2018 21:48:29 +0100 Subject: [PATCH 01/66] Environment variables not used. --- .rubocop.yml | 87 ++++++++++++++++++++++++++++++++++++ Readme.md | 32 ------------- Scripts/Common/Config.rb | 29 +++++++----- Scripts/Shell/environment.sh | 32 ------------- 4 files changed, 104 insertions(+), 76 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..a2dc3342 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,87 @@ +AllCops: + Exclude: + - Build/**/* + - Install/**/* + - Projects/**/* + - Sources/**/* + +Metrics/AbcSize: + Max: 50 + +Metrics/ClassLength: + Max: 240 + +Metrics/MethodLength: + Max: 80 + +Metrics/CyclomaticComplexity: + Max: 20 + +Metrics/PerceivedComplexity: + Max: 20 + +Style/IfUnlessModifier: + Enabled: false + +Style/SpecialGlobalVars: + Enabled: false + +Style/BracesAroundHashParameters: + Enabled: false + +Style/WordArray: + EnforcedStyle: brackets + +Style/Documentation: + Enabled: false + +Style/AsciiComments: + Enabled: false + +Style/SymbolArray: + Enabled: false + +Style/RedundantReturn: + Enabled: false + +Style/MethodCallWithoutArgsParentheses: + Enabled: false + +Style/GuardClause: + Enabled: false + +Style/BlockDelimiters: + Enabled: false + +Style/NegatedIf: + Enabled: false + +Style/DefWithParentheses: + Enabled: false + +Style/StringLiterals: + Enabled: false + +Layout/EmptyLinesAroundClassBody: + EnforcedStyle: empty_lines + +Layout/IndentationWidth: + Width: 3 + +Naming/VariableName: + EnforcedStyle: camelCase + +Naming/MethodName: + Enabled: false + +Naming/UncommunicativeMethodParamName: + Enabled: false + +Naming/UncommunicativeBlockParamName: + Enabled: false + +Layout/EmptyLinesAroundModuleBody: + Enabled: false + +Metrics/LineLength: + Enabled: false diff --git a/Readme.md b/Readme.md index a8786abf..204a8cff 100644 --- a/Readme.md +++ b/Readme.md @@ -182,38 +182,6 @@ D. Getting Sources box$ ls -l /vagrant/Sources ``` -5. Verify environment variables inside Box. - - ```bash - box$ env | sort - ``` - - Should output: - - ``` - ... - PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/vagrant/Sources/android-ndk-r18b - PWD=/home/vagrant - RUBYOPT=-W0 - SA_BUILD_ROOT_ANDK=/vagrant/Build/android-ndk - SA_BUILD_ROOT_ICU=/vagrant/Build/icu - SA_BUILD_ROOT_SWIFT=/vagrant/Build/swift-android - SA_BUILD_ROOT=/vagrant/Build - SA_INSTALL_ROOT_ANDK=/vagrant/Install/android-ndk - SA_INSTALL_ROOT_ICU=/vagrant/Install/icu - SA_INSTALL_ROOT_SWIFT=/vagrant/Install/swift - SA_INSTALL_ROOT=/vagrant/Install - SA_PATCHES_ROOT_ICU=/vagrant/Patches/icu - SA_PATCHES_ROOT=/vagrant/Patches - SA_PROJECTS_ROOT=/vagrant/Projects - SA_SOURCES_ROOT_ANDK=/vagrant/Sources/android-ndk-r18b - SA_SOURCES_ROOT_ICU=/vagrant/Sources/icu - SA_SOURCES_ROOT_SWIFT=/vagrant/Sources/swift - SA_SOURCES_ROOT=/vagrant/Sources - SHELL=/bin/bash - ... - ``` - E. Installing dependencies on Box --------------------------------------- diff --git a/Scripts/Common/Config.rb b/Scripts/Common/Config.rb index 7dee2ab5..7a8fa0f8 100755 --- a/Scripts/Common/Config.rb +++ b/Scripts/Common/Config.rb @@ -4,45 +4,50 @@ def self.androidAPI return "21" end + def self.rootDirPath + return File.realpath(File.dirname(__FILE__) + "/../../") + end + def self.verify - puts "- Android NDK Path: \t\"#{andkPath}\"" - puts "- ICU Sources Path: \t\"#{icuSources}\"" - puts "- ICU Patches Path: \t\"#{icuPatchesDirPath}\"" - puts "- Swift Sources Path: \t\"#{swiftSources}\"" + puts "- Project Root Path: \t\"#{rootDirPath}\"" + puts "- Android NDK Path: \t\"#{ndkSourcesRoot}\"" + puts "- ICU Sources Path: \t\"#{icuSourcesRoot}\"" + puts "- ICU Patches Path: \t\"#{icuPatchesRoot}\"" + puts "- Swift Sources Path: \t\"#{swiftSourcesRoot}\"" puts "- Build root Path: \t\"#{buildRoot}\"" puts "- Install root Path: \t\"#{installRoot}\"" end def self.ndkSourcesRoot - return getEnvVariable('SA_SOURCES_ROOT_ANDK') + return "#{rootDirPath}/Sources/android-ndk-r18b" end def self.icuSourcesRoot - return getEnvVariable('SA_SOURCES_ROOT_ICU') + return "#{rootDirPath}/Sources/icu" end def self.swiftSourcesRoot - return getEnvVariable('SA_SOURCES_ROOT_SWIFT') + return "#{rootDirPath}/Sources/swift" end def self.buildRoot - return getEnvVariable('SA_BUILD_ROOT') + return "#{rootDirPath}/Build" end def self.swiftBuildRoot - return getEnvVariable('SA_BUILD_ROOT_SWIFT') + return "#{buildRoot}/swift-android" end def self.installRoot - return getEnvVariable('SA_INSTALL_ROOT') + return "#{rootDirPath}/Install" end def self.icuPatchesRoot - return getEnvVariable('SA_PATCHES_ROOT_ICU') + return "#{rootDirPath}/Patches/icu" end def self.projectsRoot - return getEnvVariable('SA_PROJECTS_ROOT') + return "#{rootDirPath}/Projects" end def self.getEnvVariable(name) diff --git a/Scripts/Shell/environment.sh b/Scripts/Shell/environment.sh index 69bdaee3..989bc567 100644 --- a/Scripts/Shell/environment.sh +++ b/Scripts/Shell/environment.sh @@ -1,33 +1 @@ -## Sources -export SA_SOURCES_ROOT=/vagrant/Sources - -export SA_SOURCES_ROOT_ANDK=$SA_SOURCES_ROOT/android-ndk-r18b -export SA_SOURCES_ROOT_ICU=$SA_SOURCES_ROOT/icu -export SA_SOURCES_ROOT_SWIFT=$SA_SOURCES_ROOT/swift - -## Build -export SA_BUILD_ROOT=/vagrant/Build - -export SA_BUILD_ROOT_ANDK=$SA_BUILD_ROOT/android-ndk -export SA_BUILD_ROOT_ICU=$SA_BUILD_ROOT/icu -export SA_BUILD_ROOT_SWIFT=$SA_BUILD_ROOT/swift-android - -## Install -export SA_INSTALL_ROOT=/vagrant/Install - -export SA_INSTALL_ROOT_ANDK=$SA_INSTALL_ROOT/android-ndk -export SA_INSTALL_ROOT_ICU=$SA_INSTALL_ROOT/icu -export SA_INSTALL_ROOT_SWIFT=$SA_INSTALL_ROOT/swift - -## Patches -export SA_PATCHES_ROOT=/vagrant/Patches - -export SA_PATCHES_ROOT_ICU=$SA_PATCHES_ROOT/icu - -## Projects -export SA_PROJECTS_ROOT=/vagrant/Projects - - -## Misc -export PATH=$PATH:$SA_SOURCES_ROOT_ANDK export RUBYOPT=-W0 From 17642d9b08bc96f609dddee7a35db32884b56542 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Wed, 12 Dec 2018 22:10:34 +0100 Subject: [PATCH 02/66] Structure update. --- .rubocop.yml | 3 +++ Rakefile | 25 +++++++++++++++++++++++++ Scripts/Builders/AndroidBuilder.rb | 2 +- Scripts/Builders/CurlBuilder.rb | 14 ++++++++++++++ Scripts/Builders/FoundationBuilder.rb | 10 ++++++++++ Scripts/Builders/ICUBuilder.rb | 2 +- Scripts/Builders/SwiftBuilder.rb | 2 +- Scripts/{Builders => Common}/Builder.rb | 0 Scripts/Common/Config.rb | 14 +++++++++++--- 9 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 Scripts/Builders/CurlBuilder.rb create mode 100644 Scripts/Builders/FoundationBuilder.rb rename Scripts/{Builders => Common}/Builder.rb (100%) diff --git a/.rubocop.yml b/.rubocop.yml index a2dc3342..8e2659b1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -74,6 +74,9 @@ Naming/VariableName: Naming/MethodName: Enabled: false +Layout/EmptyLinesAroundBlockBody: + Enabled: false + Naming/UncommunicativeMethodParamName: Enabled: false diff --git a/Rakefile b/Rakefile index 34db9cae..1c7b4e3f 100755 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,8 @@ require_relative "Scripts/Builders/ICUBuilder.rb" require_relative "Scripts/Builders/AndroidBuilder.rb" require_relative "Scripts/Builders/SwiftBuilder.rb" +require_relative "Scripts/Builders/FoundationBuilder.rb" +require_relative "Scripts/Builders/CurlBuilder.rb" require_relative "Scripts/HelloProjectBuilder.rb" require_relative "Scripts/ADBHelper.rb" @@ -134,6 +136,29 @@ namespace :swift do end +namespace :foundation do + + desc "Builds libFoundation for Android" + task :build do + FoundationBuilder.new().make + end + +end + +namespace :curl do + + desc "Checkout curl" + task :checkout do + CurlBuilder.new().checkout + end + + desc "Build curl" + task :build do + CurlBuilder.new().make + end + +end + namespace :project do namespace :hello do diff --git a/Scripts/Builders/AndroidBuilder.rb b/Scripts/Builders/AndroidBuilder.rb index bb8aa925..10e1a2a5 100755 --- a/Scripts/Builders/AndroidBuilder.rb +++ b/Scripts/Builders/AndroidBuilder.rb @@ -1,4 +1,4 @@ -require_relative "Builder.rb" +require_relative "../Common/Builder.rb" require_relative "../Common/Config.rb" class AndroidBuilder < Builder diff --git a/Scripts/Builders/CurlBuilder.rb b/Scripts/Builders/CurlBuilder.rb new file mode 100644 index 00000000..eda75096 --- /dev/null +++ b/Scripts/Builders/CurlBuilder.rb @@ -0,0 +1,14 @@ +require_relative "../Common/Builder.rb" +require_relative "../Common/Config.rb" + +class CurlBuilder < Builder + + def checkout() + execute "cd #{Config.sourcesRoot} && git clone https://github.com/curl/curl.git" + end + + def make() + puts "OK" + end + +end diff --git a/Scripts/Builders/FoundationBuilder.rb b/Scripts/Builders/FoundationBuilder.rb new file mode 100644 index 00000000..f6cb60b8 --- /dev/null +++ b/Scripts/Builders/FoundationBuilder.rb @@ -0,0 +1,10 @@ +require_relative "../Common/Builder.rb" +require_relative "../Common/Config.rb" + +class FoundationBuilder < Builder + + def make() + puts "OK" + end + +end diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index f65e1487..79a60a3e 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -1,4 +1,4 @@ -require_relative "Builder.rb" +require_relative "../Common/Builder.rb" require_relative "../Common/Config.rb" # See: diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 5de4c1b4..b3bf4646 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -1,4 +1,4 @@ -require_relative "Builder.rb" +require_relative "../Common/Builder.rb" require_relative "../Common/Config.rb" =begin diff --git a/Scripts/Builders/Builder.rb b/Scripts/Common/Builder.rb similarity index 100% rename from Scripts/Builders/Builder.rb rename to Scripts/Common/Builder.rb diff --git a/Scripts/Common/Config.rb b/Scripts/Common/Config.rb index 7a8fa0f8..e1418f7c 100755 --- a/Scripts/Common/Config.rb +++ b/Scripts/Common/Config.rb @@ -19,15 +19,23 @@ def self.verify end def self.ndkSourcesRoot - return "#{rootDirPath}/Sources/android-ndk-r18b" + return "#{sourcesRoot}/android-ndk-r18b" end def self.icuSourcesRoot - return "#{rootDirPath}/Sources/icu" + return "#{sourcesRoot}/icu" end def self.swiftSourcesRoot - return "#{rootDirPath}/Sources/swift" + return "#{sourcesRoot}/swift" + end + + def self.curlSourcesRoot + return "#{sourcesRoot}/curl" + end + + def self.sourcesRoot + return "#{rootDirPath}/Sources" end def self.buildRoot From 0172f7a6f497d1ffb0a4204da394190c5d9eba5b Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Wed, 12 Dec 2018 22:43:46 +0100 Subject: [PATCH 03/66] Scripts update. --- Rakefile | 4 +-- Scripts/ADBHelper.rb | 2 +- Scripts/Builders/AndroidBuilder.rb | 5 ++- Scripts/Builders/CurlBuilder.rb | 35 ++++++++++++++++--- Scripts/{ => Builders}/HelloProjectBuilder.rb | 4 +-- Scripts/Builders/ICUBuilder.rb | 14 ++++---- Scripts/Builders/SwiftBuilder.rb | 2 +- Scripts/Common/Builder.rb | 8 +++++ Scripts/Common/Config.rb | 8 +++++ 9 files changed, 62 insertions(+), 20 deletions(-) rename Scripts/{ => Builders}/HelloProjectBuilder.rb (94%) diff --git a/Rakefile b/Rakefile index 1c7b4e3f..ce502a0f 100755 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,7 @@ require_relative "Scripts/Builders/AndroidBuilder.rb" require_relative "Scripts/Builders/SwiftBuilder.rb" require_relative "Scripts/Builders/FoundationBuilder.rb" require_relative "Scripts/Builders/CurlBuilder.rb" -require_relative "Scripts/HelloProjectBuilder.rb" +require_relative "Scripts/Builders/HelloProjectBuilder.rb" require_relative "Scripts/ADBHelper.rb" # References: @@ -153,7 +153,7 @@ namespace :curl do end desc "Build curl" - task :build do + task :make do CurlBuilder.new().make end diff --git a/Scripts/ADBHelper.rb b/Scripts/ADBHelper.rb index eca7b778..1a79be31 100755 --- a/Scripts/ADBHelper.rb +++ b/Scripts/ADBHelper.rb @@ -24,7 +24,7 @@ def deployLibs() cmd = "adb push #{lib} #{@destinationDirPath}" execute cmd } - icuLibsDirPath = "#{Config.installRoot}/icu/armv7a/lib" + icuLibsDirPath = "#{Config.icuInstallRoot}/armv7a/lib" Dir[icuLibsDirPath + "/*.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 diff --git a/Scripts/Builders/AndroidBuilder.rb b/Scripts/Builders/AndroidBuilder.rb index 10e1a2a5..10aee3fc 100755 --- a/Scripts/Builders/AndroidBuilder.rb +++ b/Scripts/Builders/AndroidBuilder.rb @@ -6,7 +6,7 @@ class AndroidBuilder < Builder def initialize(arch) super() @arch = arch - @installDir = Config.installRoot + "/android/#{@arch}" + @installDir = Config.ndkInstallRoot + "/#{@arch}" end def setupToolchain @@ -25,8 +25,7 @@ def setupToolchain end def clean() - execute "rm -rf #{Config.buildRoot}/android/" - execute "rm -rf #{Config.installRoot}/android/" + execute "rm -rf #{Config.ndkInstallRoot}/" end end diff --git a/Scripts/Builders/CurlBuilder.rb b/Scripts/Builders/CurlBuilder.rb index eda75096..ebfc045c 100644 --- a/Scripts/Builders/CurlBuilder.rb +++ b/Scripts/Builders/CurlBuilder.rb @@ -3,12 +3,39 @@ class CurlBuilder < Builder - def checkout() - execute "cd #{Config.sourcesRoot} && git clone https://github.com/curl/curl.git" + def initialize(target = "armv7a") + super() + @target = target + @sourcesDir = Config.curlSourcesRoot + @buildDir = Config.buildRoot + "/curl/" + @target + @installDir = Config.installRoot + "/curl/" + @target end - def make() - puts "OK" + def checkout + checkoutIfNeeded(@sourcesDir, "https://github.com/curl/curl.git") + end + + def prepare + execute "mkdir -p #{@buildDir}" + execute "mkdir -p #{@installDir}" + end + + def configure + # Arguments took from `swift/swift-corelibs-foundation/build-android` + cmd = ["cd #{@sourcesDir} &&"] + cmd << "autoreconf -i" + execute cmd.join(" ") + end + + def build + + end + + def make + checkout + prepare + configure + build end end diff --git a/Scripts/HelloProjectBuilder.rb b/Scripts/Builders/HelloProjectBuilder.rb similarity index 94% rename from Scripts/HelloProjectBuilder.rb rename to Scripts/Builders/HelloProjectBuilder.rb index bbeff80c..6cc9854b 100755 --- a/Scripts/HelloProjectBuilder.rb +++ b/Scripts/Builders/HelloProjectBuilder.rb @@ -1,5 +1,5 @@ -require_relative "Builders/Builder.rb" -require_relative "Common/Config.rb" +require_relative "../Common/Builder.rb" +require_relative "../Common/Config.rb" # See: # - Build error: No such module "SwiftGlibc" – https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20160919/002955.html diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index 79a60a3e..cb22323c 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -16,7 +16,7 @@ def initialize(target = "armv7a") super() @target = target @buildDir = Config.buildRoot + "/icu/" + @target - @prefixDir = Config.installRoot + "/icu/" + @target + @prefixDir = Config.icuInstallRoot + "/" + @target end def configure @@ -28,7 +28,7 @@ def configure cmd << "--enable-static --enable-shared=no --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no" cmd << "--enable-layoutex=no --enable-tools=no --enable-tests=no --enable-samples=no --enable-dyload=no" elsif @target == "armv7a" - cmd << "PATH=#{Config.installRoot}/android/#{@target}/bin:$PATH" + cmd << "PATH=#{Config.ndkInstallRoot}/#{@target}/bin:$PATH" cmd << "CFLAGS='-Os -march=armv7-a -mfloat-abi=softfp -mfpu=neon'" cmd << "CXXFLAGS='--std=c++11 -march=armv7-a -mfloat-abi=softfp -mfpu=neon'" cmd << "LDFLAGS='-march=armv7-a -Wl,--fix-cortex-a8'" @@ -44,7 +44,7 @@ def configure cmd << "--with-cross-build=#{Config.buildRoot}/icu/linux" cmd << "--with-data-packaging=archive" elsif @target == "x86" - cmd << "PATH=#{Config.installRoot}/android/#{@target}/bin:$PATH" + cmd << "PATH=#{Config.ndkInstallRoot}/#{@target}/bin:$PATH" cmd << "CFLAGS='-Os -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32'" cmd << "CXXFLAGS='--std=c++11 -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32'" cmd << "CC=i686-linux-android-clang" @@ -59,7 +59,7 @@ def configure cmd << "--with-cross-build=#{Config.buildRoot}/icu/linux" cmd << "--with-data-packaging=archive" elsif @target == "aarch64" - cmd << "PATH=#{Config.installRoot}/android/#{@target}/bin:$PATH" + cmd << "PATH=#{Config.ndkInstallRoot}/#{@target}/bin:$PATH" cmd << "CFLAGS='-Os'" cmd << "CXXFLAGS='--std=c++11'" cmd << "CC=aarch64-linux-android-clang" @@ -95,8 +95,8 @@ def applyPatchIfNeeded() end def build - execute "cd #{@buildDir} && PATH=#{Config.installRoot}/android/#{@target}/bin:$PATH make -j4" - execute "cd #{@buildDir} && PATH=#{Config.installRoot}/android/#{@target}/bin:$PATH make install" + execute "cd #{@buildDir} && PATH=#{Config.ndkInstallRoot}/#{@target}/bin:$PATH make -j4" + execute "cd #{@buildDir} && PATH=#{Config.ndkInstallRoot}/#{@target}/bin:$PATH make install" end def make() @@ -107,7 +107,7 @@ def make() def clean() execute "rm -rf #{Config.buildRoot}/icu/" - execute "rm -rf #{Config.installRoot}/icu/" + execute "rm -rf #{Config.icuInstallRoot}/" end end diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index b3bf4646..78ca6422 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -56,7 +56,7 @@ def initialize() def build() target = "armv7a" - libICUBuildPath = Config.installRoot + "/icu/#{target}/lib" + libICUBuildPath = Config.icuInstallRoot + "/#{target}/lib" cmd = ["cd #{Config.swiftSourcesRoot} &&"] cmd << "./swift/utils/build-script --release --android" cmd << "--android-ndk #{Config.ndkSourcesRoot}" diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index a0842555..32354cd1 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -2,4 +2,12 @@ class Builder < Tool + def checkoutIfNeeded(localPath, repoURL) + if File.exist?(localPath) + message "Repository #{repoURL} seems already checked out." + else + execute "cd #{File.dirname(localPath)} && git clone #{repoURL}" + end + end + end diff --git a/Scripts/Common/Config.rb b/Scripts/Common/Config.rb index e1418f7c..dfc7232b 100755 --- a/Scripts/Common/Config.rb +++ b/Scripts/Common/Config.rb @@ -50,6 +50,14 @@ def self.installRoot return "#{rootDirPath}/Install" end + def self.ndkInstallRoot + return "#{installRoot}/android" + end + + def self.icuInstallRoot + return "#{installRoot}/icu" + end + def self.icuPatchesRoot return "#{rootDirPath}/Patches/icu" end From 513bb838ceed434e983e4666cbfd884458792b1a Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Thu, 13 Dec 2018 00:36:43 +0100 Subject: [PATCH 04/66] Implemented openSSL and CURL builds. --- Rakefile | 14 ++++++ Scripts/Builders/CurlBuilder.rb | 40 ++++++++++++++--- Scripts/Builders/OpenSSLBuilder.rb | 69 ++++++++++++++++++++++++++++++ Scripts/Common/Config.rb | 4 ++ Scripts/Shell/bootstrap.sh | 2 +- Sources/.gitignore | 1 + 6 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 Scripts/Builders/OpenSSLBuilder.rb diff --git a/Rakefile b/Rakefile index ce502a0f..a2621473 100755 --- a/Rakefile +++ b/Rakefile @@ -5,6 +5,7 @@ require_relative "Scripts/Builders/AndroidBuilder.rb" require_relative "Scripts/Builders/SwiftBuilder.rb" require_relative "Scripts/Builders/FoundationBuilder.rb" require_relative "Scripts/Builders/CurlBuilder.rb" +require_relative "Scripts/Builders/OpenSSLBuilder.rb" require_relative "Scripts/Builders/HelloProjectBuilder.rb" require_relative "Scripts/ADBHelper.rb" @@ -159,6 +160,19 @@ namespace :curl do end +namespace :openssl do + + desc "Checkout OpenSSL" + task :checkout do + OpenSSLBuilder.new().checkout + end + + desc "Make OpenSSL" + task :make do + OpenSSLBuilder.new().make + end +end + namespace :project do namespace :hello do diff --git a/Scripts/Builders/CurlBuilder.rb b/Scripts/Builders/CurlBuilder.rb index ebfc045c..aeb6c4c0 100644 --- a/Scripts/Builders/CurlBuilder.rb +++ b/Scripts/Builders/CurlBuilder.rb @@ -20,21 +20,51 @@ def prepare execute "mkdir -p #{@installDir}" end + def commonArgs() + + end + def configure # Arguments took from `swift/swift-corelibs-foundation/build-android` + ndkToolchainPath = "#{Config.ndkInstallRoot}/#{@target}" + ndkToolchainBinPath = "#{ndkToolchainPath}/bin" + ndkToolchainSysPath = "#{ndkToolchainPath}/sysroot" + archFlags = "-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16" + ldFlags = "-march=armv7-a -Wl,--fix-cortex-a8" cmd = ["cd #{@sourcesDir} &&"] - cmd << "autoreconf -i" + 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 << "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\"" + cmd << "CFLAGS=\"#{archFlags} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing\"" + cmd << "LDFLAGS=\"#{ldFlags}\"" + execute cmd.join(" ") + " autoreconf -i" + + cmd << "./configure" + cmd << "--host=arm-linux-androideabi --enable-shared --disable-static --disable-dependency-tracking --without-ca-bundle --without-ca-path --enable-ipv6 --enable-http --enable-ftp" + cmd << "--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" + cmd << "--target=arm-linux-androideabi --build=x86_64-unknown-linux-gnu" + cmd << "--with-zlib=#{ndkToolchainSysPath}/usr --with-ssl=#{Config.opensslSourcesRoot} --prefix=#{@installDir}" execute cmd.join(" ") end def build - + execute "cd #{@sourcesDir} && make" + execute "cd #{@sourcesDir} && make install" end def make - checkout - prepare - configure + # checkout + # prepare + # configure build end diff --git a/Scripts/Builders/OpenSSLBuilder.rb b/Scripts/Builders/OpenSSLBuilder.rb new file mode 100644 index 00000000..39726f3a --- /dev/null +++ b/Scripts/Builders/OpenSSLBuilder.rb @@ -0,0 +1,69 @@ +require_relative "../Common/Builder.rb" +require_relative "../Common/Config.rb" + +# See: +# - Compiling the latest OpenSSL for Android: https://stackoverflow.com/questions/11929773/compiling-the-latest-openssl-for-android + +class OpenSSLBuilder < Builder + + def initialize(target = "armv7a") + super() + @target = target + @sourcesDir = Config.opensslSourcesRoot + @buildDir = Config.buildRoot + "/openssl/" + @target + @installDir = Config.installRoot + "/openssl/" + @target + end + + def checkout + url = "https://github.com/openssl/openssl/archive/OpenSSL_1_1_1a.tar.gz" + if File.exist? Config.opensslSourcesRoot + message "Seems URL \"#{url}\" already downloaded and unpacked to \"#{Config.opensslSourcesRoot}\"." + return + end + execute "cd #{Config.sourcesRoot} && curl -O -J -L #{url}" + execute "cd #{Config.sourcesRoot} && tar -xzf openssl-*.tar.gz" + unpackedDir = Dir[Config.sourcesRoot + "/openssl-*"].select { |dir| File.directory?(dir) }.first + if !unpackedDir.nil? + File.rename(unpackedDir, Config.opensslSourcesRoot) + end + end + + def prepare + execute "mkdir -p #{@buildDir}" + execute "mkdir -p #{@installDir}" + end + + def configure + execute commonArgs.join(" ") + " ./Configure -D__ANDROID_API__=#{Config.androidAPI} --prefix=#{@installDir} android-arm" + end + + def commonArgs() + ndkToolchainPath = "#{Config.ndkInstallRoot}/#{@target}" + ndkToolchainBinPath = "#{ndkToolchainPath}/bin" + archFlags = "-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16" + ldFlags = "-march=armv7-a -Wl,--fix-cortex-a8" + cmd = ["cd #{@sourcesDir} &&"] + cmd << "ANDROID_NDK=#{ndkToolchainPath}" + cmd << "PATH=#{ndkToolchainBinPath}:$PATH" + # >> 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}\"" + # << + return cmd + end + + def build + execute commonArgs.join(" ") + " make -j4" + execute commonArgs.join(" ") + " make install" + end + + def make + checkout + prepare + configure + build + end + +end diff --git a/Scripts/Common/Config.rb b/Scripts/Common/Config.rb index dfc7232b..8cc877ec 100755 --- a/Scripts/Common/Config.rb +++ b/Scripts/Common/Config.rb @@ -34,6 +34,10 @@ def self.curlSourcesRoot return "#{sourcesRoot}/curl" end + def self.opensslSourcesRoot + return "#{sourcesRoot}/openssl" + end + def self.sourcesRoot return "#{rootDirPath}/Sources" end diff --git a/Scripts/Shell/bootstrap.sh b/Scripts/Shell/bootstrap.sh index fe760887..367f63bf 100755 --- a/Scripts/Shell/bootstrap.sh +++ b/Scripts/Shell/bootstrap.sh @@ -8,7 +8,7 @@ $SA_CMD # Swift dependencies echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" -SA_CMD="sudo apt-get install ruby cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev systemtap-sdt-dev tzdata rsync libz3-dev" +SA_CMD="sudo apt-get install ruby cmake ninja-build clang python autoconf libtool uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev systemtap-sdt-dev tzdata rsync libz3-dev" echo "Executing command: \"$SA_CMD\"" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" $SA_CMD diff --git a/Sources/.gitignore b/Sources/.gitignore index e385402b..6ec84a6b 100644 --- a/Sources/.gitignore +++ b/Sources/.gitignore @@ -1,3 +1,4 @@ /*/ /*.zip /*.tgz +/*.tar.gz From e14f86aec79959dd6cbe85e86d4e0109ef1b5297 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Thu, 13 Dec 2018 15:18:53 +0100 Subject: [PATCH 05/66] Scripts update. --- .rubocop.yml | 3 ++ Rakefile | 15 +++++++ Scripts/Builders/OpenSSLBuilder.rb | 13 +----- Scripts/Builders/XMLBuilder.rb | 67 ++++++++++++++++++++++++++++++ Scripts/Common/Builder.rb | 2 +- Scripts/Common/Config.rb | 4 ++ Scripts/Common/Downloader.rb | 56 +++++++++++++++++++++++++ Sources/Readme.md | 2 +- 8 files changed, 149 insertions(+), 13 deletions(-) create mode 100644 Scripts/Builders/XMLBuilder.rb create mode 100644 Scripts/Common/Downloader.rb diff --git a/.rubocop.yml b/.rubocop.yml index 8e2659b1..45906546 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -74,6 +74,9 @@ Naming/VariableName: Naming/MethodName: Enabled: false +Style/InverseMethods: + Enabled: false + Layout/EmptyLinesAroundBlockBody: Enabled: false diff --git a/Rakefile b/Rakefile index a2621473..0da8d403 100755 --- a/Rakefile +++ b/Rakefile @@ -6,6 +6,7 @@ require_relative "Scripts/Builders/SwiftBuilder.rb" require_relative "Scripts/Builders/FoundationBuilder.rb" require_relative "Scripts/Builders/CurlBuilder.rb" require_relative "Scripts/Builders/OpenSSLBuilder.rb" +require_relative "Scripts/Builders/XMLBuilder.rb" require_relative "Scripts/Builders/HelloProjectBuilder.rb" require_relative "Scripts/ADBHelper.rb" @@ -146,6 +147,20 @@ namespace :foundation do end +namespace :xml do + + desc "Checkout libXML" + task :checkout do + XMLBuilder.new().checkout + end + + desc "Build libXML" + task :make do + XMLBuilder.new().make + end + +end + namespace :curl do desc "Checkout curl" diff --git a/Scripts/Builders/OpenSSLBuilder.rb b/Scripts/Builders/OpenSSLBuilder.rb index 39726f3a..7d495ad9 100644 --- a/Scripts/Builders/OpenSSLBuilder.rb +++ b/Scripts/Builders/OpenSSLBuilder.rb @@ -15,17 +15,8 @@ def initialize(target = "armv7a") end def checkout - url = "https://github.com/openssl/openssl/archive/OpenSSL_1_1_1a.tar.gz" - if File.exist? Config.opensslSourcesRoot - message "Seems URL \"#{url}\" already downloaded and unpacked to \"#{Config.opensslSourcesRoot}\"." - return - end - execute "cd #{Config.sourcesRoot} && curl -O -J -L #{url}" - execute "cd #{Config.sourcesRoot} && tar -xzf openssl-*.tar.gz" - unpackedDir = Dir[Config.sourcesRoot + "/openssl-*"].select { |dir| File.directory?(dir) }.first - if !unpackedDir.nil? - File.rename(unpackedDir, Config.opensslSourcesRoot) - end + downloader = Downloader.new(Config.sourcesRoot, Config.opensslSourcesRoot, "https://github.com/openssl/openssl/archive/OpenSSL_1_1_1a.tar.gz", 'openssl-*') + downloader.bootstrap() end def prepare diff --git a/Scripts/Builders/XMLBuilder.rb b/Scripts/Builders/XMLBuilder.rb new file mode 100644 index 00000000..8a6938c7 --- /dev/null +++ b/Scripts/Builders/XMLBuilder.rb @@ -0,0 +1,67 @@ +require_relative "../Common/Builder.rb" +require_relative "../Common/Config.rb" +require_relative "../Common/Downloader.rb" + +class XMLBuilder < Builder + + def initialize(target = "armv7a") + super() + @target = target + @sourcesDir = Config.xmlSourcesRoot + @buildDir = Config.buildRoot + "/xml/" + @target + @installDir = Config.installRoot + "/xml/" + @target + end + + def checkout + downloader = Downloader.new(Config.sourcesRoot, Config.xmlSourcesRoot, "https://github.com/GNOME/libxml2/archive/v2.9.8.tar.gz", 'libxml2-*') + downloader.bootstrap() + end + + def prepare + execute "mkdir -p #{@buildDir}" + execute "mkdir -p #{@installDir}" + end + + def configure + # Arguments took from `swift/swift-corelibs-foundation/build-android` + ndkToolchainPath = "#{Config.ndkInstallRoot}/#{@target}" + ndkToolchainBinPath = "#{ndkToolchainPath}/bin" + ndkToolchainSysPath = "#{ndkToolchainPath}/sysroot" + 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 << "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\"" + cmd << "CFLAGS=\"#{archFlags} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing\"" + cmd << "LDFLAGS=\"#{ldFlags}\"" + + 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" + execute cmd.join(" ") + " ./configure " + args + end + + def build + execute "cd #{@sourcesDir} && make libxml2.la" + execute "cd #{@sourcesDir} && make install-libLTLIBRARIES" + execute "cd #{@sourcesDir}/include && make install" + end + + def make + checkout + prepare + configure + build + end + +end diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index 32354cd1..308d8bc6 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -1,4 +1,4 @@ -require_relative "../Common/Tool.rb" +require_relative "Tool.rb" class Builder < Tool diff --git a/Scripts/Common/Config.rb b/Scripts/Common/Config.rb index 8cc877ec..b9bc61cd 100755 --- a/Scripts/Common/Config.rb +++ b/Scripts/Common/Config.rb @@ -38,6 +38,10 @@ def self.opensslSourcesRoot return "#{sourcesRoot}/openssl" end + def self.xmlSourcesRoot + return "#{sourcesRoot}/xml" + end + def self.sourcesRoot return "#{rootDirPath}/Sources" end diff --git a/Scripts/Common/Downloader.rb b/Scripts/Common/Downloader.rb new file mode 100644 index 00000000..59ede0b6 --- /dev/null +++ b/Scripts/Common/Downloader.rb @@ -0,0 +1,56 @@ +require_relative "Tool.rb" + +class Downloader < Tool + + def initialize(downloadsDirPath, destinationDirPath, url, downloadedFileNameMask) + @downloads = downloadsDirPath + @destination = destinationDirPath + @url = url + @fileNameMask = downloadedFileNameMask + end + + def bootstrap() + downloadIfNeeded() + unpackIfNeeded() + end + + def unpack() + if archive.end_with? ".tar.gz" + execute "cd #{@downloads} && tar -xzf \"#{archive}\"" + else + raise "Don't know how to unpack file \"#{archive}\"." + end + unpackedDir = Dir[@downloads + "/" + @fileNameMask].select { |dir| File.directory?(dir) }.first + if !unpackedDir.nil? + File.rename(unpackedDir, @destination) + end + end + + def unpackIfNeeded() + if File.exist?(@destination) + message "Seems URL \"#{@url}\" already downloaded and unpacked to \"#{@destination}\"." + return + end + unpack() + end + + def download() + execute "cd \"#{@downloads}\" && curl -O -J -L #{@url}" + end + + def downloadIfNeeded() + if !archive.nil? + message "Seems URL \"#{@url}\" already downloaded to \"#{archive}\"." + return + end + download() + end + + def archive + if @archive.nil? + @archive = Dir[@downloads + "/" + @fileNameMask].select { |file| !File.directory?(file) }.first + end + return @archive + end + +end diff --git a/Sources/Readme.md b/Sources/Readme.md index 27b63635..24eb86ee 100644 --- a/Sources/Readme.md +++ b/Sources/Readme.md @@ -1 +1 @@ -# Put downloaded Swift, ICU sources and Android NDK here +# Swift, ICU, libXML, ... sources and Android NDK will be extracted here. From 5105fc833b40f9eab51fb047b0c4243706778025 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Thu, 13 Dec 2018 15:20:17 +0100 Subject: [PATCH 06/66] Readme file update. --- Downloads/.gitignore | 4 ++++ Downloads/Readme.md | 1 + 2 files changed, 5 insertions(+) create mode 100644 Downloads/.gitignore create mode 100644 Downloads/Readme.md diff --git a/Downloads/.gitignore b/Downloads/.gitignore new file mode 100644 index 00000000..6ec84a6b --- /dev/null +++ b/Downloads/.gitignore @@ -0,0 +1,4 @@ +/*/ +/*.zip +/*.tgz +/*.tar.gz diff --git a/Downloads/Readme.md b/Downloads/Readme.md new file mode 100644 index 00000000..8935dd0e --- /dev/null +++ b/Downloads/Readme.md @@ -0,0 +1 @@ +# Automatically or Manually downloadded ICU, libXML, ... and Android NDK archives will be placed here From bab0c92cb2f0a3cd8d3cf3049cb92aa7753e72f8 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Thu, 13 Dec 2018 16:46:54 +0100 Subject: [PATCH 07/66] Scripts update. --- Rakefile | 12 ++++++++- Scripts/Builders/CurlBuilder.rb | 6 ++--- Scripts/Builders/DispatchBuilder.rb | 41 +++++++++++++++++++++++++++++ Scripts/Common/Config.rb | 24 +++++++++++------ Vagrantfile | 2 ++ 5 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 Scripts/Builders/DispatchBuilder.rb diff --git a/Rakefile b/Rakefile index 0da8d403..4eb1f94e 100755 --- a/Rakefile +++ b/Rakefile @@ -4,6 +4,7 @@ require_relative "Scripts/Builders/ICUBuilder.rb" require_relative "Scripts/Builders/AndroidBuilder.rb" require_relative "Scripts/Builders/SwiftBuilder.rb" require_relative "Scripts/Builders/FoundationBuilder.rb" +require_relative "Scripts/Builders/DispatchBuilder.rb" require_relative "Scripts/Builders/CurlBuilder.rb" require_relative "Scripts/Builders/OpenSSLBuilder.rb" require_relative "Scripts/Builders/XMLBuilder.rb" @@ -140,13 +141,22 @@ end namespace :foundation do - desc "Builds libFoundation for Android" + desc "Build libFoundation" task :build do FoundationBuilder.new().make end end +namespace :dispatch do + + desc "Build libDispatch" + task :build do + DispatchBuilder.new().make + end + +end + namespace :xml do desc "Checkout libXML" diff --git a/Scripts/Builders/CurlBuilder.rb b/Scripts/Builders/CurlBuilder.rb index aeb6c4c0..78cd8e6d 100644 --- a/Scripts/Builders/CurlBuilder.rb +++ b/Scripts/Builders/CurlBuilder.rb @@ -62,9 +62,9 @@ def build end def make - # checkout - # prepare - # configure + checkout + prepare + configure build end diff --git a/Scripts/Builders/DispatchBuilder.rb b/Scripts/Builders/DispatchBuilder.rb new file mode 100644 index 00000000..dcd62b4f --- /dev/null +++ b/Scripts/Builders/DispatchBuilder.rb @@ -0,0 +1,41 @@ +require_relative "../Common/Builder.rb" +require_relative "../Common/Config.rb" + +# See: +# - Dispatch build script: https://github.com/readdle/swift-android-toolchain/blob/master/build/Linux/040_build_corelibs_libdispatch.sh +class DispatchBuilder < Builder + + def initialize(target = "armv7a") + super() + @target = target + @sourcesDir = Config.swiftSourcesRoot + "/swift-corelibs-libdispatch" + @buildDir = Config.buildRoot + "/dispatch/" + @target + @installDir = Config.installRoot + "/dispatch/" + @target + end + + def prepare + execute "mkdir -p #{@buildDir}" + execute "mkdir -p #{@installDir}" + end + + def configure + # See: /swift/swift-corelibs-libdispatch/INSTALL.md + cmd = [] + cmd << "cd #{@buildDir} &&" + cmd << "cmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++" + cmd << "-DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=#{Config.androidAPI} -DCMAKE_ANDROID_NDK=#{Config.ndkSourcesRoot}" + cmd << @sourcesDir + execute cmd.join(" ") + end + + def build + # ninja + end + + def make + prepare + configure + build + end + +end diff --git a/Scripts/Common/Config.rb b/Scripts/Common/Config.rb index b9bc61cd..e20ea766 100755 --- a/Scripts/Common/Config.rb +++ b/Scripts/Common/Config.rb @@ -1,13 +1,5 @@ class Config - def self.androidAPI - return "21" - end - - def self.rootDirPath - return File.realpath(File.dirname(__FILE__) + "/../../") - end - def self.verify puts "- Project Root Path: \t\"#{rootDirPath}\"" puts "- Android NDK Path: \t\"#{ndkSourcesRoot}\"" @@ -18,6 +10,16 @@ def self.verify puts "- Install root Path: \t\"#{installRoot}\"" end + def self.androidAPI + return "21" + end + + def self.rootDirPath + return File.realpath(File.dirname(__FILE__) + "/../../") + end + + # Sources + def self.ndkSourcesRoot return "#{sourcesRoot}/android-ndk-r18b" end @@ -46,6 +48,8 @@ def self.sourcesRoot return "#{rootDirPath}/Sources" end + # Builds + def self.buildRoot return "#{rootDirPath}/Build" end @@ -54,6 +58,8 @@ def self.swiftBuildRoot return "#{buildRoot}/swift-android" end + # Install + def self.installRoot return "#{rootDirPath}/Install" end @@ -66,6 +72,8 @@ def self.icuInstallRoot return "#{installRoot}/icu" end + # Misc + def self.icuPatchesRoot return "#{rootDirPath}/Patches/icu" end diff --git a/Vagrantfile b/Vagrantfile index d0cf9864..3167eb1f 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,6 +1,8 @@ # -*- mode: ruby -*- # vi: set ft=ruby : +# See: +# - https://github.com/readdle/swift-android-toolchain/blob/master/vagrant/Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "ubuntu/bionic64" config.vm.provision :shell, inline: "echo 'source /vagrant/Scripts/Shell/environment.sh' > /etc/profile.d/sa-environment.sh", :run => 'always' From 5fe73b9080d8a46a1f6fd1b598ca60f9619f2128 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Thu, 13 Dec 2018 16:47:01 +0100 Subject: [PATCH 08/66] scripts update. --- Scripts/Builders/FoundationBuilder.rb | 49 +++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/Scripts/Builders/FoundationBuilder.rb b/Scripts/Builders/FoundationBuilder.rb index f6cb60b8..b8940317 100644 --- a/Scripts/Builders/FoundationBuilder.rb +++ b/Scripts/Builders/FoundationBuilder.rb @@ -3,8 +3,53 @@ class FoundationBuilder < Builder - def make() - puts "OK" + def initialize(target = "armv7a") + super() + @target = target + @sourcesDir = Config.swiftSourcesRoot + @buildDir = Config.buildRoot + "/foundation/" + @target + @installDir = Config.installRoot + "/foundation/" + @target + end + + def prepare + execute "mkdir -p #{@buildDir}" + execute "mkdir -p #{@installDir}" + end + + def configure + # Arguments took from `swift/swift-corelibs-foundation/build-android` + ndkToolchainPath = "#{Config.ndkInstallRoot}/#{@target}" + ndkToolchainBinPath = "#{ndkToolchainPath}/bin" + ndkToolchainSysPath = "#{ndkToolchainPath}/sysroot" + swiftBuildPath = Config.swiftBuildRoot + swiftSDKRoot = "#{swiftBuildPath}/swift-linux-x86_64" + icuRootPath = "#{Config.icuInstallRoot}/#{@target}" + cmd = [] + cmd << "cd #{@sourcesDir}/swift-corelibs-foundation &&" + cmd << "BUILD_DIR=#{@buildDir}" + cmd << "DSTROOT=#{@installDir}" + + cmd << "SWIFTC=\"#{swiftSDKRoot}/bin/swiftc\"" + cmd << "CLANG=\"#{swiftBuildPath}/llvm-linux-x86_64/bin/clang\"" + cmd << "SWIFT=\"#{swiftSDKRoot}/bin/swift\"" + cmd << "SDKROOT=\"#{swiftSDKRoot}\"" + cmd << "CFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH --sysroot=#{ndkToolchainSysPath} -I#{icuRootPath}/include -I#{swiftSDKRoot}/lib/swift -I#{Config.ndkSourcesRoot}/sources/android/support/include -I#{ndkToolchainSysPath}/usr/include -I#{@sourcesDir}/swift-corelibs-foundation/closure\"" + cmd << "SWIFTCFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH -I#{ndkToolchainSysPath}/usr/include\"" + cmd << "LDFLAGS=\"-fuse-ld=gold --sysroot=#{ndkToolchainSysPath} -L#{Config.ndkSourcesRoot}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x -L#{icuRootPath} -L#{ndkToolchainSysPath}/usr/lib -ldispatch\"" + + cmd << "./configure Release --target=armv7-none-linux-androideabi --sysroot=#{ndkToolchainSysPath}" + # cmd << "-DXCTEST_BUILD_DIR=#{swiftSDKRoot}/xctest-linux-x86_64" + cmd << "-DLIBDISPATCH_SOURCE_DIR=#{Config.swiftSourcesRoot}/swift-corelibs-libdispatch" + # cmd << "-DLIBDISPATCH_BUILD_DIR=#{Config.dispatchBuildDir}/swift-corelibs-libdispatch" #fixme + execute cmd.join(" ") + end + + def build; end + + def make + prepare + configure + build end end From a61f18a6e208fff8824a00d2442d4756a7909313 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Thu, 13 Dec 2018 18:07:57 +0100 Subject: [PATCH 09/66] Scripts update. --- Scripts/Builders/DispatchBuilder.rb | 16 ++++++++++++++-- Scripts/Shell/bootstrap.sh | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Scripts/Builders/DispatchBuilder.rb b/Scripts/Builders/DispatchBuilder.rb index dcd62b4f..e5c23d99 100644 --- a/Scripts/Builders/DispatchBuilder.rb +++ b/Scripts/Builders/DispatchBuilder.rb @@ -3,6 +3,7 @@ # See: # - Dispatch build script: https://github.com/readdle/swift-android-toolchain/blob/master/build/Linux/040_build_corelibs_libdispatch.sh +# - Cmake. Cross Compiling for Android: https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#id20 class DispatchBuilder < Builder def initialize(target = "armv7a") @@ -20,16 +21,27 @@ def prepare def configure # See: /swift/swift-corelibs-libdispatch/INSTALL.md + swiftCCRoot = "#{Config.swiftBuildRoot}/swift-linux-x86_64" + llvmCCRoot = "#{Config.swiftBuildRoot}/llvm-linux-x86_64" cmd = [] cmd << "cd #{@buildDir} &&" - cmd << "cmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++" + cmd << "CLANG=\"#{llvmCCRoot}/bin/clang\"" + cmd << "CC=\"#{llvmCCRoot}/bin/clang\"" + cmd << "CXX=\"#{llvmCCRoot}/bin/clang++\"" + cmd << "SWIFT=\"#{swiftCCRoot}/bin/swift\"" + cmd << "SWIFTC=\"#{swiftCCRoot}/bin/swiftc\"" + cmd << "cmake -G Ninja" + cmd << "-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++" + cmd << "-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a" + cmd << "-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang" + cmd << "-DCMAKE_ANDROID_STL_TYPE=\"c++_static\" -DCMAKE_BUILD_TYPE=Release" cmd << "-DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=#{Config.androidAPI} -DCMAKE_ANDROID_NDK=#{Config.ndkSourcesRoot}" cmd << @sourcesDir execute cmd.join(" ") end def build - # ninja + execute "cd #{@buildDir} && ninja" end def make diff --git a/Scripts/Shell/bootstrap.sh b/Scripts/Shell/bootstrap.sh index 367f63bf..096d3f03 100755 --- a/Scripts/Shell/bootstrap.sh +++ b/Scripts/Shell/bootstrap.sh @@ -8,7 +8,7 @@ $SA_CMD # Swift dependencies echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" -SA_CMD="sudo apt-get install ruby cmake ninja-build clang python autoconf libtool uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev systemtap-sdt-dev tzdata rsync libz3-dev" +SA_CMD="sudo apt-get install mc ruby cmake ninja-build clang python autoconf libtool uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev systemtap-sdt-dev tzdata rsync libz3-dev" echo "Executing command: \"$SA_CMD\"" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" $SA_CMD From b1c50a9d16988bf2b8431cdf3e2d039b0e767932 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Thu, 13 Dec 2018 18:32:42 +0100 Subject: [PATCH 10/66] Scripts update. --- Scripts/Builders/DispatchBuilder.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Scripts/Builders/DispatchBuilder.rb b/Scripts/Builders/DispatchBuilder.rb index e5c23d99..8a711654 100644 --- a/Scripts/Builders/DispatchBuilder.rb +++ b/Scripts/Builders/DispatchBuilder.rb @@ -31,7 +31,7 @@ def configure cmd << "SWIFT=\"#{swiftCCRoot}/bin/swift\"" cmd << "SWIFTC=\"#{swiftCCRoot}/bin/swiftc\"" cmd << "cmake -G Ninja" - cmd << "-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++" + cmd << "-DCMAKE_C_COMPILER=#{llvmCCRoot}/bin/clang -DCMAKE_CXX_COMPILER=#{llvmCCRoot}/bin/clang++" cmd << "-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a" cmd << "-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang" cmd << "-DCMAKE_ANDROID_STL_TYPE=\"c++_static\" -DCMAKE_BUILD_TYPE=Release" @@ -42,6 +42,8 @@ def configure def build execute "cd #{@buildDir} && ninja" + # See: What is CMake equivalent of 'configure --prefix=DIR && make all install: https://stackoverflow.com/a/35753015/1418981 + execute "cd #{@buildDir} && cmake -DCMAKE_INSTALL_PREFIX=#{@installDir} . && ninja install" end def make From 33c2c90f341a72d844bfe77b7571289871fc297a Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Thu, 13 Dec 2018 18:52:28 +0100 Subject: [PATCH 11/66] Scripts update. --- Scripts/Builders/DispatchBuilder.rb | 2 +- Scripts/Builders/FoundationBuilder.rb | 10 ++++++---- Scripts/Common/Config.rb | 4 ++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Scripts/Builders/DispatchBuilder.rb b/Scripts/Builders/DispatchBuilder.rb index 8a711654..0dd59231 100644 --- a/Scripts/Builders/DispatchBuilder.rb +++ b/Scripts/Builders/DispatchBuilder.rb @@ -11,7 +11,7 @@ def initialize(target = "armv7a") @target = target @sourcesDir = Config.swiftSourcesRoot + "/swift-corelibs-libdispatch" @buildDir = Config.buildRoot + "/dispatch/" + @target - @installDir = Config.installRoot + "/dispatch/" + @target + @installDir = Config.dispatchInstallRoot + "/" + @target end def prepare diff --git a/Scripts/Builders/FoundationBuilder.rb b/Scripts/Builders/FoundationBuilder.rb index b8940317..2402aac2 100644 --- a/Scripts/Builders/FoundationBuilder.rb +++ b/Scripts/Builders/FoundationBuilder.rb @@ -6,7 +6,7 @@ class FoundationBuilder < Builder def initialize(target = "armv7a") super() @target = target - @sourcesDir = Config.swiftSourcesRoot + @sourcesDir = Config.swiftSourcesRoot + "/swift-corelibs-foundation" @buildDir = Config.buildRoot + "/foundation/" + @target @installDir = Config.installRoot + "/foundation/" + @target end @@ -25,7 +25,7 @@ def configure swiftSDKRoot = "#{swiftBuildPath}/swift-linux-x86_64" icuRootPath = "#{Config.icuInstallRoot}/#{@target}" cmd = [] - cmd << "cd #{@sourcesDir}/swift-corelibs-foundation &&" + cmd << "cd #{@sourcesDir} &&" cmd << "BUILD_DIR=#{@buildDir}" cmd << "DSTROOT=#{@installDir}" @@ -40,11 +40,13 @@ def configure cmd << "./configure Release --target=armv7-none-linux-androideabi --sysroot=#{ndkToolchainSysPath}" # cmd << "-DXCTEST_BUILD_DIR=#{swiftSDKRoot}/xctest-linux-x86_64" cmd << "-DLIBDISPATCH_SOURCE_DIR=#{Config.swiftSourcesRoot}/swift-corelibs-libdispatch" - # cmd << "-DLIBDISPATCH_BUILD_DIR=#{Config.dispatchBuildDir}/swift-corelibs-libdispatch" #fixme + cmd << "-DLIBDISPATCH_BUILD_DIR=#{Config.dispatchInstallRoot}/swift-corelibs-libdispatch" execute cmd.join(" ") end - def build; end + def build + execute "cd #{@sourcesDir} && ninja" + end def make prepare diff --git a/Scripts/Common/Config.rb b/Scripts/Common/Config.rb index e20ea766..e3db2682 100755 --- a/Scripts/Common/Config.rb +++ b/Scripts/Common/Config.rb @@ -68,6 +68,10 @@ def self.ndkInstallRoot return "#{installRoot}/android" end + def self.dispatchInstallRoot + return "#{installRoot}/dispatch" + end + def self.icuInstallRoot return "#{installRoot}/icu" end From 6964212c3c8762a89d02ce9278d92cb42b33bce9 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Thu, 13 Dec 2018 23:59:06 +0100 Subject: [PATCH 12/66] Scripts update. --- Scripts/Builders/FoundationBuilder.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Scripts/Builders/FoundationBuilder.rb b/Scripts/Builders/FoundationBuilder.rb index 2402aac2..86cb20c1 100644 --- a/Scripts/Builders/FoundationBuilder.rb +++ b/Scripts/Builders/FoundationBuilder.rb @@ -22,25 +22,27 @@ def configure ndkToolchainBinPath = "#{ndkToolchainPath}/bin" ndkToolchainSysPath = "#{ndkToolchainPath}/sysroot" swiftBuildPath = Config.swiftBuildRoot - swiftSDKRoot = "#{swiftBuildPath}/swift-linux-x86_64" + swiftCCRoot = "#{Config.swiftBuildRoot}/swift-linux-x86_64" + llvmCCRoot = "#{Config.swiftBuildRoot}/llvm-linux-x86_64" icuRootPath = "#{Config.icuInstallRoot}/#{@target}" cmd = [] cmd << "cd #{@sourcesDir} &&" cmd << "BUILD_DIR=#{@buildDir}" cmd << "DSTROOT=#{@installDir}" - cmd << "SWIFTC=\"#{swiftSDKRoot}/bin/swiftc\"" - cmd << "CLANG=\"#{swiftBuildPath}/llvm-linux-x86_64/bin/clang\"" - cmd << "SWIFT=\"#{swiftSDKRoot}/bin/swift\"" - cmd << "SDKROOT=\"#{swiftSDKRoot}\"" - cmd << "CFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH --sysroot=#{ndkToolchainSysPath} -I#{icuRootPath}/include -I#{swiftSDKRoot}/lib/swift -I#{Config.ndkSourcesRoot}/sources/android/support/include -I#{ndkToolchainSysPath}/usr/include -I#{@sourcesDir}/swift-corelibs-foundation/closure\"" + cmd << "SWIFTC=\"#{swiftCCRoot}/bin/swiftc\"" + cmd << "CLANG=\"#{llvmCCRoot}/bin/clang\"" + cmd << "CLANGXX=\"#{llvmCCRoot}/bin/clang++\"" + cmd << "SWIFT=\"#{swiftCCRoot}/bin/swift\"" + cmd << "SDKROOT=\"#{swiftCCRoot}\"" + cmd << "CFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH --sysroot=#{ndkToolchainSysPath} -I#{icuRootPath}/include -I#{swiftCCRoot}/lib/swift -I#{Config.ndkSourcesRoot}/sources/android/support/include -I#{ndkToolchainSysPath}/usr/include -I#{@sourcesDir}/closure\"" cmd << "SWIFTCFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH -I#{ndkToolchainSysPath}/usr/include\"" - cmd << "LDFLAGS=\"-fuse-ld=gold --sysroot=#{ndkToolchainSysPath} -L#{Config.ndkSourcesRoot}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x -L#{icuRootPath} -L#{ndkToolchainSysPath}/usr/lib -ldispatch\"" + cmd << "LDFLAGS=\"-fuse-ld=gold --sysroot=#{ndkToolchainSysPath} -L#{Config.ndkSourcesRoot}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x -L#{icuRootPath}/lib -L#{ndkToolchainSysPath}/usr/lib -ldispatch\"" cmd << "./configure Release --target=armv7-none-linux-androideabi --sysroot=#{ndkToolchainSysPath}" - # cmd << "-DXCTEST_BUILD_DIR=#{swiftSDKRoot}/xctest-linux-x86_64" + # cmd << "-DXCTEST_BUILD_DIR=#{swiftCCRoot}/xctest-linux-x86_64" cmd << "-DLIBDISPATCH_SOURCE_DIR=#{Config.swiftSourcesRoot}/swift-corelibs-libdispatch" - cmd << "-DLIBDISPATCH_BUILD_DIR=#{Config.dispatchInstallRoot}/swift-corelibs-libdispatch" + cmd << "-DLIBDISPATCH_BUILD_DIR=#{Config.dispatchInstallRoot}/#{@target}" execute cmd.join(" ") end From e13aa826d212d35d17a84dc2880389ad141e23fe Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Fri, 14 Dec 2018 15:43:44 +0100 Subject: [PATCH 13/66] Scripts update. --- .../MissedLocaleHeaders.patch | 14 ++++ Patches/swift-corelibs-foundation/Readme.txt | 1 + Scripts/Builders/FoundationBuilder.rb | 68 +++++++++++++++---- Scripts/Common/Config.rb | 8 +++ 4 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 Patches/swift-corelibs-foundation/MissedLocaleHeaders.patch create mode 100644 Patches/swift-corelibs-foundation/Readme.txt diff --git a/Patches/swift-corelibs-foundation/MissedLocaleHeaders.patch b/Patches/swift-corelibs-foundation/MissedLocaleHeaders.patch new file mode 100644 index 00000000..211efd38 --- /dev/null +++ b/Patches/swift-corelibs-foundation/MissedLocaleHeaders.patch @@ -0,0 +1,14 @@ +diff --git a/build.py b/build.py +index 8ee475f374dbb2cf479d7447c953719643bf8075..b228a4dcc6fd4c04619e03d22ff32bbd93d076e9 100755 +--- a/build.py ++++ b/build.py +@@ -211,6 +211,9 @@ private = [ + 'CoreFoundation/PlugIn.subproj/CFBundle_BinaryTypes.h', + 'CoreFoundation/Locale.subproj/CFICULogging.h', + 'CoreFoundation/Locale.subproj/CFLocaleInternal.h', ++ 'CoreFoundation/Locale.subproj/CFCalendar_Internal.h', ++ 'CoreFoundation/Locale.subproj/CFDateComponents.h', ++ 'CoreFoundation/Locale.subproj/CFDateInterval.h', + 'CoreFoundation/StringEncodings.subproj/CFUnicodePrecomposition.h', + 'CoreFoundation/Base.subproj/CFPriv.h', + 'CoreFoundation/StringEncodings.subproj/CFUniCharPriv.h', diff --git a/Patches/swift-corelibs-foundation/Readme.txt b/Patches/swift-corelibs-foundation/Readme.txt new file mode 100644 index 00000000..3cf5f5f2 --- /dev/null +++ b/Patches/swift-corelibs-foundation/Readme.txt @@ -0,0 +1 @@ +Bugreport: https://bugs.swift.org/browse/SR-9513 \ No newline at end of file diff --git a/Scripts/Builders/FoundationBuilder.rb b/Scripts/Builders/FoundationBuilder.rb index 86cb20c1..60252454 100644 --- a/Scripts/Builders/FoundationBuilder.rb +++ b/Scripts/Builders/FoundationBuilder.rb @@ -1,6 +1,8 @@ require_relative "../Common/Builder.rb" require_relative "../Common/Config.rb" +# See: +# - Libdispatch issues with CMake: https://forums.swift.org/t/libdispatch-switched-to-cmake/6665/7 class FoundationBuilder < Builder def initialize(target = "armv7a") @@ -9,45 +11,87 @@ def initialize(target = "armv7a") @sourcesDir = Config.swiftSourcesRoot + "/swift-corelibs-foundation" @buildDir = Config.buildRoot + "/foundation/" + @target @installDir = Config.installRoot + "/foundation/" + @target + + @ndkToolchainPath = "#{Config.ndkInstallRoot}/#{@target}" + @ndkToolchainBinPath = "#{@ndkToolchainPath}/bin" + @ndkToolchainSysPath = "#{@ndkToolchainPath}/sysroot" end def prepare execute "mkdir -p #{@buildDir}" execute "mkdir -p #{@installDir}" + + # Copy dispatch public and private headers to the directory foundation is expecting to get it + targetDir = "#{@ndkToolchainSysPath}/usr/include/dispatch" + execute "mkdir -p #{targetDir}" + execute "cp -v #{Config.swiftSourcesRoot}/swift-corelibs-libdispatch/dispatch/*.h #{targetDir}" + execute "cp -v #{Config.swiftSourcesRoot}/swift-corelibs-libdispatch/private/*.h #{targetDir}" + + # libFoundation script is not completely prepared to handle cross compilation yet. + execute "ln -svf #{Config.swiftBuildRoot}/swift-linux-x86_64/lib/swift #{@ndkToolchainSysPath}/usr/lib/" + execute "cp -vr #{Config.swiftBuildRoot}/swift-linux-x86_64/lib/swift/android/armv7/* #{Config.swiftBuildRoot}/swift-linux-x86_64/lib/swift/android/" + + # Search path for curl seems to be wrong in foundation + execute "cp -rv #{Config.curlInstallRoot}/#{@target}/include/curl #{@ndkToolchainSysPath}/usr/include" + execute "ln -fvs #{@ndkToolchainSysPath}/usr/include/curl #{@ndkToolchainSysPath}/usr/include/curl/curl" + + execute "cp -rv #{Config.xmlInstallRoot}/#{@target}/include/libxml2 #{@ndkToolchainSysPath}/usr/include" + execute "ln -fvs #{@ndkToolchainSysPath}/usr/include/libxml2/libxml #{@ndkToolchainSysPath}/usr/include/libxml" + + execute "cp -vr /usr/include/uuid #{@ndkToolchainSysPath}/usr/include" end - def configure + def args # Arguments took from `swift/swift-corelibs-foundation/build-android` - ndkToolchainPath = "#{Config.ndkInstallRoot}/#{@target}" - ndkToolchainBinPath = "#{ndkToolchainPath}/bin" - ndkToolchainSysPath = "#{ndkToolchainPath}/sysroot" - swiftBuildPath = Config.swiftBuildRoot swiftCCRoot = "#{Config.swiftBuildRoot}/swift-linux-x86_64" llvmCCRoot = "#{Config.swiftBuildRoot}/llvm-linux-x86_64" icuRootPath = "#{Config.icuInstallRoot}/#{@target}" cmd = [] - cmd << "cd #{@sourcesDir} &&" + cmd << "cd #{@sourcesDir} && env" cmd << "BUILD_DIR=#{@buildDir}" cmd << "DSTROOT=#{@installDir}" cmd << "SWIFTC=\"#{swiftCCRoot}/bin/swiftc\"" cmd << "CLANG=\"#{llvmCCRoot}/bin/clang\"" - cmd << "CLANGXX=\"#{llvmCCRoot}/bin/clang++\"" + # cmd << "CLANGXX=\"#{llvmCCRoot}/bin/clang++\"" cmd << "SWIFT=\"#{swiftCCRoot}/bin/swift\"" cmd << "SDKROOT=\"#{swiftCCRoot}\"" - cmd << "CFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH --sysroot=#{ndkToolchainSysPath} -I#{icuRootPath}/include -I#{swiftCCRoot}/lib/swift -I#{Config.ndkSourcesRoot}/sources/android/support/include -I#{ndkToolchainSysPath}/usr/include -I#{@sourcesDir}/closure\"" - cmd << "SWIFTCFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH -I#{ndkToolchainSysPath}/usr/include\"" - cmd << "LDFLAGS=\"-fuse-ld=gold --sysroot=#{ndkToolchainSysPath} -L#{Config.ndkSourcesRoot}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x -L#{icuRootPath}/lib -L#{ndkToolchainSysPath}/usr/lib -ldispatch\"" + cmd << "CFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH --sysroot=#{@ndkToolchainSysPath} -I#{icuRootPath}/include -I#{swiftCCRoot}/lib/swift -I#{Config.ndkSourcesRoot}/sources/android/support/include -I#{@ndkToolchainSysPath}/usr/include -I#{@sourcesDir}/closure\"" + cmd << "SWIFTCFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH -Xcc -DDEPLOYMENT_TARGET_ANDROID -I#{@ndkToolchainSysPath}/usr/include\"" + cmd << "LDFLAGS=\"-fuse-ld=gold --sysroot=#{@ndkToolchainSysPath} -L#{Config.ndkSourcesRoot}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x -L#{icuRootPath}/lib -L#{@ndkToolchainSysPath}/usr/lib -ldispatch\"" + return cmd + end - cmd << "./configure Release --target=armv7-none-linux-androideabi --sysroot=#{ndkToolchainSysPath}" + def configure + cmd = args + cmd << "./configure Release --target=armv7-none-linux-androideabi --sysroot=#{@ndkToolchainSysPath}" # cmd << "-DXCTEST_BUILD_DIR=#{swiftCCRoot}/xctest-linux-x86_64" cmd << "-DLIBDISPATCH_SOURCE_DIR=#{Config.swiftSourcesRoot}/swift-corelibs-libdispatch" cmd << "-DLIBDISPATCH_BUILD_DIR=#{Config.dispatchInstallRoot}/#{@target}" execute cmd.join(" ") + + execute "cd #{@sourcesDir} && sed --in-place 's/-I\\/usr\\/include\\/x86_64-linux-gnu//' build.ninja" + execute "cd #{@sourcesDir} && sed --in-place 's/-I\\/usr\\/include\\/libxml2//' build.ninja" + execute "cd #{@sourcesDir} && sed --in-place 's/-I.\\///' build.ninja" + execute "cd #{@sourcesDir} && sed --in-place 's/-licui18n/-licui18nswift/g' build.ninja" + execute "cd #{@sourcesDir} && sed --in-place 's/-licuuc/-licuucswift/g' build.ninja" + execute "cd #{@sourcesDir} && sed --in-place 's/-licudata/-licudataswift/g' build.ninja" end def build - execute "cd #{@sourcesDir} && ninja" + execute args.join(" ") + " ninja CopyHeaders" + + # Patching module.modulemap file. + message "Patching module.modulemap file." + headersPath = "#{@buildDir}/Foundation/usr/lib/swift/CoreFoundation" + moduleMapPath = headersPath + "/module.modulemap" + contents = File.readlines(moduleMapPath).join() + contents = contents.sub('"CoreFoundation.h"', '"' + headersPath + '/CoreFoundation.h"') + contents = contents.sub('"CFPlugInCOM.h"', '"' + headersPath + '/CFPlugInCOM.h"') + File.write(moduleMapPath, contents) + + # Running build. + execute args.join(" ") + " ninja" end def make diff --git a/Scripts/Common/Config.rb b/Scripts/Common/Config.rb index e3db2682..b8910168 100755 --- a/Scripts/Common/Config.rb +++ b/Scripts/Common/Config.rb @@ -76,6 +76,14 @@ def self.icuInstallRoot return "#{installRoot}/icu" end + def self.curlInstallRoot + return "#{installRoot}/curl" + end + + def self.xmlInstallRoot + return "#{installRoot}/xml" + end + # Misc def self.icuPatchesRoot From 09877bf4079dda3fa112c8fa3af2cdb21912ffb6 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Fri, 14 Dec 2018 17:02:01 +0100 Subject: [PATCH 14/66] Scripts update. --- .../CmakeSystemProcessor.patch | 13 +++++++++++++ Rakefile | 9 +++++++++ Scripts/Builders/DispatchBuilder.rb | 8 ++++++++ Scripts/Common/Tool.rb | 11 ++++++++++- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 Patches/swift-corelibs-libdispatch/CmakeSystemProcessor.patch diff --git a/Patches/swift-corelibs-libdispatch/CmakeSystemProcessor.patch b/Patches/swift-corelibs-libdispatch/CmakeSystemProcessor.patch new file mode 100644 index 00000000..e0ea67be --- /dev/null +++ b/Patches/swift-corelibs-libdispatch/CmakeSystemProcessor.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake +index 60f8b45a33e1546dce4aa2b30d3f9070f7b37ab9..14b4e950210f72321f1418531687ad67fc44e7a2 100644 +--- a/cmake/modules/SwiftSupport.cmake ++++ b/cmake/modules/SwiftSupport.cmake +@@ -228,6 +228,8 @@ function(get_swift_host_arch result_var_name) + set("${result_var_name}" "s390x" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l") + set("${result_var_name}" "armv6" PARENT_SCOPE) ++ elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a") ++ set("${result_var_name}" "armv7" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l") + set("${result_var_name}" "armv7" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64") diff --git a/Rakefile b/Rakefile index 4eb1f94e..a7e3778e 100755 --- a/Rakefile +++ b/Rakefile @@ -155,6 +155,15 @@ namespace :dispatch do DispatchBuilder.new().make end + desc "Clean libDispatch" + task :clean do + DispatchBuilder.new().clean + end + + desc "Rebuild libDispatch" + task :rebuild => [:clean, :build] do + end + end namespace :xml do diff --git a/Scripts/Builders/DispatchBuilder.rb b/Scripts/Builders/DispatchBuilder.rb index 0dd59231..83ae9bbd 100644 --- a/Scripts/Builders/DispatchBuilder.rb +++ b/Scripts/Builders/DispatchBuilder.rb @@ -35,6 +35,9 @@ def configure cmd << "-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a" cmd << "-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang" cmd << "-DCMAKE_ANDROID_STL_TYPE=\"c++_static\" -DCMAKE_BUILD_TYPE=Release" + cmd << "-DENABLE_SWIFT=true" + cmd << "-DCMAKE_SWIFT_COMPILER=\"#{swiftCCRoot}/bin/swift\"" + cmd << "-DCMAKE_PREFIX_PATH=\"#{swiftCCRoot}/lib/cmake/swift\"" cmd << "-DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=#{Config.androidAPI} -DCMAKE_ANDROID_NDK=#{Config.ndkSourcesRoot}" cmd << @sourcesDir execute cmd.join(" ") @@ -52,4 +55,9 @@ def make build end + def clean + execute "rm -rf \"#{@buildDir}\"" + execute "rm -rf \"#{@installDir}\"" + end + end diff --git a/Scripts/Common/Tool.rb b/Scripts/Common/Tool.rb index 0999277a..42b73352 100755 --- a/Scripts/Common/Tool.rb +++ b/Scripts/Common/Tool.rb @@ -5,11 +5,20 @@ class Tool def execute(command) puts "\e[32m#{command}\e[0m" # Print to console with Green color. - system command + if system(command) != true + message "Execution of command is failed:" + error command + puts + raise + end end def message(command) puts "\e[36m#{command}\e[0m" # Print to console with Light blue color. end + def error(command) + puts "\e[31m#{command}\e[0m" # Print to console with Light blue color. + end + end From 804382d2452c155e131fbecb62e78533cd8b4874 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Fri, 14 Dec 2018 18:10:58 +0100 Subject: [PATCH 15/66] Scripts upadte. --- Scripts/Builders/DispatchBuilder.rb | 42 ++++++++++++++++++----------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Scripts/Builders/DispatchBuilder.rb b/Scripts/Builders/DispatchBuilder.rb index 83ae9bbd..5ae4d0e3 100644 --- a/Scripts/Builders/DispatchBuilder.rb +++ b/Scripts/Builders/DispatchBuilder.rb @@ -12,6 +12,8 @@ def initialize(target = "armv7a") @sourcesDir = Config.swiftSourcesRoot + "/swift-corelibs-libdispatch" @buildDir = Config.buildRoot + "/dispatch/" + @target @installDir = Config.dispatchInstallRoot + "/" + @target + @swiftCCRoot = "#{Config.swiftBuildRoot}/swift-linux-x86_64" + @llvmCCRoot = "#{Config.swiftBuildRoot}/llvm-linux-x86_64" end def prepare @@ -19,34 +21,44 @@ def prepare execute "mkdir -p #{@installDir}" end - def configure + def args + cmd = [] + cmd << "CLANG=\"#{@llvmCCRoot}/bin/clang\"" + cmd << "CC=\"#{@llvmCCRoot}/bin/clang\"" + cmd << "CXX=\"#{@llvmCCRoot}/bin/clang++\"" + cmd << "SWIFT=\"#{@swiftCCRoot}/bin/swift\"" + cmd << "SWIFTC=\"#{@swiftCCRoot}/bin/swiftc\"" + return cmd + end + + def options # See: /swift/swift-corelibs-libdispatch/INSTALL.md - swiftCCRoot = "#{Config.swiftBuildRoot}/swift-linux-x86_64" - llvmCCRoot = "#{Config.swiftBuildRoot}/llvm-linux-x86_64" cmd = [] - cmd << "cd #{@buildDir} &&" - cmd << "CLANG=\"#{llvmCCRoot}/bin/clang\"" - cmd << "CC=\"#{llvmCCRoot}/bin/clang\"" - cmd << "CXX=\"#{llvmCCRoot}/bin/clang++\"" - cmd << "SWIFT=\"#{swiftCCRoot}/bin/swift\"" - cmd << "SWIFTC=\"#{swiftCCRoot}/bin/swiftc\"" - cmd << "cmake -G Ninja" - cmd << "-DCMAKE_C_COMPILER=#{llvmCCRoot}/bin/clang -DCMAKE_CXX_COMPILER=#{llvmCCRoot}/bin/clang++" + cmd << "-DCMAKE_C_COMPILER=#{@llvmCCRoot}/bin/clang -DCMAKE_CXX_COMPILER=#{@llvmCCRoot}/bin/clang++" cmd << "-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a" cmd << "-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang" cmd << "-DCMAKE_ANDROID_STL_TYPE=\"c++_static\" -DCMAKE_BUILD_TYPE=Release" cmd << "-DENABLE_SWIFT=true" - cmd << "-DCMAKE_SWIFT_COMPILER=\"#{swiftCCRoot}/bin/swift\"" - cmd << "-DCMAKE_PREFIX_PATH=\"#{swiftCCRoot}/lib/cmake/swift\"" + cmd << "-DCMAKE_SWIFT_COMPILER=\"#{@swiftCCRoot}/bin/swiftc\"" + cmd << "-DCMAKE_PREFIX_PATH=\"#{@swiftCCRoot}/lib/cmake/swift\"" + cmd << "-DCMAKE_INSTALL_PREFIX=#{@installDir}" cmd << "-DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=#{Config.androidAPI} -DCMAKE_ANDROID_NDK=#{Config.ndkSourcesRoot}" + return cmd + end + + def configure + cmd = [] + cmd << "cd #{@buildDir} &&" + cmd += args + cmd << "cmake -G Ninja" + cmd += options cmd << @sourcesDir execute cmd.join(" ") end def build - execute "cd #{@buildDir} && ninja" # See: What is CMake equivalent of 'configure --prefix=DIR && make all install: https://stackoverflow.com/a/35753015/1418981 - execute "cd #{@buildDir} && cmake -DCMAKE_INSTALL_PREFIX=#{@installDir} . && ninja install" + execute "cd #{@buildDir} && cmake " + options.join(" ") + " . && " + args.join(" ") + " ninja install" end def make From db005a437bfda2260e655fcfd525233625741529 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Fri, 14 Dec 2018 19:58:33 +0100 Subject: [PATCH 16/66] Scripts update. --- Rakefile | 5 +++++ Scripts/Builders/FoundationBuilder.rb | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Rakefile b/Rakefile index a7e3778e..4032b707 100755 --- a/Rakefile +++ b/Rakefile @@ -146,6 +146,11 @@ namespace :foundation do FoundationBuilder.new().make end + desc "Clean libFoundation" + task :clean do + FoundationBuilder.new().clean + end + end namespace :dispatch do diff --git a/Scripts/Builders/FoundationBuilder.rb b/Scripts/Builders/FoundationBuilder.rb index 60252454..d4f064d5 100644 --- a/Scripts/Builders/FoundationBuilder.rb +++ b/Scripts/Builders/FoundationBuilder.rb @@ -100,4 +100,9 @@ def make build end + def clean + execute "rm -rf \"#{@buildDir}\"" + execute "rm -rf \"#{@installDir}\"" + end + end From 309edfbfc7ca4145d74d4a79b354c9c3032203d9 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Fri, 14 Dec 2018 20:37:57 +0100 Subject: [PATCH 17/66] scripts update. --- Rakefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 4032b707..040b5bc7 100755 --- a/Rakefile +++ b/Rakefile @@ -16,7 +16,7 @@ require_relative "Scripts/ADBHelper.rb" # - Using Rake to Automate Tasks: https://www.stuartellis.name/articles/rake/ # -task default: %w[usage] +task default: ['usage'] task :usage do help = < [:linux, :armv7a, :x86, :aarch64] do + task all: [:linux, :armv7a, :x86, :aarch64] do puts "Done!" end @@ -166,7 +166,7 @@ namespace :dispatch do end desc "Rebuild libDispatch" - task :rebuild => [:clean, :build] do + task rebuild: [:clean, :build] do end end @@ -245,7 +245,7 @@ namespace :project do end desc "Project Hello: Deploy and Run on Android" - task :deploy => [:install, :run] do + task deploy: [:install, :run] do end end From 2789c0a222997c06520411321808f8d75050abad Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Fri, 14 Dec 2018 21:24:26 +0100 Subject: [PATCH 18/66] Gitignore update. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a0a0e17d..c3ce0740 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /Build /Install +/Temp From ce269aa0f5f4053a0b78f5b2f68be38d3bea8cc1 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Fri, 14 Dec 2018 23:54:12 +0100 Subject: [PATCH 19/66] Scripts update. --- Rakefile | 45 ++++++++---- Readme.md | 109 ++--------------------------- Scripts/Builders/AndroidBuilder.rb | 11 +-- Scripts/Builders/ICUBuilder.rb | 5 ++ Scripts/Builders/SwiftBuilder.rb | 10 ++- Scripts/Builders/XMLBuilder.rb | 2 - Scripts/Common/Arch.rb | 18 +++++ Scripts/Common/Builder.rb | 16 ++++- Scripts/Common/Config.rb | 42 ++++++++--- Scripts/Common/Downloader.rb | 2 + Scripts/Common/Lib.rb | 15 ++++ Scripts/Common/Location.rb | 22 ++++++ Scripts/Common/Tool.rb | 2 +- Vagrantfile | 4 +- 14 files changed, 168 insertions(+), 135 deletions(-) create mode 100644 Scripts/Common/Arch.rb create mode 100644 Scripts/Common/Lib.rb create mode 100644 Scripts/Common/Location.rb diff --git a/Rakefile b/Rakefile index 040b5bc7..badb4e95 100755 --- a/Rakefile +++ b/Rakefile @@ -20,18 +20,19 @@ task default: ['usage'] task :usage do help = < /etc/profile.d/sa-environment.sh", :run => 'always' config.vm.provider "virtualbox" do |vb| vb.memory = "5120" # Setting value less that `5120` can cause linker to fail. - vb.cpus = "4" # Setting value less that `4` can cause sloooooow compile time. + vb.cpus = `sysctl -n hw.physicalcpu`.to_i # use all available end end From 8192d1bc26689c26c009e9e2ae780aa3c876de7d Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sat, 15 Dec 2018 01:03:54 +0100 Subject: [PATCH 20/66] Scripts update. --- Rakefile | 68 ++++++++++++----------- Scripts/Builders/AndroidBuilder.rb | 20 ++++--- Scripts/Builders/ICUBuilder.rb | 88 +++++++++++++++++------------- Scripts/Common/Arch.rb | 7 ++- Scripts/Common/Builder.rb | 3 + 5 files changed, 106 insertions(+), 80 deletions(-) diff --git a/Rakefile b/Rakefile index badb4e95..8f00dc39 100755 --- a/Rakefile +++ b/Rakefile @@ -24,34 +24,30 @@ task :usage do Building Swift Toolchain. Steps: 1. Checkout Sources. - "rake checkout:swift" - "rake checkout:ndk" - "rake checkout:icu" + rake checkout:swift + rake checkout:ndk + rake checkout:icu Alternatively you can download Android NDK manually form https://developer.android.com/ndk/downloads/ and put it into Downloads folder. -2. Prepare Android Toolchains: - Execute: "rake ndk:setup" +2. Configure and Build Sources: + rake build:armv7a:ndk + rake build:armv7a:icu + rake build:armv7a:swift -4. Build ICU for all platforms. - Execute: "rake icu:build:all" - If you decided to build only one platform, them make sure that ICU for linux - build before any other platform (due cross compilation). - -5. Build Swift. - Execute: "rake swift:build" - -6. Build Hello project using new Swift Compiler. +3. Build `Hello` project. Execute: "rake project:hello:build" -7. Install Android Tools for macOS. See: https://stackoverflow.com/questions/17901692/set-up-adb-on-mac-os-x +4. Install Android Tools for macOS. See: https://stackoverflow.com/questions/17901692/set-up-adb-on-mac-os-x -8. Connect Android device to Host. Enable USB Debugging on Android device. Verify that device is connected. +5. Connect Android device to Host. Enable USB Debugging on Android device. Verify that device is connected. Execute: "rake project:hello:verify" -9. Deploy and run Hello Project to Android Device. +6. Deploy and run Hello Project to Android Device. Execute: "rake project:hello:install" Execute: "rake project:hello:run" + +7. Repeat steps 2...6 for other architectures. \n EOM puts help @@ -86,15 +82,34 @@ end namespace :build do + namespace :armv7a do + + desc "Setup Android toolchain." + task :ndk do + AndroidBuilder.new(Arch.armv7a).setup + end + + desc "Build ICU" + task :icu do + ICUBuilder.new(Arch.armv7a).make + end + end end -namespace :icu do +namespace :clean do - desc "Cleans ICU build." - task :clean do - ICUBuilder.new().clean + namespace :armv7a do + + desc "Clean ICU." + task :icu do + ICUBuilder.new(Arch.armv7a).clean + end end +end + +namespace :icu do + namespace :build do desc "Applies patch (if needed) and builds ICU for all platforms." @@ -107,11 +122,6 @@ namespace :icu do ICUBuilder.new("linux").make end - desc "Builds ICU for armv7a" - task :armv7a do - ICUBuilder.new("armv7a").make - end - desc "Builds ICU for x86" task :x86 do ICUBuilder.new("x86").make @@ -131,12 +141,6 @@ namespace :ndk do AndroidBuilder.new("").clean end - desc "Setup Android toolchains for All platforms." - task :setup do - AndroidBuilder.new("armv7a").setupToolchain - AndroidBuilder.new("x86").setupToolchain - AndroidBuilder.new("aarch64").setupToolchain - end end namespace :swift do diff --git a/Scripts/Builders/AndroidBuilder.rb b/Scripts/Builders/AndroidBuilder.rb index 5cbb75c5..6cc5e131 100755 --- a/Scripts/Builders/AndroidBuilder.rb +++ b/Scripts/Builders/AndroidBuilder.rb @@ -2,6 +2,10 @@ class AndroidBuilder < Builder + def self.api + return "21" + end + def initialize(arch = Arch.default) super(Lib.ndk, arch) @installDir = Config.ndkInstallRoot + "/#{@arch}" @@ -12,23 +16,23 @@ def download() downloader.bootstrap() end - def setupToolchain + def setup cmd = [] - cmd << "#{Config.ndkSourcesRoot}/build/tools/make-standalone-toolchain.sh" - cmd << "--platform=android-#{Config.androidAPI}" - cmd << "--install-dir=#{@installDir}" - if @arch == "armv7a" + cmd << "#{@sources}/build/tools/make-standalone-toolchain.sh" + cmd << "--platform=android-#{AndroidBuilder.api}" + cmd << "--install-dir=#{@install}" + if @arch == Arch.armv7a cmd << "--toolchain=arm-linux-androideabi-4.9" - elsif @arch == "x86" + elsif @arch == Arch.x86 cmd << "--toolchain=x86-4.9" - elsif @arch == "aarch64" + elsif @arch == Arch.aarch64 cmd << "--toolchain=aarch64-linux-android-4.9" end execute cmd.join(" ") end def clean() - execute "rm -rf #{Config.ndkInstallRoot}/" + execute "rm -rf #{@install}/" end end diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index bec13f03..5ab17582 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -1,5 +1,4 @@ require_relative "../Common/Builder.rb" -require_relative "../Common/Config.rb" # See: # - ICU Patches: https://github.com/amraboelela/swift/blob/android/docs/Android.md @@ -12,23 +11,36 @@ class ICUBuilder < Builder - def initialize(target = "armv7a") - super() - @target = target - @buildDir = Config.buildRoot + "/icu/" + @target - @prefixDir = Config.icuInstallRoot + "/" + @target + def initialize(arch = Arch.default) + super(Lib.icu, arch) + @ndk = AndroidBuilder.new(arch) + if arch != "linux" + @host = ICUBuilder.new("linux") + end + end + + def configureHost + cmd = ["cd #{@build} &&"] + cmd << 'CFLAGS="-Os"' + cmd << 'CXXFLAGS="--std=c++11"' + cmd << "#{@sources}/icu4c/source/runConfigureICU Linux --prefix=#{@install}" + cmd << "--enable-static --enable-shared=no --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no" + cmd << "--enable-layoutex=no --enable-tools=no --enable-tests=no --enable-samples=no --enable-dyload=no" + execute cmd.join(" ") end def configure - cmd = ["cd #{@buildDir} &&"] - if @target == "linux" - cmd << 'CFLAGS="-Os"' - cmd << 'CXXFLAGS="--std=c++11"' - cmd << "#{Config.icuSourcesRoot}/source/runConfigureICU Linux --prefix=#{@prefixDir}" - cmd << "--enable-static --enable-shared=no --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no" - cmd << "--enable-layoutex=no --enable-tools=no --enable-tests=no --enable-samples=no --enable-dyload=no" - elsif @target == "armv7a" - cmd << "PATH=#{Config.ndkInstallRoot}/#{@target}/bin:$PATH" + if !@host.nil? && !File.exist?(@host.build) + message "Building Corss-Build Host." + @host.prepare + @host.configureHost + @host.compile + message "Corss-Build Host Build completed." + end + + cmd = ["cd #{@build} &&"] + if @arch == Arch.armv7a + cmd << "PATH=#{@ndk.install}/bin:$PATH" cmd << "CFLAGS='-Os -march=armv7-a -mfloat-abi=softfp -mfpu=neon'" cmd << "CXXFLAGS='--std=c++11 -march=armv7-a -mfloat-abi=softfp -mfpu=neon'" cmd << "LDFLAGS='-march=armv7-a -Wl,--fix-cortex-a8'" @@ -36,61 +48,60 @@ def configure cmd << "CXX=arm-linux-androideabi-clang++" cmd << "AR=arm-linux-androideabi-ar" cmd << "RINLIB=arm-linux-androideabi-ranlib" - cmd << "#{Config.icuSourcesRoot}/source/configure --prefix=#{@prefixDir}" + cmd << "#{@sources}/icu4c/source/configure --prefix=#{@install}" cmd << "--host=arm-linux-androideabi" cmd << "--with-library-suffix=swift" cmd << "--enable-static --enable-shared --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no --enable-layoutex=no" cmd << "--enable-tools=no --enable-tests=no --enable-samples=no --enable-dyload=no" - cmd << "--with-cross-build=#{Config.buildRoot}/icu/linux" + cmd << "--with-cross-build=#{@host.build}" cmd << "--with-data-packaging=archive" - elsif @target == "x86" - cmd << "PATH=#{Config.ndkInstallRoot}/#{@target}/bin:$PATH" + elsif @arch == Arch.x86 + cmd << "PATH=#{@ndk.install}/bin:$PATH" cmd << "CFLAGS='-Os -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32'" cmd << "CXXFLAGS='--std=c++11 -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32'" cmd << "CC=i686-linux-android-clang" cmd << "CXX=i686-linux-android-clang++" cmd << "AR=i686-linux-android-ar" cmd << "RINLIB=i686-linux-android-ranlib" - cmd << "#{Config.icuSourcesRoot}/source/configure --prefix=#{@prefixDir}" + cmd << "#{@sources}/icu4c/source/configure --prefix=#{@install}" cmd << "--host=i686-linux-android" cmd << "--with-library-suffix=swift" cmd << "--enable-static --enable-shared --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no --enable-layoutex=no" cmd << "--enable-tools=no --enable-tests=no --enable-samples=no --enable-dyload=no" - cmd << "--with-cross-build=#{Config.buildRoot}/icu/linux" + cmd << "--with-cross-build=#{@host.build}" cmd << "--with-data-packaging=archive" - elsif @target == "aarch64" - cmd << "PATH=#{Config.ndkInstallRoot}/#{@target}/bin:$PATH" + elsif @arch == Arch.aarch64 + cmd << "PATH=#{@ndk.install}/bin:$PATH" cmd << "CFLAGS='-Os'" cmd << "CXXFLAGS='--std=c++11'" cmd << "CC=aarch64-linux-android-clang" cmd << "CXX=aarch64-linux-android-clang++" cmd << "AR=aarch64-linux-android-ar" cmd << "RINLIB=aarch64-linux-android-ranlib" - cmd << "#{Config.icuSourcesRoot}/source/configure --prefix=#{@prefixDir}" + cmd << "#{@sources}/icu4c/source/configure --prefix=#{@install}" cmd << "--host=aarch64-linux-android" cmd << "--with-library-suffix=swift" cmd << "--enable-static --enable-shared --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no --enable-layoutex=no" cmd << "--enable-tools=no --enable-tests=no --enable-samples=no --enable-dyload=no" - cmd << "--with-cross-build=#{Config.buildRoot}/icu/linux" + cmd << "--with-cross-build=#{@host.build}" cmd << "--with-data-packaging=archive" end execute cmd.join(" ") end def checkout - execute "cd \"#{Config.sourcesRoot}\" && git clone --depth=100 https://github.com/unicode-org/icu.git" - message "#{Lib::ICU} checkout completed." + checkoutIfNeeded(@sources, "https://github.com/unicode-org/icu.git") end def prepare() - execute "mkdir -p #{@buildDir}" + execute "mkdir -p #{@build}" applyPatchIfNeeded() end def applyPatchIfNeeded() - originalFile = "#{Config.icuSourcesRoot}/source/configure" - backupFile = "#{Config.icuSourcesRoot}/source/configure.orig" - patchFile = "#{Config.icuPatchesRoot}/configure.patch" + originalFile = "#{@sources}/icu4c/source/configure" + backupFile = "#{@sources}/icu4c/source/configure.orig" + patchFile = "#{@patches}/configure.patch" if !File.exist? backupFile puts "Patching ICU..." execute "patch --backup #{originalFile} #{patchFile}" @@ -99,20 +110,23 @@ def applyPatchIfNeeded() end end - def build - execute "cd #{@buildDir} && PATH=#{Config.ndkInstallRoot}/#{@target}/bin:$PATH make -j4" - execute "cd #{@buildDir} && PATH=#{Config.ndkInstallRoot}/#{@target}/bin:$PATH make install" + def compile + execute "cd #{@build} && PATH=#{@ndk.install}/bin:$PATH make -j4" + execute "cd #{@build} && PATH=#{@ndk.install}/bin:$PATH make install" end def make() prepare configure - build + compile end def clean() - execute "rm -rf #{Config.buildRoot}/icu/" - execute "rm -rf #{Config.icuInstallRoot}/" + if !@host.nil? + @host.clean + end + execute "rm -rf #{@build}" + execute "rm -rf #{@install}" end end diff --git a/Scripts/Common/Arch.rb b/Scripts/Common/Arch.rb index 1d2c3085..ae3d86f1 100644 --- a/Scripts/Common/Arch.rb +++ b/Scripts/Common/Arch.rb @@ -1,5 +1,9 @@ class Arch + def self.default + return armv7a + end + def self.x86 return "x86" end @@ -12,7 +16,4 @@ def self.aarch64 return "aarch64" end - def self.default - return armv7a - end end diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index 90d9734b..15d55b53 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -7,6 +7,8 @@ class Builder < Tool + attr_reader :build, :install, :sources + def initialize(component, arch) @component = component @arch = arch @@ -21,6 +23,7 @@ def checkoutIfNeeded(localPath, repoURL) message "Repository #{repoURL} seems already checked out." else execute "cd #{File.dirname(localPath)} && git clone --depth=100 #{repoURL}" + message "#{repoURL} checkout completed." end end From 853ef01b8501eb2350d98464ce165e670e9dea1d Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sat, 15 Dec 2018 12:46:23 +0100 Subject: [PATCH 21/66] Scripts update. --- Rakefile | 46 +++---------- Readme.md | 100 +++++++++-------------------- Scripts/Builders/AndroidBuilder.rb | 4 +- Scripts/Builders/ICUBuilder.rb | 13 ++-- Scripts/Builders/SwiftBuilder.rb | 75 ++++++++++++++-------- Scripts/Common/Builder.rb | 8 ++- Scripts/Shell/bootstrap.sh | 4 +- Vagrantfile | 2 +- 8 files changed, 107 insertions(+), 145 deletions(-) diff --git a/Rakefile b/Rakefile index 8f00dc39..e3fde696 100755 --- a/Rakefile +++ b/Rakefile @@ -93,6 +93,11 @@ namespace :build do task :icu do ICUBuilder.new(Arch.armv7a).make end + + desc "Build Swift" + task :swift do + SwiftBuilder.new(Arch.armv7a).make + end end end @@ -104,52 +109,17 @@ namespace :clean do task :icu do ICUBuilder.new(Arch.armv7a).clean end - end - -end - -namespace :icu do - - namespace :build do - - desc "Applies patch (if needed) and builds ICU for all platforms." - task all: [:linux, :armv7a, :x86, :aarch64] do - puts "Done!" - end - - desc "Builds ICU for Linux" - task :linux do - ICUBuilder.new("linux").make - end - desc "Builds ICU for x86" - task :x86 do - ICUBuilder.new("x86").make - end - - desc "Builds ICU for aarch64" - task :aarch64 do - ICUBuilder.new("aarch64").make + desc "Clean NDK." + task :ndk do + AndroidBuilder.new(Arch.armv7a).clean end end -end - -namespace :ndk do - - desc "Cleans NDK build." - task :clean do - AndroidBuilder.new("").clean - end end namespace :swift do - desc "Build Swift" - task :build do - SwiftBuilder.new().make - end - desc "Swift: Show Build options (i.e. `swift/utils/build-script --help`)" task :help do SwiftBuilder.new().help diff --git a/Readme.md b/Readme.md index 70cc4d39..45597aad 100644 --- a/Readme.md +++ b/Readme.md @@ -1,13 +1,8 @@ -I. Prerequesites +I. Initial setup ================ **Note**: Every time you see `host$` – this means that command should be executed on **HOST** macOS computer. Every time you see `box$` – this means that command should be executed on virtual **GUEST** Linux OS. -**Note**: If you found mistake or something from written below is not working, then open issue and specify exact step which fails. I.e. `Step B.1.ii`. - -A. Initial setup ----------------- - 1. Download and install software. - Vagrant: https://www.vagrantup.com @@ -21,86 +16,57 @@ A. Initial setup host$ vagrant --version ``` -3. Clone this repository. +3. Download Ubuntu image. + + **Note**: Usually you need to download box image once. ```bash - host$ git clone https://github.com/vgorloff/Android-On-Swift.git - host$ cd Android-On-Swift + host$ vagrant box add ubuntu/bionic64 ``` -B. Setting up Ubuntu box ------------------------- - -**Note**: Most of the steps similar to [Getting Started](https://www.vagrantup.com/intro/getting-started/index.html) from Vagrant website. - -1. Setup Ubuntu box. - - 1. Download Ubuntu box image. - - **Note**: Usually you need to download box image once. + **Note**: You can explore trending boxes here: - ```bash - host$ vagrant box add ubuntu/bionic64 - ``` + - https://app.vagrantup.com/boxes/search + - https://app.vagrantup.com/ubuntu/boxes/bionic64 - **Note**: You can explore trending boxes here: +4. Clone this repository. - - https://app.vagrantup.com/boxes/search - - https://app.vagrantup.com/ubuntu/boxes/bionic64 - - 2. (Optionall) Verify downloaded Ubuntu image in local folder. - - ```bash - host$ ls -l ~/.vagrant.d/boxes - ``` + ```bash + host$ git clone https://github.com/vgorloff/Android-On-Swift.git + host$ cd Android-On-Swift + ``` - 3. Start box and connect via SSH. +2. (Optionall) Verify downloaded Ubuntu image in local folder. - ```bash - host$ vagrant up - host$ vagrant ssh - ``` + ```bash + host$ ls -l ~/.vagrant.d/boxes + ``` - **Note**: Box will be created in directory specified in VirtualBox settings. Detalis in [this post](http://www.thisprogrammingthing.com/2013/changing-the-directory-vagrant-stores-the-vms-in/). +3. Start box and connect via SSH. - 4. (Optionall) Verify Ubuntu version and Explore synced folders. + ```bash + host$ vagrant up + host$ vagrant ssh + ``` - ```bash - box$ lsb_release -irc - box$ ls -l /vagrant - ``` + **Note**: Box will be created in directory specified in VirtualBox settings. Detalis in [this post](http://www.thisprogrammingthing.com/2013/changing-the-directory-vagrant-stores-the-vms-in/). - **Note**: You should see this `Readme.md` file inside Ubuntu Box. +4. (Optionall) Verify Ubuntu version and Explore synced folders. - As result we have Ubuntu box running on macOS. + ```bash + box$ lsb_release -irc + box$ ls -l /vagrant + ``` + **Note**: You should see this `Readme.md` file inside Ubuntu Box. -C. (Optional) Setting Up Visual Studio Code -------------------------------------------- +5. (Optional) Setting Up Visual Studio Code If you going to edit Ruby files, then it worth to install Visual Studio Code for macOS and Ruby plugin. -1. Visual Studio Code: https://code.visualstudio.com -2. Ruby language support: https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby + - Visual Studio Code: https://code.visualstudio.com + - Ruby language support: https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby -E. Installing dependencies on Box ---------------------------------------- - -1. Install development packages and Verify Ruby and Rake version. - - ```bash - host$ vagrant ssh - - box$ bash /vagrant/Scripts/Shell/bootstrap.sh - ``` - -2. (Optionall) Take snapshot. - - ```bash - host$ vagrant snapshot save "Clean System" - ``` - - **Note**: Under the hood it will save VirtualBox snapshot. II. Usage ========= @@ -111,5 +77,3 @@ Remaining process of compilling Swift Toolchain, building and deploying sample p box$ cd /vagrant/ box$ rake ``` - -**Note**: Some Rake targets need to be executed on `host`, but some on `box`. Don't mix up execution environment. diff --git a/Scripts/Builders/AndroidBuilder.rb b/Scripts/Builders/AndroidBuilder.rb index 6cc5e131..c9ef6102 100755 --- a/Scripts/Builders/AndroidBuilder.rb +++ b/Scripts/Builders/AndroidBuilder.rb @@ -2,7 +2,7 @@ class AndroidBuilder < Builder - def self.api + def api return "21" end @@ -19,7 +19,7 @@ def download() def setup cmd = [] cmd << "#{@sources}/build/tools/make-standalone-toolchain.sh" - cmd << "--platform=android-#{AndroidBuilder.api}" + cmd << "--platform=android-#{@api}" cmd << "--install-dir=#{@install}" if @arch == Arch.armv7a cmd << "--toolchain=arm-linux-androideabi-4.9" diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index 5ab17582..59bacbd6 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -13,6 +13,7 @@ class ICUBuilder < Builder def initialize(arch = Arch.default) super(Lib.icu, arch) + @sources = "#{Config.sources}/#{Lib.icu}/icu4c" @ndk = AndroidBuilder.new(arch) if arch != "linux" @host = ICUBuilder.new("linux") @@ -23,7 +24,7 @@ def configureHost cmd = ["cd #{@build} &&"] cmd << 'CFLAGS="-Os"' cmd << 'CXXFLAGS="--std=c++11"' - cmd << "#{@sources}/icu4c/source/runConfigureICU Linux --prefix=#{@install}" + cmd << "#{@sources}/source/runConfigureICU Linux --prefix=#{@install}" cmd << "--enable-static --enable-shared=no --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no" cmd << "--enable-layoutex=no --enable-tools=no --enable-tests=no --enable-samples=no --enable-dyload=no" execute cmd.join(" ") @@ -48,7 +49,7 @@ def configure cmd << "CXX=arm-linux-androideabi-clang++" cmd << "AR=arm-linux-androideabi-ar" cmd << "RINLIB=arm-linux-androideabi-ranlib" - cmd << "#{@sources}/icu4c/source/configure --prefix=#{@install}" + cmd << "#{@sources}/source/configure --prefix=#{@install}" cmd << "--host=arm-linux-androideabi" cmd << "--with-library-suffix=swift" cmd << "--enable-static --enable-shared --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no --enable-layoutex=no" @@ -63,7 +64,7 @@ def configure cmd << "CXX=i686-linux-android-clang++" cmd << "AR=i686-linux-android-ar" cmd << "RINLIB=i686-linux-android-ranlib" - cmd << "#{@sources}/icu4c/source/configure --prefix=#{@install}" + cmd << "#{@sources}/source/configure --prefix=#{@install}" cmd << "--host=i686-linux-android" cmd << "--with-library-suffix=swift" cmd << "--enable-static --enable-shared --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no --enable-layoutex=no" @@ -78,7 +79,7 @@ def configure cmd << "CXX=aarch64-linux-android-clang++" cmd << "AR=aarch64-linux-android-ar" cmd << "RINLIB=aarch64-linux-android-ranlib" - cmd << "#{@sources}/icu4c/source/configure --prefix=#{@install}" + cmd << "#{@sources}/source/configure --prefix=#{@install}" cmd << "--host=aarch64-linux-android" cmd << "--with-library-suffix=swift" cmd << "--enable-static --enable-shared --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no --enable-layoutex=no" @@ -99,8 +100,8 @@ def prepare() end def applyPatchIfNeeded() - originalFile = "#{@sources}/icu4c/source/configure" - backupFile = "#{@sources}/icu4c/source/configure.orig" + originalFile = "#{@sources}/source/configure" + backupFile = "#{@sources}/source/configure.orig" patchFile = "#{@patches}/configure.patch" if !File.exist? backupFile puts "Patching ICU..." diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 949ea103..f7acf2ac 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -48,30 +48,52 @@ class SwiftBuilder < Builder - def initialize() - super() - @installRoot = Config.installRoot + "/swift/swift" - @installArchive = Config.installRoot + "/swift/swift.tar.gz" + def initialize(arch = Arch.default) + super(Lib.swift, arch) + @icu = ICUBuilder.new(arch) + @ndk = AndroidBuilder.new(arch) end - def build() - target = "armv7a" - libICUBuildPath = Config.icuInstallRoot + "/#{target}/lib" - cmd = ["cd #{Config.swiftSourcesRoot} &&"] + def compileOLD + cmd = ["cd #{@sources} &&"] cmd << "./swift/utils/build-script --release --android" - cmd << "--android-ndk #{Config.ndkSourcesRoot}" - cmd << "--android-api-level #{Config.androidAPI}" - cmd << "--android-icu-uc #{libICUBuildPath}/libicuucswift.so" - cmd << "--android-icu-uc-include #{Config.icuSourcesRoot}/source/common" - cmd << "--android-icu-i18n #{libICUBuildPath}/libicui18nswift.so" - cmd << "--android-icu-i18n-include #{Config.icuSourcesRoot}/source/i18n" - cmd << "--android-icu-data #{Config.icuSourcesRoot}/libicudataswift.so" + cmd << "--android-ndk #{@ndk.sources}" + cmd << "--android-api-level #{@ndk.api}" + cmd << "--android-icu-uc #{@icu.lib}/libicuucswift.so" + cmd << "--android-icu-uc-include #{@icu.sources}/source/common" + 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 << "--foundation --libdispatch" # Needs to be compiled separately. - cmd << "--build-dir #{Config.swiftBuildRoot}" + cmd << "--build-dir #{@build}" execute cmd.join(" ") end - def prepare() + def compile + cmd = ["cd #{@sources} &&"] + cmd << "./swift/utils/build-script --release --android" + cmd << "--android-ndk #{@ndk.sources}" + cmd << "--android-api-level #{@ndk.api}" + cmd << "--android-icu-uc #{@icu.lib}/libicuucswift.so" + cmd << "--android-icu-uc-include #{@icu.sources}/source/common" + 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 << "--libdispatch --install-libdispatch" + cmd << "--foundation --install-foundation" + cmd << "--llbuild --install-llbuild" + cmd << "--lldb --install-lldb" + cmd << "--swiftpm --install-swiftpm" + cmd << "--xctest --install-xctest" + cmd << "--install-swift" + cmd << "'--swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;dev'" + cmd << "--install-prefix=/usr" + cmd << "--install-destdir=#{@install}" + cmd << "--build-dir #{@build}" + execute cmd.join(" ") + end + + def prepare targetFile = "/usr/bin/armv7-none-linux-androideabi-ld.gold" if File.exist?(targetFile) return @@ -85,25 +107,24 @@ def prepare() execute "ls -a /usr/bin/*ld.gold" end - def make() - prepare - build + def make + # prepare + compile end def help - execute "cd #{Config.swiftSourcesRoot} && ./swift/utils/build-script --help | more" + execute "cd #{@sources} && ./swift/utils/build-script --help | more" end def update - execute "cd #{Config.swiftSourcesRoot} && ./swift/utils/update-checkout" + execute "cd #{@sources} && ./swift/utils/update-checkout" end def checkout - sources = Config.sources(Lib::Swift) - execute "mkdir -p \"#{sources}\"" - execute "cd \"#{sources}\" && git clone --depth=100 https://github.com/apple/swift.git" - execute "cd \"#{sources}\" && ./swift/utils/update-checkout --clone" - message "#{Lib::Swift} checkout completed." + dir = @sources + "/swift" + checkoutIfNeeded(dir, "https://github.com/apple/swift.git") + execute "cd \"#{dir}\" && ./swift/utils/update-checkout --clone" + message "#{Lib.swift} checkout completed." end end diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index 15d55b53..188c5436 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -18,11 +18,17 @@ def initialize(component, arch) @install = "#{Config.install}/#{component}/#{arch}" end + def lib + return @install + "/lib" + end + def checkoutIfNeeded(localPath, repoURL) if File.exist?(localPath) message "Repository #{repoURL} seems already checked out." else - execute "cd #{File.dirname(localPath)} && git clone --depth=100 #{repoURL}" + dir = File.dirname(localPath) + execute "mkdir -p \"#{dir}\"" + execute "cd \"#{dir}\" && git clone --depth=100 #{repoURL}" message "#{repoURL} checkout completed." end end diff --git a/Scripts/Shell/bootstrap.sh b/Scripts/Shell/bootstrap.sh index 096d3f03..ff61953a 100755 --- a/Scripts/Shell/bootstrap.sh +++ b/Scripts/Shell/bootstrap.sh @@ -1,14 +1,14 @@ #!/bin/bash echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" -SA_CMD="sudo apt-get update" +SA_CMD="apt-get -y update" echo "Executing command: \"$SA_CMD\"" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" $SA_CMD # Swift dependencies echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" -SA_CMD="sudo apt-get install mc ruby cmake ninja-build clang python autoconf libtool uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev systemtap-sdt-dev tzdata rsync libz3-dev" +SA_CMD="apt-get -y install mc ruby cmake ninja-build clang python autoconf libtool uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev systemtap-sdt-dev tzdata rsync libz3-dev" echo "Executing command: \"$SA_CMD\"" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" $SA_CMD diff --git a/Vagrantfile b/Vagrantfile index b834db0e..c9fd7e9a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,7 +6,7 @@ Vagrant.configure("2") do |config| config.vm.box = "ubuntu/bionic64" - config.disksize.size = '25GB' + config.vm.provision :shell, path: "Scripts/Shell/bootstrap.sh" config.vm.provision :shell, inline: "echo 'source /vagrant/Scripts/Shell/environment.sh' > /etc/profile.d/sa-environment.sh", :run => 'always' config.vm.provider "virtualbox" do |vb| From 04d00f3c67b10bc48ae4315e532cd6ce594c0e73 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sat, 15 Dec 2018 12:50:11 +0100 Subject: [PATCH 22/66] Reame correction. --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 45597aad..4e913779 100644 --- a/Readme.md +++ b/Readme.md @@ -62,7 +62,7 @@ I. Initial setup 5. (Optional) Setting Up Visual Studio Code -If you going to edit Ruby files, then it worth to install Visual Studio Code for macOS and Ruby plugin. + If you going to edit Ruby files, then it worth to install Visual Studio Code for macOS and Ruby plugin. - Visual Studio Code: https://code.visualstudio.com - Ruby language support: https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby From a1b59fe45c1a1f2cae2bab253d63d4e21688dc76 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sat, 15 Dec 2018 12:53:00 +0100 Subject: [PATCH 23/66] Readme update. --- Readme.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 4e913779..7bd31091 100644 --- a/Readme.md +++ b/Readme.md @@ -36,13 +36,13 @@ I. Initial setup host$ cd Android-On-Swift ``` -2. (Optionall) Verify downloaded Ubuntu image in local folder. +5. (Optionall) Verify downloaded Ubuntu image in local folder. ```bash host$ ls -l ~/.vagrant.d/boxes ``` -3. Start box and connect via SSH. +6. Start box and connect via SSH. ```bash host$ vagrant up @@ -51,7 +51,7 @@ I. Initial setup **Note**: Box will be created in directory specified in VirtualBox settings. Detalis in [this post](http://www.thisprogrammingthing.com/2013/changing-the-directory-vagrant-stores-the-vms-in/). -4. (Optionall) Verify Ubuntu version and Explore synced folders. +7. (Optionall) Verify Ubuntu version and Explore synced folders. ```bash box$ lsb_release -irc @@ -60,14 +60,21 @@ I. Initial setup **Note**: You should see this `Readme.md` file inside Ubuntu Box. -5. (Optional) Setting Up Visual Studio Code +8. (Optionall) Take snapshot. + + ```bash + host$ vagrant snapshot save "Clean System" + ``` + + **Note**: Under the hood it will save VirtualBox snapshot. + +9. (Optional) Setting Up Visual Studio Code If you going to edit Ruby files, then it worth to install Visual Studio Code for macOS and Ruby plugin. - Visual Studio Code: https://code.visualstudio.com - Ruby language support: https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby - II. Usage ========= From cbe58799809e4ce8734e720b8f2791c4c0f02ddf Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 16 Dec 2018 11:25:18 +0100 Subject: [PATCH 24/66] Scripts update. --- Rakefile | 23 +++++++--- Scripts/Builders/SwiftBuilder.rb | 79 ++++++++++++++++---------------- Scripts/Shell/bootstrap.sh | 4 +- 3 files changed, 59 insertions(+), 47 deletions(-) diff --git a/Rakefile b/Rakefile index e3fde696..92903a93 100755 --- a/Rakefile +++ b/Rakefile @@ -114,20 +114,29 @@ namespace :clean do task :ndk do AndroidBuilder.new(Arch.armv7a).clean end + + desc "Clean Swift." + task :swift do + SwiftBuilder.new(Arch.armv7a).clean + end end end -namespace :swift do +namespace :update do - desc "Swift: Show Build options (i.e. `swift/utils/build-script --help`)" - task :help do - SwiftBuilder.new().help + desc "Updated Git repositories: `swift/utils/update-checkout`" + task :swift do + SwiftBuilder.new().update end - desc "Swift: Update sources (i.e. `swift/utils/update-checkout`)" - task :update do - SwiftBuilder.new().update +end + +namespace :help do + + desc "Show Build options: `swift/utils/build-script --help`" + task :swift do + SwiftBuilder.new().help end end diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index f7acf2ac..244fb236 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -2,47 +2,33 @@ =begin -Compiling swift on Linux: https://akrabat.com/compiling-swift-on-linux/ - -# See: -# 1. Building the Swift stdlib for Android – https://github.com/amraboelela/swift/blob/android/docs/Android.md -# 2. fuchsia build – https://fuchsia.googlesource.com/third_party/swift-corelibs-foundation/+/upstream/google/build-android -# 3. Port to Android Patch – https://github.com/SwiftAndroid/swift/commit/7c502b6344a240c8e06c5e48e5ab6fa32c887ab3 -# 4. Using Swift to Build Code for Android – https://www.infoq.com/news/2016/04/swift-for-android -# 5. Issue with lg.gold – https://bugs.swift.org/browse/SR-1264?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel&showAll=true -# 6. Ussue with ld.gold – https://github.com/apple/swift/commit/d49d88e53d15b6cba00950ec7985df4631e24312 -# 7. Cross compile Apps on Mac for Linux: https://github.com/apple/swift-package-manager/blob/master/Utilities/build_ubuntu_cross_compilation_toolchain -# 8. Swift cross compile on Rasperi Pi: https://stackoverflow.com/a/44003655/1418981 -# 9. Java and Swift interoperability: https://medium.com/@michiamling/android-app-with-java-native-interface-for-swift-c9c322609e08 -# 10. /Sources/Swift/swift/utils/android/build-toolchain - -Swift in Java. - -- https://romain.goyet.com/articles/running_swift_code_on_android/ +Swift for Linux: +- Compiling swift on Linux: https://akrabat.com/compiling-swift-on-linux/ +- Build Swift for Android from your Mac: https://github.com/flowkey/swift-android-toolchain + +Swift for Android: +- See ./Sources/Swift/swift/utils/android/build-toolchain +- Running Swift code on Android https://romain.goyet.com/articles/running_swift_code_on_android/ +- Building a Development Environment for Swift on Android: https://medium.com/@michiamling/building-a-development-environment-for-swift-on-android-4bb652d2c938 +- Java and Swift interoperability: https://medium.com/@michiamling/android-app-with-java-native-interface-for-swift-c9c322609e08 +- Android App with Java native interface for Swift: http://michis.culture-blog.org/2017/04/android-app-with-java-native-interface.html +- Building the Swift stdlib for Android – https://github.com/amraboelela/swift/blob/android/docs/Android.md +- fuchsia build – https://fuchsia.googlesource.com/third_party/swift-corelibs-foundation/+/upstream/google/build-android - https://www.reddit.com/r/swift/comments/3w0xrd/im_patching_the_opensource_swift_compiler_to/ - https://github.com/flowkey/UIKit-cross-platform -- https://github.com/flowkey/swift-android-toolchain - https://blog.readdle.com/why-we-use-swift-for-android-db449feeacaf +- Swift on Android: The Future of Cross-Platform Programming?: https://academy.realm.io/posts/swift-on-android/ +Pull Requests and Patches: +- Port to Android Patch: https://github.com/SwiftAndroid/swift/commit/7c502b6344a240c8e06c5e48e5ab6fa32c887ab3 -~~OLD +Issues: +- Issue with lg.gold – https://bugs.swift.org/browse/SR-1264 +- Issue with ld.gold – https://github.com/apple/swift/commit/d49d88e53d15b6cba00950ec7985df4631e24312 -./swift/utils/build-script --show-presets (see also swift/utils/build-presets.ini) - -5. Build: ./swift/utils/build-script --preset=buildbot_linux installable_package=~/swift.tar.gz install_destdir=~/swift-install -5. Build: ./swift/utils/build-script --preset=buildbot_linux,no_test installable_package=~/swift.tar.gz install_destdir=~/swift-install - -# ./swift/utils/build-script -# --assertions --no-swift-stdlib-assertions --swift-enable-ast-verifier=0 -# --llbuild --swiftpm --xctest --libicu --build-ninja --install-swift --install-lldb --install-llbuild -# --install-swiftpm --install-xctest --install-libicu -# --install-prefix=/usr '--swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;license;sourcekit-inproc' -# '--llvm-install-components=llvm-cov;llvm-profdata;IndexStore' -# --build-swift-static-stdlib --build-swift-static-sdk-overlay --build-swift-stdlib-unittest-extra -# --test-installable-package -# --install-destdir=/home/user/Developer/Install/swift/swift5-android -# --installable-package=/home/user/Developer/Install/swift/swift5-android.tar.gz -# --build-subdir=buildbot_linux --lldb --release +Cross compile: +- Cross compile Apps on Mac for Linux: https://github.com/apple/swift-package-manager/blob/master/Utilities/build_ubuntu_cross_compilation_toolchain +- Swift cross compile on Rasperi Pi: https://stackoverflow.com/a/44003655/1418981 =end @@ -56,6 +42,10 @@ def initialize(arch = Arch.default) 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" + cmd << "./swift/utils/build-script --release --android" cmd << "--android-ndk #{@ndk.sources}" cmd << "--android-api-level #{@ndk.api}" @@ -64,12 +54,15 @@ def compileOLD 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 << "--foundation --libdispatch" # Needs to be compiled separately. + cmd << "--libdispatch --install-libdispatch" + cmd << "--foundation --install-foundation" + cmd << "--install-prefix=/usr" + cmd << "--install-destdir=#{@install}" cmd << "--build-dir #{@build}" execute cmd.join(" ") end - def compile + def compileNew cmd = ["cd #{@sources} &&"] cmd << "./swift/utils/build-script --release --android" cmd << "--android-ndk #{@ndk.sources}" @@ -93,15 +86,18 @@ def compile execute cmd.join(" ") end + def compile + compileNew + end + def prepare targetFile = "/usr/bin/armv7-none-linux-androideabi-ld.gold" if File.exist?(targetFile) return end - puts "Making symbolic link to \"#{targetFile}\"..." cmd = ["sudo"] - cmd << "ln -s #{Config.ndkSourcesRoot}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/ld.gold" + cmd << "ln -svf #{@ndk.sources}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/ld.gold" cmd << targetFile execute cmd.join(" ") execute "ls -a /usr/bin/*ld.gold" @@ -127,4 +123,9 @@ def checkout message "#{Lib.swift} checkout completed." end + def clean + execute "rm -rf #{@build}" + execute "rm -rf #{@install}" + end + end diff --git a/Scripts/Shell/bootstrap.sh b/Scripts/Shell/bootstrap.sh index ff61953a..56c2f9d7 100755 --- a/Scripts/Shell/bootstrap.sh +++ b/Scripts/Shell/bootstrap.sh @@ -8,7 +8,9 @@ $SA_CMD # Swift dependencies echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" -SA_CMD="apt-get -y install mc ruby cmake ninja-build clang python autoconf libtool uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev systemtap-sdt-dev tzdata rsync libz3-dev" +# Z3 dependency (`apt-get install libz3-dev`) temporary removed due compile error `llvm::Twine(Z3_get_error_msg(Context, Error)));` +# See: https://reviews.llvm.org/D54391 +SA_CMD="apt-get -y install mc ruby cmake ninja-build clang python autoconf libtool uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev systemtap-sdt-dev tzdata rsync" echo "Executing command: \"$SA_CMD\"" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" $SA_CMD From c0203598d6289a77fd736ddbfbac7aafee72b4d2 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 09:45:12 +0100 Subject: [PATCH 25/66] LLVM Compile. --- Scripts/Builders/SwiftBuilder.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 244fb236..fa141288 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -86,8 +86,26 @@ def compileNew execute cmd.join(" ") end + def buildLLVM + # See: LLVM Getting Started https://llvm.org/docs/GettingStarted.html + execute "mkdir -p #{@build}/llvm" + cmd = [] + cmd << "cd #{@build}/llvm &&" + cmd << "cmake -G Ninja" + cmd << "-DCMAKE_INSTALL_PREFIX=#{@install}/llvm" + cmd << "-DCMAKE_BUILD_TYPE=Release" + cmd << "#{@sources}/llvm" + execute cmd.join(" ") + + execute "cd #{@build}/llvm && ninja" + message "LLVM Compile is completed." + + execute "cd #{@build}/llvm && ninja install" + message "LLVM Install is completed." + end + def compile - compileNew + buildLLVM end def prepare From 05993db96de22af8a0fed43a6e4722d5e3bc2582 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 14:12:53 +0100 Subject: [PATCH 26/66] Added LLVM Builder. --- Rakefile | 6 ++++ Scripts/Builders/LLVMBuilder.rb | 51 ++++++++++++++++++++++++++++++++ Scripts/Builders/SwiftBuilder.rb | 20 +------------ Scripts/Common/Lib.rb | 4 +++ 4 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 Scripts/Builders/LLVMBuilder.rb diff --git a/Rakefile b/Rakefile index 92903a93..d676358f 100755 --- a/Rakefile +++ b/Rakefile @@ -9,6 +9,7 @@ require_relative "Scripts/Builders/CurlBuilder.rb" require_relative "Scripts/Builders/OpenSSLBuilder.rb" require_relative "Scripts/Builders/XMLBuilder.rb" require_relative "Scripts/Builders/HelloProjectBuilder.rb" +require_relative "Scripts/Builders/LLVMBuilder.rb" require_relative "Scripts/ADBHelper.rb" # References: @@ -98,6 +99,11 @@ namespace :build do task :swift do SwiftBuilder.new(Arch.armv7a).make end + + desc "Build LLVM" + task :llvm do + LLVMBuilder.new(Arch.armv7a).make + end end end diff --git a/Scripts/Builders/LLVMBuilder.rb b/Scripts/Builders/LLVMBuilder.rb new file mode 100644 index 00000000..bab63aa9 --- /dev/null +++ b/Scripts/Builders/LLVMBuilder.rb @@ -0,0 +1,51 @@ +require_relative "../Common/Builder.rb" + +# See: +# - build llvm clang4.0 for android armeabi - https://stackoverflow.com/questions/40122657/build-llvm-clang4-0-for-android-armeabi +# - LLVM Getting Started: https://llvm.org/docs/GettingStarted.html#requirements +# - CLANG Getting Started: http://clang.llvm.org/get_started.html + +class LLVMBuilder < Builder + + def initialize(arch = Arch.default) + super(Lib.llvm, arch) + @sources = SwiftBuilder.new(Arch.default).sources + "/llvm" + end + + def configure + cmd = [] + cmd << "cd #{@build} &&" + cmd << "cmake -G Ninja" + cmd << "-DCMAKE_INSTALL_PREFIX=#{@install}" + cmd << "-DCMAKE_BUILD_TYPE=Release" + cmd << @sources + execute cmd.join(" ") + message "LLVM Configure is completed." + end + + def compile + execute "cd #{@build} && ninja" + message "LLVM Compile is completed." + end + + def install + execute "cd #{@build} && ninja install" + message "LLVM Install is completed." + end + + def make + prepare + configure + compile + install + end + + def checkout + puts "Implement LLVM Download" + end + + def prepare() + execute "mkdir -p #{@build}" + end + +end diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index fa141288..7cdf06be 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -86,26 +86,8 @@ def compileNew execute cmd.join(" ") end - def buildLLVM - # See: LLVM Getting Started https://llvm.org/docs/GettingStarted.html - execute "mkdir -p #{@build}/llvm" - cmd = [] - cmd << "cd #{@build}/llvm &&" - cmd << "cmake -G Ninja" - cmd << "-DCMAKE_INSTALL_PREFIX=#{@install}/llvm" - cmd << "-DCMAKE_BUILD_TYPE=Release" - cmd << "#{@sources}/llvm" - execute cmd.join(" ") - - execute "cd #{@build}/llvm && ninja" - message "LLVM Compile is completed." - - execute "cd #{@build}/llvm && ninja install" - message "LLVM Install is completed." - end - def compile - buildLLVM + puts "Implement Me" end def prepare diff --git a/Scripts/Common/Lib.rb b/Scripts/Common/Lib.rb index d3eaed6d..c453dc7c 100644 --- a/Scripts/Common/Lib.rb +++ b/Scripts/Common/Lib.rb @@ -12,4 +12,8 @@ def self.ndk return "ndk" end + def self.llvm + return "llvm" + end + end From 3f235e98e375177341d19eeba89983d53052f957 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 15:08:14 +0100 Subject: [PATCH 27/66] Scripts update. --- Rakefile | 59 +++++++++++++++++++++++++++----- Scripts/Builders/CMarkBuilder.rb | 43 +++++++++++++++++++++++ Scripts/Builders/LLVMBuilder.rb | 12 +++---- Scripts/Common/Lib.rb | 4 +++ 4 files changed, 104 insertions(+), 14 deletions(-) create mode 100644 Scripts/Builders/CMarkBuilder.rb diff --git a/Rakefile b/Rakefile index d676358f..5034981e 100755 --- a/Rakefile +++ b/Rakefile @@ -10,6 +10,7 @@ require_relative "Scripts/Builders/OpenSSLBuilder.rb" require_relative "Scripts/Builders/XMLBuilder.rb" require_relative "Scripts/Builders/HelloProjectBuilder.rb" require_relative "Scripts/Builders/LLVMBuilder.rb" +require_relative "Scripts/Builders/CMarkBuilder.rb" require_relative "Scripts/ADBHelper.rb" # References: @@ -81,30 +82,72 @@ namespace :checkout do end -namespace :build do +namespace :armv7a do - namespace :armv7a do - - desc "Setup Android toolchain." + namespace :setup do + desc "Setup NDK Toolchain." task :ndk do AndroidBuilder.new(Arch.armv7a).setup end + end - desc "Build ICU" + namespace :configure do + desc "Configure ICU" task :icu do - ICUBuilder.new(Arch.armv7a).make + ICUBuilder.new(Arch.armv7a).configure + end + desc "Configure Swift" + task :swift do + SwiftBuilder.new(Arch.armv7a).configure end + desc "Configure LLVM" + task :llvm do + LLVMBuilder.new(Arch.armv7a).configure + end + desc "Configure CMark" + task :cmark do + CMarkBuilder.new(Arch.armv7a).configure + end + end + namespace :build do + desc "Build ICU" + task :icu do + ICUBuilder.new(Arch.armv7a).compile + end desc "Build Swift" task :swift do - SwiftBuilder.new(Arch.armv7a).make + SwiftBuilder.new(Arch.armv7a).compile end - desc "Build LLVM" + task :llvm do + LLVMBuilder.new(Arch.armv7a).compile + end + desc "Build CMark" + task :cmark do + CMarkBuilder.new(Arch.armv7a).compile + end + end + + namespace :make do + desc "Configure, Build and Install ICU" + task :icu do + ICUBuilder.new(Arch.armv7a).make + end + desc "Configure, Build and Install Swift" + task :swift do + SwiftBuilder.new(Arch.armv7a).make + end + desc "Configure, Build and Install LLVM" task :llvm do LLVMBuilder.new(Arch.armv7a).make end + desc "Configure, Build and Install CMark" + task :cmark do + CMarkBuilder.new(Arch.armv7a).make + end end + end namespace :clean do diff --git a/Scripts/Builders/CMarkBuilder.rb b/Scripts/Builders/CMarkBuilder.rb new file mode 100644 index 00000000..ed5787e2 --- /dev/null +++ b/Scripts/Builders/CMarkBuilder.rb @@ -0,0 +1,43 @@ +require_relative "../Common/Builder.rb" + +class CMarkBuilder < Builder + + def initialize(arch = Arch.default) + super(Lib.cmark, arch) + @sources = SwiftBuilder.new(Arch.default).sources + "/cmark" + end + + def configure + # See: $SWIFT_REPO/docs/WindowsBuild.md + cmd = [] + cmd << "cd #{@build} &&" + cmd << "cmake -G Ninja" + cmd << "-DCMAKE_INSTALL_PREFIX=#{@install}" + cmd << "-DCMAKE_BUILD_TYPE=Release" + cmd << @sources + execute cmd.join(" ") + message "LLVM Configure is completed." + end + + def compile + execute "cd #{@build} && ninja" + message "CMark Build is completed." + end + + def install + execute "cd #{@build} && ninja install" + message "CMark Install is completed." + end + + def make + prepare + configure + compile + install + end + + def prepare + execute "mkdir -p #{@build}" + end + +end diff --git a/Scripts/Builders/LLVMBuilder.rb b/Scripts/Builders/LLVMBuilder.rb index bab63aa9..79c1e1f5 100644 --- a/Scripts/Builders/LLVMBuilder.rb +++ b/Scripts/Builders/LLVMBuilder.rb @@ -1,10 +1,5 @@ require_relative "../Common/Builder.rb" -# See: -# - build llvm clang4.0 for android armeabi - https://stackoverflow.com/questions/40122657/build-llvm-clang4-0-for-android-armeabi -# - LLVM Getting Started: https://llvm.org/docs/GettingStarted.html#requirements -# - CLANG Getting Started: http://clang.llvm.org/get_started.html - class LLVMBuilder < Builder def initialize(arch = Arch.default) @@ -13,11 +8,16 @@ def initialize(arch = Arch.default) end def configure + # See: + # - LLVM Getting Started: https://llvm.org/docs/GettingStarted.html#requirements + # - CLANG Getting Started: http://clang.llvm.org/get_started.html cmd = [] cmd << "cd #{@build} &&" cmd << "cmake -G Ninja" cmd << "-DCMAKE_INSTALL_PREFIX=#{@install}" cmd << "-DCMAKE_BUILD_TYPE=Release" + # See: https://stackoverflow.com/questions/40122657/build-llvm-clang4-0-for-android-armeabi + cmd << "-DLLVM_TARGETS_TO_BUILD=\"ARM;AArch64\" -DLLVM_DEFAULT_TARGET_TRIPLE=\"arm-linux-androideabi\"" cmd << @sources execute cmd.join(" ") message "LLVM Configure is completed." @@ -25,7 +25,7 @@ def configure def compile execute "cd #{@build} && ninja" - message "LLVM Compile is completed." + message "LLVM Build is completed." end def install diff --git a/Scripts/Common/Lib.rb b/Scripts/Common/Lib.rb index c453dc7c..4831ce73 100644 --- a/Scripts/Common/Lib.rb +++ b/Scripts/Common/Lib.rb @@ -16,4 +16,8 @@ def self.llvm return "llvm" end + def self.cmark + return "cmark" + end + end From a3fdeba52faef6fb8efca8a3ba3551030c2dc450 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 15:21:16 +0100 Subject: [PATCH 28/66] Scripts update. --- Scripts/Builders/LLVMBuilder.rb | 3 ++- Scripts/Builders/SwiftBuilder.rb | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Scripts/Builders/LLVMBuilder.rb b/Scripts/Builders/LLVMBuilder.rb index 79c1e1f5..b48469e1 100644 --- a/Scripts/Builders/LLVMBuilder.rb +++ b/Scripts/Builders/LLVMBuilder.rb @@ -17,7 +17,8 @@ def configure cmd << "-DCMAKE_INSTALL_PREFIX=#{@install}" cmd << "-DCMAKE_BUILD_TYPE=Release" # See: https://stackoverflow.com/questions/40122657/build-llvm-clang4-0-for-android-armeabi - cmd << "-DLLVM_TARGETS_TO_BUILD=\"ARM;AArch64\" -DLLVM_DEFAULT_TARGET_TRIPLE=\"arm-linux-androideabi\"" + # Line below still cause build failure. + # cmd << "-DLLVM_TARGETS_TO_BUILD=\"ARM;AArch64\" -DLLVM_DEFAULT_TARGET_TRIPLE=\"arm-linux-androideabi\"" cmd << @sources execute cmd.join(" ") message "LLVM Configure is completed." diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 7cdf06be..fb324161 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -38,6 +38,8 @@ def initialize(arch = Arch.default) super(Lib.swift, arch) @icu = ICUBuilder.new(arch) @ndk = AndroidBuilder.new(arch) + @cmark = CMarkBuilder.new(arch) + @llvm = LLVMBuilder.new(arch) end def compileOLD @@ -86,6 +88,35 @@ def compileNew execute cmd.join(" ") end + def configure + # See: SWIFT_GIT_ROOT/docs/WindowsBuild.md + cmd = [] + cmd << "cd #{@build} &&" + cmd << "cmake -G Ninja" + # -DCMAKE_C_COMPILER="%llvm_bin_dir%/clang-cl.exe"^ + # -DCMAKE_CXX_COMPILER="%llvm_bin_dir%/clang-cl.exe"^ + # cmd << "-DCMAKE_CXX_FLAGS="-Wno-c++98-compat -Wno-c++98-compat-pedantic"^ + # cmd << "-DCMAKE_EXE_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^ + # cmd << "-DCMAKE_SHARED_LINKER_FLAGS="/INCREMENTAL:NO"^ + cmd << "-DCMAKE_INSTALL_PREFIX=\"#{@install}\"" + cmd << "-DCMAKE_BUILD_TYPE=Release" + cmd << "-DSWIFT_PATH_TO_CMARK_SOURCE=\"#{@cmark.source}\"" + cmd << "-DSWIFT_INCLUDE_DOCS=NO" + cmd << "-DSWIFT_PATH_TO_LLVM_SOURCE=\"#{@llvm.source}\"" + cmd << "-DSWIFT_PATH_TO_CLANG_SOURCE=\"#{@llvm.source}/tools/clang\"" + cmd << "-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=\"#{@source}/../swift-corelibs-libdispatch\"" + cmd << "-DSWIFT_PATH_TO_LLVM_BUILD=\"#{@llvm.install}\"" + cmd << "-DSWIFT_PATH_TO_CLANG_BUILD=\"#{@llvm.install}\"" + cmd << "-DSWIFT_PATH_TO_CMARK_BUILD=\"#{@cmark.install}\"" + # -DSWIFT_WINDOWS_x86_64_ICU_UC_INCLUDE="%swift_source_dir%/icu/include"^ + # -DSWIFT_WINDOWS_x86_64_ICU_UC="%swift_source_dir%/icu/lib64/icuuc.lib"^ + # -DSWIFT_WINDOWS_x86_64_ICU_I18N_INCLUDE="%swift_source_dir%/icu/include"^ + # -DSWIFT_WINDOWS_x86_64_ICU_I18N="%swift_source_dir%/icu/lib64/icuin.lib"^ + cmd << @sources + execute cmd.join(" ") + message "Swift Configure is completed." + end + def compile puts "Implement Me" end From 6d56ea5254ae01e41d77aa36e490a9e0814e3778 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 15:41:28 +0100 Subject: [PATCH 29/66] Readme update. --- Readme.md | 13 +++---------- Scripts/Shell/bootstrap.sh | 8 ++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Readme.md b/Readme.md index 7bd31091..46170caf 100644 --- a/Readme.md +++ b/Readme.md @@ -46,6 +46,8 @@ I. Initial setup ```bash host$ vagrant up + # (Optionall) Take snapshot. Under the hood it will save VirtualBox snapshot. + host$ vagrant snapshot save "Clean System" host$ vagrant ssh ``` @@ -54,21 +56,12 @@ I. Initial setup 7. (Optionall) Verify Ubuntu version and Explore synced folders. ```bash - box$ lsb_release -irc box$ ls -l /vagrant ``` **Note**: You should see this `Readme.md` file inside Ubuntu Box. -8. (Optionall) Take snapshot. - - ```bash - host$ vagrant snapshot save "Clean System" - ``` - - **Note**: Under the hood it will save VirtualBox snapshot. - -9. (Optional) Setting Up Visual Studio Code +8. (Optional) Setting Up Visual Studio Code If you going to edit Ruby files, then it worth to install Visual Studio Code for macOS and Ruby plugin. diff --git a/Scripts/Shell/bootstrap.sh b/Scripts/Shell/bootstrap.sh index 56c2f9d7..fc9cfe9a 100755 --- a/Scripts/Shell/bootstrap.sh +++ b/Scripts/Shell/bootstrap.sh @@ -22,4 +22,12 @@ echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ruby --version rake --version echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" +echo "Ubuntu version" +echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" +lsb_release -irc +echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" +echo "Synched folder Contents" +echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" +ls -l /vagrant +echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "Done!" From 85b236149eefdaeebb5330fc8c4ebf07b556e8e7 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 16:08:04 +0100 Subject: [PATCH 30/66] Readme update. --- Readme.md | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Readme.md b/Readme.md index 46170caf..5a1954c6 100644 --- a/Readme.md +++ b/Readme.md @@ -47,33 +47,29 @@ I. Initial setup ```bash host$ vagrant up # (Optionall) Take snapshot. Under the hood it will save VirtualBox snapshot. - host$ vagrant snapshot save "Clean System" - host$ vagrant ssh - ``` - **Note**: Box will be created in directory specified in VirtualBox settings. Detalis in [this post](http://www.thisprogrammingthing.com/2013/changing-the-directory-vagrant-stores-the-vms-in/). + host$ vagrant snapshot save "Clean System" -7. (Optionall) Verify Ubuntu version and Explore synced folders. + host$ vagrant ssh - ```bash + # (Optionall) Explore synced folders. You should see this `Readme.md` file inside Ubuntu Box. box$ ls -l /vagrant ``` - **Note**: You should see this `Readme.md` file inside Ubuntu Box. + **Note**: Box will be created in directory specified in VirtualBox settings. Detalis in [this post](http://www.thisprogrammingthing.com/2013/changing-the-directory-vagrant-stores-the-vms-in/). -8. (Optional) Setting Up Visual Studio Code +7. (Optional) Setting Up Visual Studio Code If you going to edit Ruby files, then it worth to install Visual Studio Code for macOS and Ruby plugin. - Visual Studio Code: https://code.visualstudio.com - Ruby language support: https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby -II. Usage -========= +8. Start a build. -Remaining process of compilling Swift Toolchain, building and deploying sample projects automated via Rakefile. + **Note**: Process of compilling Swift Toolchain, building and deploying sample projects automated via Rakefile. -```bash -box$ cd /vagrant/ -box$ rake -``` + ```bash + box$ cd /vagrant/ + box$ rake + ``` From 8944227ff1ead54d162b1ea146e1eb7806462e37 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 16:08:37 +0100 Subject: [PATCH 31/66] Readme update. --- Readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index 5a1954c6..fe4e862e 100644 --- a/Readme.md +++ b/Readme.md @@ -1,5 +1,5 @@ -I. Initial setup -================ +Setup and Build +=============== **Note**: Every time you see `host$` – this means that command should be executed on **HOST** macOS computer. Every time you see `box$` – this means that command should be executed on virtual **GUEST** Linux OS. @@ -71,5 +71,5 @@ I. Initial setup ```bash box$ cd /vagrant/ - box$ rake + box$ rake | more ``` From 8f762d193d992091916534e0261a7626b478504c Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 16:50:33 +0100 Subject: [PATCH 32/66] Scripts update. --- Rakefile | 14 ++++++++++++-- Scripts/Builders/AndroidBuilder.rb | 1 - Scripts/Builders/CMarkBuilder.rb | 5 ++++- Scripts/Builders/ClangBuilder.rb | 13 +++++++++++++ Scripts/Builders/CompilerRTBuilder.rb | 13 +++++++++++++ Scripts/Builders/ICUBuilder.rb | 5 +++-- Scripts/Builders/LLVMBuilder.rb | 3 +-- Scripts/Builders/SwiftBuilder.rb | 5 +---- Scripts/Common/Builder.rb | 6 +++--- Scripts/Common/Lib.rb | 8 ++++++++ 10 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 Scripts/Builders/ClangBuilder.rb create mode 100644 Scripts/Builders/CompilerRTBuilder.rb diff --git a/Rakefile b/Rakefile index 5034981e..e765df0f 100755 --- a/Rakefile +++ b/Rakefile @@ -11,6 +11,8 @@ require_relative "Scripts/Builders/XMLBuilder.rb" require_relative "Scripts/Builders/HelloProjectBuilder.rb" 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" # References: @@ -26,9 +28,9 @@ task :usage do Building Swift Toolchain. Steps: 1. Checkout Sources. - rake checkout:swift rake checkout:ndk rake checkout:icu + rake checkout:swift Alternatively you can download Android NDK manually form https://developer.android.com/ndk/downloads/ and put it into Downloads folder. @@ -65,8 +67,9 @@ end namespace :checkout do - desc "Checkout Swift" + desc "Checkout Swift, CMark" task :swift do + CMarkBuilder.new().checkout SwiftBuilder.new().checkout end @@ -75,6 +78,13 @@ namespace :checkout do ICUBuilder.new().checkout end + desc "Checkout LLVM, Clang, Compiler-RT" + task :llvm do + LLVMBuilder.new().checkout + ClangBuilder.new().checkout + CompilerRTBuilder.new().checkout + end + desc "Download Android NDK" task :ndk do AndroidBuilder.new().download diff --git a/Scripts/Builders/AndroidBuilder.rb b/Scripts/Builders/AndroidBuilder.rb index c9ef6102..dca1c4e6 100755 --- a/Scripts/Builders/AndroidBuilder.rb +++ b/Scripts/Builders/AndroidBuilder.rb @@ -8,7 +8,6 @@ def api def initialize(arch = Arch.default) super(Lib.ndk, arch) - @installDir = Config.ndkInstallRoot + "/#{@arch}" end def download() diff --git a/Scripts/Builders/CMarkBuilder.rb b/Scripts/Builders/CMarkBuilder.rb index ed5787e2..a5a20754 100644 --- a/Scripts/Builders/CMarkBuilder.rb +++ b/Scripts/Builders/CMarkBuilder.rb @@ -4,7 +4,6 @@ class CMarkBuilder < Builder def initialize(arch = Arch.default) super(Lib.cmark, arch) - @sources = SwiftBuilder.new(Arch.default).sources + "/cmark" end def configure @@ -19,6 +18,10 @@ def configure message "LLVM Configure is completed." end + def checkout + checkoutIfNeeded(@sources, "https://github.com/commonmark/cmark.git") + end + def compile execute "cd #{@build} && ninja" message "CMark Build is completed." diff --git a/Scripts/Builders/ClangBuilder.rb b/Scripts/Builders/ClangBuilder.rb new file mode 100644 index 00000000..96a8597b --- /dev/null +++ b/Scripts/Builders/ClangBuilder.rb @@ -0,0 +1,13 @@ +require_relative "../Common/Builder.rb" + +class ClangBuilder < Builder + + def initialize(arch = Arch.default) + super(Lib.clang, arch) + end + + def checkout + checkoutIfNeeded(@sources, "https://git.llvm.org/git/clang.git") + end + +end diff --git a/Scripts/Builders/CompilerRTBuilder.rb b/Scripts/Builders/CompilerRTBuilder.rb new file mode 100644 index 00000000..2494ccb6 --- /dev/null +++ b/Scripts/Builders/CompilerRTBuilder.rb @@ -0,0 +1,13 @@ +require_relative "../Common/Builder.rb" + +class CompilerRTBuilder < Builder + + def initialize(arch = Arch.default) + super(Lib.crt, arch) + end + + def checkout + checkoutIfNeeded(@sources, "https://git.llvm.org/git/compiler-rt.git") + end + +end diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index 59bacbd6..91bba5c9 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -13,7 +13,8 @@ class ICUBuilder < Builder def initialize(arch = Arch.default) super(Lib.icu, arch) - @sources = "#{Config.sources}/#{Lib.icu}/icu4c" + @gitRepoRoot = "#{Config.sources}/#{Lib.icu}" + @sources = "#{@gitRepoRoot}/icu4c" @ndk = AndroidBuilder.new(arch) if arch != "linux" @host = ICUBuilder.new("linux") @@ -91,7 +92,7 @@ def configure end def checkout - checkoutIfNeeded(@sources, "https://github.com/unicode-org/icu.git") + checkoutIfNeeded(@gitRepoRoot, "https://github.com/unicode-org/icu.git") end def prepare() diff --git a/Scripts/Builders/LLVMBuilder.rb b/Scripts/Builders/LLVMBuilder.rb index b48469e1..f1f98c55 100644 --- a/Scripts/Builders/LLVMBuilder.rb +++ b/Scripts/Builders/LLVMBuilder.rb @@ -4,7 +4,6 @@ class LLVMBuilder < Builder def initialize(arch = Arch.default) super(Lib.llvm, arch) - @sources = SwiftBuilder.new(Arch.default).sources + "/llvm" end def configure @@ -42,7 +41,7 @@ def make end def checkout - puts "Implement LLVM Download" + checkoutIfNeeded(@sources, "https://git.llvm.org/git/llvm.git") end def prepare() diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index fb324161..8a240c94 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -148,10 +148,7 @@ def update end def checkout - dir = @sources + "/swift" - checkoutIfNeeded(dir, "https://github.com/apple/swift.git") - execute "cd \"#{dir}\" && ./swift/utils/update-checkout --clone" - message "#{Lib.swift} checkout completed." + checkoutIfNeeded(@sources, "https://github.com/apple/swift.git") end def clean diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index 188c5436..3db9dedf 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -24,12 +24,12 @@ def lib def checkoutIfNeeded(localPath, repoURL) if File.exist?(localPath) - message "Repository #{repoURL} seems already checked out." + message "Repository \"#{repoURL}\" seems already checked out to \"#{localPath}\"." else dir = File.dirname(localPath) execute "mkdir -p \"#{dir}\"" - execute "cd \"#{dir}\" && git clone --depth=100 #{repoURL}" - message "#{repoURL} checkout completed." + execute "cd \"#{dir}\" && git clone --depth=10 #{repoURL}" + message "#{repoURL} checkout to \"#{localPath}\" is completed." end end diff --git a/Scripts/Common/Lib.rb b/Scripts/Common/Lib.rb index 4831ce73..e42188d9 100644 --- a/Scripts/Common/Lib.rb +++ b/Scripts/Common/Lib.rb @@ -20,4 +20,12 @@ def self.cmark return "cmark" end + def self.clang + return "clang" + end + + def self.crt + return "compiler-rt" + end + end From 3bb6b3aab550515053c0916acdadb2ac4d534b54 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 17:05:25 +0100 Subject: [PATCH 33/66] Scripts update. --- Rakefile | 16 +++++++++------- Scripts/Builders/LLVMBuilder.rb | 7 +++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index e765df0f..42ebd421 100755 --- a/Rakefile +++ b/Rakefile @@ -28,16 +28,18 @@ task :usage do Building Swift Toolchain. Steps: 1. Checkout Sources. - rake checkout:ndk rake checkout:icu + rake checkout:llvm rake checkout:swift + rake checkout:ndk - Alternatively you can download Android NDK manually form https://developer.android.com/ndk/downloads/ and put it into Downloads folder. + Alternatively you can download Android NDK manually form https://developer.android.com/ndk/downloads/ and put archive to Downloads folder. 2. Configure and Build Sources: - rake build:armv7a:ndk - rake build:armv7a:icu - rake build:armv7a:swift + rake armv7a:setup:ndk + rake armv7a:build:llvm + rake armv7a:build:icu + rake armv7a:build:cmark 3. Build `Hello` project. Execute: "rake project:hello:build" @@ -120,7 +122,7 @@ namespace :armv7a do end end - namespace :build do + namespace :compile do desc "Build ICU" task :icu do ICUBuilder.new(Arch.armv7a).compile @@ -139,7 +141,7 @@ namespace :armv7a do end end - namespace :make do + namespace :build do desc "Configure, Build and Install ICU" task :icu do ICUBuilder.new(Arch.armv7a).make diff --git a/Scripts/Builders/LLVMBuilder.rb b/Scripts/Builders/LLVMBuilder.rb index f1f98c55..4d148825 100644 --- a/Scripts/Builders/LLVMBuilder.rb +++ b/Scripts/Builders/LLVMBuilder.rb @@ -4,6 +4,8 @@ class LLVMBuilder < Builder def initialize(arch = Arch.default) super(Lib.llvm, arch) + @clang = ClangBuilder.new() + @crt = CompilerRTBuilder.new() end def configure @@ -46,6 +48,11 @@ def checkout def prepare() execute "mkdir -p #{@build}" + # Making needed SymLinks. See: https://llvm.org/docs/GettingStarted.html#git-mirror + message "Making symbolic links..." + execute "ln -svf \"#{@clang.sources}\" \"#{@sources}/tools\"" + execute "ln -svf \"#{@crt.sources}\" \"#{@sources}/projects\"" + message "LLVM Prepare is Done!" end end From e04b7c32fe95c4ac10aa76e4a0d3d42e4f2155fd Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 17:10:04 +0100 Subject: [PATCH 34/66] Scripts update. --- Rakefile | 12 ++++++------ Scripts/Builders/LLVMBuilder.rb | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index 42ebd421..7b26b632 100755 --- a/Rakefile +++ b/Rakefile @@ -160,12 +160,7 @@ namespace :armv7a do end end -end - -namespace :clean do - - namespace :armv7a do - + namespace :clean do desc "Clean ICU." task :icu do ICUBuilder.new(Arch.armv7a).clean @@ -180,6 +175,11 @@ namespace :clean do task :swift do SwiftBuilder.new(Arch.armv7a).clean end + + desc "LLVM Swift." + task :llvm do + LLVMBuilder.new(Arch.armv7a).clean + end end end diff --git a/Scripts/Builders/LLVMBuilder.rb b/Scripts/Builders/LLVMBuilder.rb index 4d148825..5b4b6feb 100644 --- a/Scripts/Builders/LLVMBuilder.rb +++ b/Scripts/Builders/LLVMBuilder.rb @@ -19,7 +19,8 @@ def configure cmd << "-DCMAKE_BUILD_TYPE=Release" # See: https://stackoverflow.com/questions/40122657/build-llvm-clang4-0-for-android-armeabi # Line below still cause build failure. - # cmd << "-DLLVM_TARGETS_TO_BUILD=\"ARM;AArch64\" -DLLVM_DEFAULT_TARGET_TRIPLE=\"arm-linux-androideabi\"" + cmd << "-DLLVM_TARGETS_TO_BUILD=\"ARM;AArch64;X86\"" + # cmd << "-DLLVM_DEFAULT_TARGET_TRIPLE=\"arm-linux-androideabi\"" cmd << @sources execute cmd.join(" ") message "LLVM Configure is completed." @@ -55,4 +56,9 @@ def prepare() message "LLVM Prepare is Done!" end + def clean + execute "rm -rf #{@build}" + execute "rm -rf #{@install}" + end + end From db9e242f2f7378ba57c0cb8b45812d6e34b9ee48 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 17:28:14 +0100 Subject: [PATCH 35/66] Scripts update. --- Scripts/Builders/DispatchBuilder.rb | 52 ++++++++++++++--------------- Scripts/Builders/SwiftBuilder.rb | 44 ++++++++++++------------ Scripts/Common/Builder.rb | 4 +++ Scripts/Common/Lib.rb | 4 +++ 4 files changed, 55 insertions(+), 49 deletions(-) diff --git a/Scripts/Builders/DispatchBuilder.rb b/Scripts/Builders/DispatchBuilder.rb index 5ae4d0e3..b9cf5dc4 100644 --- a/Scripts/Builders/DispatchBuilder.rb +++ b/Scripts/Builders/DispatchBuilder.rb @@ -6,70 +6,68 @@ # - Cmake. Cross Compiling for Android: https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#id20 class DispatchBuilder < Builder - def initialize(target = "armv7a") - super() - @target = target - @sourcesDir = Config.swiftSourcesRoot + "/swift-corelibs-libdispatch" - @buildDir = Config.buildRoot + "/dispatch/" + @target - @installDir = Config.dispatchInstallRoot + "/" + @target + def initialize(arch = Arch.default) + super(Lib.swift, arch) + @llvm = LLVMBuilder.new(arch) + @swift = SwiftBuilder.new(arch) @swiftCCRoot = "#{Config.swiftBuildRoot}/swift-linux-x86_64" - @llvmCCRoot = "#{Config.swiftBuildRoot}/llvm-linux-x86_64" + @ndk = AndroidBuilder.new(arch) end def prepare - execute "mkdir -p #{@buildDir}" - execute "mkdir -p #{@installDir}" + execute "mkdir -p #{@build}" end def args cmd = [] - cmd << "CLANG=\"#{@llvmCCRoot}/bin/clang\"" - cmd << "CC=\"#{@llvmCCRoot}/bin/clang\"" - cmd << "CXX=\"#{@llvmCCRoot}/bin/clang++\"" - cmd << "SWIFT=\"#{@swiftCCRoot}/bin/swift\"" - cmd << "SWIFTC=\"#{@swiftCCRoot}/bin/swiftc\"" + cmd << "CLANG=\"#{@llvm.bin}/clang\"" + cmd << "CC=\"#{@llvm.bin}/clang\"" + cmd << "CXX=\"#{@llvm.bin}/clang++\"" + cmd << "SWIFT=\"#{@swift.bin}/swift\"" + cmd << "SWIFTC=\"#{@swift.bin}/swiftc\"" return cmd end def options # See: /swift/swift-corelibs-libdispatch/INSTALL.md cmd = [] - cmd << "-DCMAKE_C_COMPILER=#{@llvmCCRoot}/bin/clang -DCMAKE_CXX_COMPILER=#{@llvmCCRoot}/bin/clang++" + cmd << "-DCMAKE_C_COMPILER=#{@llvm.bin}/clang -DCMAKE_CXX_COMPILER=#{@llvm.bin}/clang++" cmd << "-DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a" cmd << "-DCMAKE_ANDROID_NDK_TOOLCHAIN_VERSION=clang" - cmd << "-DCMAKE_ANDROID_STL_TYPE=\"c++_static\" -DCMAKE_BUILD_TYPE=Release" + cmd << "-DCMAKE_ANDROID_STL_TYPE=\"c++_static\"" + cmd << "-DCMAKE_BUILD_TYPE=Release" cmd << "-DENABLE_SWIFT=true" - cmd << "-DCMAKE_SWIFT_COMPILER=\"#{@swiftCCRoot}/bin/swiftc\"" - cmd << "-DCMAKE_PREFIX_PATH=\"#{@swiftCCRoot}/lib/cmake/swift\"" - cmd << "-DCMAKE_INSTALL_PREFIX=#{@installDir}" - cmd << "-DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=#{Config.androidAPI} -DCMAKE_ANDROID_NDK=#{Config.ndkSourcesRoot}" + cmd << "-DCMAKE_SWIFT_COMPILER=\"#{@swift.bin}/swiftc\"" + cmd << "-DCMAKE_PREFIX_PATH=\"#{@swift.lib}/cmake/swift\"" + cmd << "-DCMAKE_INSTALL_PREFIX=#{@install}" + cmd << "-DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=#{@ndk.api} -DCMAKE_ANDROID_NDK=#{@ndk.sources}" return cmd end def configure cmd = [] - cmd << "cd #{@buildDir} &&" + cmd << "cd #{@build} &&" cmd += args cmd << "cmake -G Ninja" cmd += options - cmd << @sourcesDir + cmd << @sources execute cmd.join(" ") end - def build + def compile # See: What is CMake equivalent of 'configure --prefix=DIR && make all install: https://stackoverflow.com/a/35753015/1418981 - execute "cd #{@buildDir} && cmake " + options.join(" ") + " . && " + args.join(" ") + " ninja install" + execute "cd #{@build} && cmake " + options.join(" ") + " . && " + args.join(" ") + " ninja install" end def make prepare configure - build + compile end def clean - execute "rm -rf \"#{@buildDir}\"" - execute "rm -rf \"#{@installDir}\"" + execute "rm -rf \"#{@build}\"" + execute "rm -rf \"#{@install}\"" end end diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 8a240c94..362fd2c7 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -40,6 +40,7 @@ def initialize(arch = Arch.default) @ndk = AndroidBuilder.new(arch) @cmark = CMarkBuilder.new(arch) @llvm = LLVMBuilder.new(arch) + @clang = ClangBuilder.new(arch) end def compileOLD @@ -100,13 +101,13 @@ def configure # cmd << "-DCMAKE_SHARED_LINKER_FLAGS="/INCREMENTAL:NO"^ cmd << "-DCMAKE_INSTALL_PREFIX=\"#{@install}\"" cmd << "-DCMAKE_BUILD_TYPE=Release" - cmd << "-DSWIFT_PATH_TO_CMARK_SOURCE=\"#{@cmark.source}\"" cmd << "-DSWIFT_INCLUDE_DOCS=NO" cmd << "-DSWIFT_PATH_TO_LLVM_SOURCE=\"#{@llvm.source}\"" - cmd << "-DSWIFT_PATH_TO_CLANG_SOURCE=\"#{@llvm.source}/tools/clang\"" + cmd << "-DSWIFT_PATH_TO_CLANG_SOURCE=\"#{@clang.source}\"" + cmd << "-DSWIFT_PATH_TO_CMARK_SOURCE=\"#{@cmark.source}\"" cmd << "-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=\"#{@source}/../swift-corelibs-libdispatch\"" cmd << "-DSWIFT_PATH_TO_LLVM_BUILD=\"#{@llvm.install}\"" - cmd << "-DSWIFT_PATH_TO_CLANG_BUILD=\"#{@llvm.install}\"" + cmd << "-DSWIFT_PATH_TO_CLANG_BUILD=\"#{@clang.install}\"" cmd << "-DSWIFT_PATH_TO_CMARK_BUILD=\"#{@cmark.install}\"" # -DSWIFT_WINDOWS_x86_64_ICU_UC_INCLUDE="%swift_source_dir%/icu/include"^ # -DSWIFT_WINDOWS_x86_64_ICU_UC="%swift_source_dir%/icu/lib64/icuuc.lib"^ @@ -121,30 +122,29 @@ def compile puts "Implement Me" end + def install + puts "Implement Me" + end + def prepare - targetFile = "/usr/bin/armv7-none-linux-androideabi-ld.gold" - if File.exist?(targetFile) - return - end - puts "Making symbolic link to \"#{targetFile}\"..." - cmd = ["sudo"] - cmd << "ln -svf #{@ndk.sources}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/ld.gold" - cmd << targetFile - execute cmd.join(" ") - execute "ls -a /usr/bin/*ld.gold" + execute "mkdir -p #{@build}" + # targetFile = "/usr/bin/armv7-none-linux-androideabi-ld.gold" + # if File.exist?(targetFile) + # return + # end + # puts "Making symbolic link to \"#{targetFile}\"..." + # cmd = ["sudo"] + # cmd << "ln -svf #{@ndk.sources}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/ld.gold" + # cmd << targetFile + # execute cmd.join(" ") + # execute "ls -a /usr/bin/*ld.gold" end def make - # prepare + prepare + configure compile - end - - def help - execute "cd #{@sources} && ./swift/utils/build-script --help | more" - end - - def update - execute "cd #{@sources} && ./swift/utils/update-checkout" + install end def checkout diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index 3db9dedf..084945dc 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -22,6 +22,10 @@ def lib return @install + "/lib" end + def bin + return @install + "/bin" + end + def checkoutIfNeeded(localPath, repoURL) if File.exist?(localPath) message "Repository \"#{repoURL}\" seems already checked out to \"#{localPath}\"." diff --git a/Scripts/Common/Lib.rb b/Scripts/Common/Lib.rb index e42188d9..7c4139fc 100644 --- a/Scripts/Common/Lib.rb +++ b/Scripts/Common/Lib.rb @@ -28,4 +28,8 @@ def self.crt return "compiler-rt" end + def self.dispatch + return "swift-corelibs-libdispatch" + end + end From 2c8a0e088ca6d1ef3274615e8a6152b94b8bdcd8 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 18:12:04 +0100 Subject: [PATCH 36/66] Scripts update. --- Scripts/Builders/DispatchBuilder.rb | 1 - Scripts/Builders/FoundationBuilder.rb | 91 ++++++++++++++------------- Scripts/Common/Builder.rb | 8 +++ Scripts/Common/Lib.rb | 4 ++ 4 files changed, 58 insertions(+), 46 deletions(-) diff --git a/Scripts/Builders/DispatchBuilder.rb b/Scripts/Builders/DispatchBuilder.rb index b9cf5dc4..cc176e72 100644 --- a/Scripts/Builders/DispatchBuilder.rb +++ b/Scripts/Builders/DispatchBuilder.rb @@ -10,7 +10,6 @@ def initialize(arch = Arch.default) super(Lib.swift, arch) @llvm = LLVMBuilder.new(arch) @swift = SwiftBuilder.new(arch) - @swiftCCRoot = "#{Config.swiftBuildRoot}/swift-linux-x86_64" @ndk = AndroidBuilder.new(arch) end diff --git a/Scripts/Builders/FoundationBuilder.rb b/Scripts/Builders/FoundationBuilder.rb index d4f064d5..a09cf56f 100644 --- a/Scripts/Builders/FoundationBuilder.rb +++ b/Scripts/Builders/FoundationBuilder.rb @@ -5,69 +5,70 @@ # - Libdispatch issues with CMake: https://forums.swift.org/t/libdispatch-switched-to-cmake/6665/7 class FoundationBuilder < Builder - def initialize(target = "armv7a") - super() - @target = target - @sourcesDir = Config.swiftSourcesRoot + "/swift-corelibs-foundation" - @buildDir = Config.buildRoot + "/foundation/" + @target - @installDir = Config.installRoot + "/foundation/" + @target - - @ndkToolchainPath = "#{Config.ndkInstallRoot}/#{@target}" - @ndkToolchainBinPath = "#{@ndkToolchainPath}/bin" - @ndkToolchainSysPath = "#{@ndkToolchainPath}/sysroot" + def initialize(arch = Arch.default) + super(Lib.swift, arch) + @ndk = AndroidBuilder.new(arch) + @dispatch = DispatchBuilder.new(arch) + @swift = SwiftBuilder.new(arch) + @curl = CurlBuilder.new(arch) + @icu = ICUBuilder.new(arch) + @xml = XMLBuilder.new(arch) + @llvm = LLVMBuilder.new(arch) end def prepare - execute "mkdir -p #{@buildDir}" - execute "mkdir -p #{@installDir}" + execute "mkdir -p #{@build}" + copyFiles + end + def copyFiles + usr = @ndk.install + "/sysroot/usr" # Copy dispatch public and private headers to the directory foundation is expecting to get it - targetDir = "#{@ndkToolchainSysPath}/usr/include/dispatch" + targetDir = "#{usr}/include/dispatch" execute "mkdir -p #{targetDir}" - execute "cp -v #{Config.swiftSourcesRoot}/swift-corelibs-libdispatch/dispatch/*.h #{targetDir}" - execute "cp -v #{Config.swiftSourcesRoot}/swift-corelibs-libdispatch/private/*.h #{targetDir}" + execute "cp -v #{@dispatch.sources}/dispatch/*.h #{targetDir}" + execute "cp -v #{@dispatch.sources}/private/*.h #{targetDir}" # libFoundation script is not completely prepared to handle cross compilation yet. - execute "ln -svf #{Config.swiftBuildRoot}/swift-linux-x86_64/lib/swift #{@ndkToolchainSysPath}/usr/lib/" - execute "cp -vr #{Config.swiftBuildRoot}/swift-linux-x86_64/lib/swift/android/armv7/* #{Config.swiftBuildRoot}/swift-linux-x86_64/lib/swift/android/" + execute "ln -svf #{@swift.lib}/swift #{usr}/lib/" + execute "cp -vr #{@swift.lib}/swift/android/armv7/* #{@swift.lib}/swift/android/" # Search path for curl seems to be wrong in foundation - execute "cp -rv #{Config.curlInstallRoot}/#{@target}/include/curl #{@ndkToolchainSysPath}/usr/include" - execute "ln -fvs #{@ndkToolchainSysPath}/usr/include/curl #{@ndkToolchainSysPath}/usr/include/curl/curl" + execute "cp -rv #{@curl.include}/curl #{usr}/include" + execute "ln -fvs #{usr}/include/curl #{usr}/include/curl/curl" - execute "cp -rv #{Config.xmlInstallRoot}/#{@target}/include/libxml2 #{@ndkToolchainSysPath}/usr/include" - execute "ln -fvs #{@ndkToolchainSysPath}/usr/include/libxml2/libxml #{@ndkToolchainSysPath}/usr/include/libxml" + execute "cp -rv #{@xml.include}/libxml2 #{usr}/include" + execute "ln -fvs #{usr}/include/libxml2/libxml #{usr}/include/libxml" - execute "cp -vr /usr/include/uuid #{@ndkToolchainSysPath}/usr/include" + execute "cp -vr /usr/include/uuid #{usr}/include" end def args # Arguments took from `swift/swift-corelibs-foundation/build-android` - swiftCCRoot = "#{Config.swiftBuildRoot}/swift-linux-x86_64" - llvmCCRoot = "#{Config.swiftBuildRoot}/llvm-linux-x86_64" - icuRootPath = "#{Config.icuInstallRoot}/#{@target}" + sysroot = @ndk.install + "/sysroot" cmd = [] - cmd << "cd #{@sourcesDir} && env" - cmd << "BUILD_DIR=#{@buildDir}" - cmd << "DSTROOT=#{@installDir}" - - cmd << "SWIFTC=\"#{swiftCCRoot}/bin/swiftc\"" - cmd << "CLANG=\"#{llvmCCRoot}/bin/clang\"" - # cmd << "CLANGXX=\"#{llvmCCRoot}/bin/clang++\"" - cmd << "SWIFT=\"#{swiftCCRoot}/bin/swift\"" - cmd << "SDKROOT=\"#{swiftCCRoot}\"" - cmd << "CFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH --sysroot=#{@ndkToolchainSysPath} -I#{icuRootPath}/include -I#{swiftCCRoot}/lib/swift -I#{Config.ndkSourcesRoot}/sources/android/support/include -I#{@ndkToolchainSysPath}/usr/include -I#{@sourcesDir}/closure\"" - cmd << "SWIFTCFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH -Xcc -DDEPLOYMENT_TARGET_ANDROID -I#{@ndkToolchainSysPath}/usr/include\"" - cmd << "LDFLAGS=\"-fuse-ld=gold --sysroot=#{@ndkToolchainSysPath} -L#{Config.ndkSourcesRoot}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x -L#{icuRootPath}/lib -L#{@ndkToolchainSysPath}/usr/lib -ldispatch\"" + cmd << "cd #{@sources} && env" + cmd << "BUILD_DIR=#{@build}" + cmd << "DSTROOT=#{@install}" + + cmd << "SWIFTC=\"#{@swift.bin}/swiftc\"" + cmd << "CLANG=\"#{@llvm.bin}/clang\"" + # cmd << "CLANGXX=\"#{@llvm.bin}/clang++\"" + cmd << "SWIFT=\"#{@swift.bin}/swift\"" + cmd << "SDKROOT=\"#{@swift.install}\"" + cmd << "CFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH --sysroot=#{sysroot} -I#{@icu.include} -I#{@swift.lib}/swift -I#{@ndk.sources}/sources/android/support/include -I#{sysroot}/usr/include -I#{@sources}/closure\"" + cmd << "SWIFTCFLAGS=\"-DDEPLOYMENT_TARGET_ANDROID -DDEPLOYMENT_ENABLE_LIBDISPATCH -Xcc -DDEPLOYMENT_TARGET_ANDROID -I#{sysroot}/usr/include\"" + cmd << "LDFLAGS=\"-fuse-ld=gold --sysroot=#{sysroot} -L#{@ndk.sources}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x -L#{@icu.lib} -L#{sysroot}/usr/lib -ldispatch\"" return cmd end def configure + sysroot = @ndk.install + "/sysroot" cmd = args - cmd << "./configure Release --target=armv7-none-linux-androideabi --sysroot=#{@ndkToolchainSysPath}" + cmd << "./configure Release --target=armv7-none-linux-androideabi --sysroot=#{sysroot}" # cmd << "-DXCTEST_BUILD_DIR=#{swiftCCRoot}/xctest-linux-x86_64" - cmd << "-DLIBDISPATCH_SOURCE_DIR=#{Config.swiftSourcesRoot}/swift-corelibs-libdispatch" - cmd << "-DLIBDISPATCH_BUILD_DIR=#{Config.dispatchInstallRoot}/#{@target}" + cmd << "-DLIBDISPATCH_SOURCE_DIR=#{@dispatch.sources}" + cmd << "-DLIBDISPATCH_BUILD_DIR=#{@dispatch.install}" execute cmd.join(" ") execute "cd #{@sourcesDir} && sed --in-place 's/-I\\/usr\\/include\\/x86_64-linux-gnu//' build.ninja" @@ -78,12 +79,12 @@ def configure execute "cd #{@sourcesDir} && sed --in-place 's/-licudata/-licudataswift/g' build.ninja" end - def build + def compile execute args.join(" ") + " ninja CopyHeaders" # Patching module.modulemap file. message "Patching module.modulemap file." - headersPath = "#{@buildDir}/Foundation/usr/lib/swift/CoreFoundation" + headersPath = "#{@build}/Foundation/usr/lib/swift/CoreFoundation" moduleMapPath = headersPath + "/module.modulemap" contents = File.readlines(moduleMapPath).join() contents = contents.sub('"CoreFoundation.h"', '"' + headersPath + '/CoreFoundation.h"') @@ -97,12 +98,12 @@ def build def make prepare configure - build + compile end def clean - execute "rm -rf \"#{@buildDir}\"" - execute "rm -rf \"#{@installDir}\"" + execute "rm -rf \"#{@build}\"" + execute "rm -rf \"#{@install}\"" end end diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index 084945dc..c128b0be 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -26,6 +26,14 @@ def bin return @install + "/bin" end + def include + return @install + "/include" + end + + def usr + return @install + "/usr" + end + def checkoutIfNeeded(localPath, repoURL) if File.exist?(localPath) message "Repository \"#{repoURL}\" seems already checked out to \"#{localPath}\"." diff --git a/Scripts/Common/Lib.rb b/Scripts/Common/Lib.rb index 7c4139fc..ebe57fcb 100644 --- a/Scripts/Common/Lib.rb +++ b/Scripts/Common/Lib.rb @@ -32,4 +32,8 @@ def self.dispatch return "swift-corelibs-libdispatch" end + def self.foundation + return "swift-corelibs-foundation" + end + end From 9f88a190772757a770db9d63e468e91c8e000d2f Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 21:31:54 +0100 Subject: [PATCH 37/66] Fixes. --- Rakefile | 28 ++++++++++++++++++++++++--- Scripts/Builders/CurlBuilder.rb | 13 ++++--------- Scripts/Builders/DispatchBuilder.rb | 14 ++++++++++---- Scripts/Builders/FoundationBuilder.rb | 6 +++++- Scripts/Builders/SwiftBuilder.rb | 3 ++- Scripts/Builders/XMLBuilder.rb | 14 ++++---------- Scripts/Common/Lib.rb | 8 ++++++++ 7 files changed, 58 insertions(+), 28 deletions(-) diff --git a/Rakefile b/Rakefile index 7b26b632..60b61fc1 100755 --- a/Rakefile +++ b/Rakefile @@ -38,8 +38,9 @@ Building Swift Toolchain. Steps: 2. Configure and Build Sources: rake armv7a:setup:ndk rake armv7a:build:llvm - rake armv7a:build:icu rake armv7a:build:cmark + rake armv7a:build:icu + rake armv7a:build:swift 3. Build `Hello` project. Execute: "rake project:hello:build" @@ -69,10 +70,12 @@ end namespace :checkout do - desc "Checkout Swift, CMark" + desc "Checkout Swift, libDispatch, libFoundation, CMark" task :swift do - CMarkBuilder.new().checkout SwiftBuilder.new().checkout + DispatchBuilder.new().checkout + FoundationBuilder.new().checkout + CMarkBuilder.new().checkout end desc "Checkout ICU" @@ -141,6 +144,25 @@ namespace :armv7a do end end + namespace :install do + desc "Install ICU" + task :icu do + ICUBuilder.new(Arch.armv7a).install + end + desc "Install Swift" + task :swift do + SwiftBuilder.new(Arch.armv7a).install + end + desc "Install LLVM" + task :llvm do + LLVMBuilder.new(Arch.armv7a).install + end + desc "Install CMark" + task :cmark do + CMarkBuilder.new(Arch.armv7a).install + end + end + namespace :build do desc "Configure, Build and Install ICU" task :icu do diff --git a/Scripts/Builders/CurlBuilder.rb b/Scripts/Builders/CurlBuilder.rb index 78cd8e6d..c2b5678a 100644 --- a/Scripts/Builders/CurlBuilder.rb +++ b/Scripts/Builders/CurlBuilder.rb @@ -3,21 +3,16 @@ class CurlBuilder < Builder - def initialize(target = "armv7a") - super() - @target = target - @sourcesDir = Config.curlSourcesRoot - @buildDir = Config.buildRoot + "/curl/" + @target - @installDir = Config.installRoot + "/curl/" + @target + def initialize(arch = Arch.default) + super(Lib.curl, arch) end def checkout - checkoutIfNeeded(@sourcesDir, "https://github.com/curl/curl.git") + checkoutIfNeeded(@sources, "https://github.com/curl/curl.git") end def prepare - execute "mkdir -p #{@buildDir}" - execute "mkdir -p #{@installDir}" + execute "mkdir -p #{@build}" end def commonArgs() diff --git a/Scripts/Builders/DispatchBuilder.rb b/Scripts/Builders/DispatchBuilder.rb index cc176e72..c434ebe4 100644 --- a/Scripts/Builders/DispatchBuilder.rb +++ b/Scripts/Builders/DispatchBuilder.rb @@ -7,10 +7,7 @@ class DispatchBuilder < Builder def initialize(arch = Arch.default) - super(Lib.swift, arch) - @llvm = LLVMBuilder.new(arch) - @swift = SwiftBuilder.new(arch) - @ndk = AndroidBuilder.new(arch) + super(Lib.dispatch, arch) end def prepare @@ -18,6 +15,8 @@ def prepare end def args + @llvm = LLVMBuilder.new(arch) + @swift = SwiftBuilder.new(arch) cmd = [] cmd << "CLANG=\"#{@llvm.bin}/clang\"" cmd << "CC=\"#{@llvm.bin}/clang\"" @@ -28,6 +27,9 @@ def args end def options + @llvm = LLVMBuilder.new(arch) + @swift = SwiftBuilder.new(arch) + @ndk = AndroidBuilder.new(arch) # See: /swift/swift-corelibs-libdispatch/INSTALL.md cmd = [] cmd << "-DCMAKE_C_COMPILER=#{@llvm.bin}/clang -DCMAKE_CXX_COMPILER=#{@llvm.bin}/clang++" @@ -69,4 +71,8 @@ def clean execute "rm -rf \"#{@install}\"" end + def checkout + checkoutIfNeeded(@sources, "https://github.com/apple/swift-corelibs-libdispatch.git") + end + end diff --git a/Scripts/Builders/FoundationBuilder.rb b/Scripts/Builders/FoundationBuilder.rb index a09cf56f..ae76d33f 100644 --- a/Scripts/Builders/FoundationBuilder.rb +++ b/Scripts/Builders/FoundationBuilder.rb @@ -6,7 +6,7 @@ class FoundationBuilder < Builder def initialize(arch = Arch.default) - super(Lib.swift, arch) + super(Lib.foundation, arch) @ndk = AndroidBuilder.new(arch) @dispatch = DispatchBuilder.new(arch) @swift = SwiftBuilder.new(arch) @@ -106,4 +106,8 @@ def clean execute "rm -rf \"#{@install}\"" end + def checkout + checkoutIfNeeded(@sources, "https://github.com/apple/swift-corelibs-foundation") + end + end diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 362fd2c7..b458dedd 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -41,6 +41,7 @@ def initialize(arch = Arch.default) @cmark = CMarkBuilder.new(arch) @llvm = LLVMBuilder.new(arch) @clang = ClangBuilder.new(arch) + @dispatch = DispatchBuilder.new(arch) end def compileOLD @@ -105,7 +106,7 @@ def configure cmd << "-DSWIFT_PATH_TO_LLVM_SOURCE=\"#{@llvm.source}\"" cmd << "-DSWIFT_PATH_TO_CLANG_SOURCE=\"#{@clang.source}\"" cmd << "-DSWIFT_PATH_TO_CMARK_SOURCE=\"#{@cmark.source}\"" - cmd << "-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=\"#{@source}/../swift-corelibs-libdispatch\"" + cmd << "-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=\"#{@dispatch.source}\"" cmd << "-DSWIFT_PATH_TO_LLVM_BUILD=\"#{@llvm.install}\"" cmd << "-DSWIFT_PATH_TO_CLANG_BUILD=\"#{@clang.install}\"" cmd << "-DSWIFT_PATH_TO_CMARK_BUILD=\"#{@cmark.install}\"" diff --git a/Scripts/Builders/XMLBuilder.rb b/Scripts/Builders/XMLBuilder.rb index 8d560c5f..c2bdcf47 100644 --- a/Scripts/Builders/XMLBuilder.rb +++ b/Scripts/Builders/XMLBuilder.rb @@ -2,22 +2,16 @@ class XMLBuilder < Builder - def initialize(target = "armv7a") - super() - @target = target - @sourcesDir = Config.xmlSourcesRoot - @buildDir = Config.buildRoot + "/xml/" + @target - @installDir = Config.installRoot + "/xml/" + @target + def initialize(arch = Arch.default) + super(Lib.xml, arch) end def checkout - downloader = Downloader.new(Config.sourcesRoot, Config.xmlSourcesRoot, "https://github.com/GNOME/libxml2/archive/v2.9.8.tar.gz", 'libxml2-*') - downloader.bootstrap() + checkoutIfNeeded(@sources, "https://github.com/GNOME/libxml2.git") end def prepare - execute "mkdir -p #{@buildDir}" - execute "mkdir -p #{@installDir}" + execute "mkdir -p #{@build}" end def configure diff --git a/Scripts/Common/Lib.rb b/Scripts/Common/Lib.rb index ebe57fcb..1fa00a1c 100644 --- a/Scripts/Common/Lib.rb +++ b/Scripts/Common/Lib.rb @@ -28,6 +28,14 @@ def self.crt return "compiler-rt" end + def self.curl + return "curl" + end + + def self.xml + return "xml" + end + def self.dispatch return "swift-corelibs-libdispatch" end From cd77586d62720a063c0acb7646554f14b375ba5a Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 21:39:01 +0100 Subject: [PATCH 38/66] Scripts update. --- Rakefile | 12 ++++++------ Scripts/Builders/CMarkBuilder.rb | 14 +++++++------- Scripts/Builders/CurlBuilder.rb | 7 +++---- Scripts/Builders/DispatchBuilder.rb | 14 +++++++------- Scripts/Builders/SwiftBuilder.rb | 26 +++++++++++++------------- Scripts/Common/Builder.rb | 14 +++++++------- 6 files changed, 43 insertions(+), 44 deletions(-) diff --git a/Rakefile b/Rakefile index 60b61fc1..f2342c5b 100755 --- a/Rakefile +++ b/Rakefile @@ -125,22 +125,22 @@ namespace :armv7a do end end - namespace :compile do + namespace :build do desc "Build ICU" task :icu do - ICUBuilder.new(Arch.armv7a).compile + ICUBuilder.new(Arch.armv7a).build end desc "Build Swift" task :swift do - SwiftBuilder.new(Arch.armv7a).compile + SwiftBuilder.new(Arch.armv7a).build end desc "Build LLVM" task :llvm do - LLVMBuilder.new(Arch.armv7a).compile + LLVMBuilder.new(Arch.armv7a).build end desc "Build CMark" task :cmark do - CMarkBuilder.new(Arch.armv7a).compile + CMarkBuilder.new(Arch.armv7a).build end end @@ -163,7 +163,7 @@ namespace :armv7a do end end - namespace :build do + namespace :make do desc "Configure, Build and Install ICU" task :icu do ICUBuilder.new(Arch.armv7a).make diff --git a/Scripts/Builders/CMarkBuilder.rb b/Scripts/Builders/CMarkBuilder.rb index a5a20754..ca31a846 100644 --- a/Scripts/Builders/CMarkBuilder.rb +++ b/Scripts/Builders/CMarkBuilder.rb @@ -9,9 +9,9 @@ def initialize(arch = Arch.default) def configure # See: $SWIFT_REPO/docs/WindowsBuild.md cmd = [] - cmd << "cd #{@build} &&" + cmd << "cd #{@builds} &&" cmd << "cmake -G Ninja" - cmd << "-DCMAKE_INSTALL_PREFIX=#{@install}" + cmd << "-DCMAKE_INSTALL_PREFIX=#{@installs}" cmd << "-DCMAKE_BUILD_TYPE=Release" cmd << @sources execute cmd.join(" ") @@ -22,25 +22,25 @@ def checkout checkoutIfNeeded(@sources, "https://github.com/commonmark/cmark.git") end - def compile - execute "cd #{@build} && ninja" + def build + execute "cd #{@builds} && ninja" message "CMark Build is completed." end def install - execute "cd #{@build} && ninja install" + execute "cd #{@builds} && ninja install" message "CMark Install is completed." end def make prepare configure - compile + build install end def prepare - execute "mkdir -p #{@build}" + execute "mkdir -p #{@builds}" end end diff --git a/Scripts/Builders/CurlBuilder.rb b/Scripts/Builders/CurlBuilder.rb index c2b5678a..ba870f9a 100644 --- a/Scripts/Builders/CurlBuilder.rb +++ b/Scripts/Builders/CurlBuilder.rb @@ -12,7 +12,7 @@ def checkout end def prepare - execute "mkdir -p #{@build}" + execute "mkdir -p #{@builds}" end def commonArgs() @@ -52,12 +52,11 @@ def configure end def build - execute "cd #{@sourcesDir} && make" - execute "cd #{@sourcesDir} && make install" + execute "cd #{@sources} && make" + execute "cd #{@sources} && make install" end def make - checkout prepare configure build diff --git a/Scripts/Builders/DispatchBuilder.rb b/Scripts/Builders/DispatchBuilder.rb index c434ebe4..6bf9fee6 100644 --- a/Scripts/Builders/DispatchBuilder.rb +++ b/Scripts/Builders/DispatchBuilder.rb @@ -11,7 +11,7 @@ def initialize(arch = Arch.default) end def prepare - execute "mkdir -p #{@build}" + execute "mkdir -p #{@builds}" end def args @@ -40,14 +40,14 @@ def options cmd << "-DENABLE_SWIFT=true" cmd << "-DCMAKE_SWIFT_COMPILER=\"#{@swift.bin}/swiftc\"" cmd << "-DCMAKE_PREFIX_PATH=\"#{@swift.lib}/cmake/swift\"" - cmd << "-DCMAKE_INSTALL_PREFIX=#{@install}" + cmd << "-DCMAKE_INSTALL_PREFIX=#{@installs}" cmd << "-DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=#{@ndk.api} -DCMAKE_ANDROID_NDK=#{@ndk.sources}" return cmd end def configure cmd = [] - cmd << "cd #{@build} &&" + cmd << "cd #{@builds} &&" cmd += args cmd << "cmake -G Ninja" cmd += options @@ -55,7 +55,7 @@ def configure execute cmd.join(" ") end - def compile + def build # See: What is CMake equivalent of 'configure --prefix=DIR && make all install: https://stackoverflow.com/a/35753015/1418981 execute "cd #{@build} && cmake " + options.join(" ") + " . && " + args.join(" ") + " ninja install" end @@ -63,12 +63,12 @@ def compile def make prepare configure - compile + build end def clean - execute "rm -rf \"#{@build}\"" - execute "rm -rf \"#{@install}\"" + execute "rm -rf \"#{@builds}\"" + execute "rm -rf \"#{@installs}\"" end def checkout diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index b458dedd..c6aa554f 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -93,23 +93,23 @@ def compileNew def configure # See: SWIFT_GIT_ROOT/docs/WindowsBuild.md cmd = [] - cmd << "cd #{@build} &&" + cmd << "cd #{@builds} &&" cmd << "cmake -G Ninja" # -DCMAKE_C_COMPILER="%llvm_bin_dir%/clang-cl.exe"^ # -DCMAKE_CXX_COMPILER="%llvm_bin_dir%/clang-cl.exe"^ # cmd << "-DCMAKE_CXX_FLAGS="-Wno-c++98-compat -Wno-c++98-compat-pedantic"^ # cmd << "-DCMAKE_EXE_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^ # cmd << "-DCMAKE_SHARED_LINKER_FLAGS="/INCREMENTAL:NO"^ - cmd << "-DCMAKE_INSTALL_PREFIX=\"#{@install}\"" + cmd << "-DCMAKE_INSTALL_PREFIX=\"#{@installs}\"" cmd << "-DCMAKE_BUILD_TYPE=Release" cmd << "-DSWIFT_INCLUDE_DOCS=NO" - cmd << "-DSWIFT_PATH_TO_LLVM_SOURCE=\"#{@llvm.source}\"" - cmd << "-DSWIFT_PATH_TO_CLANG_SOURCE=\"#{@clang.source}\"" - cmd << "-DSWIFT_PATH_TO_CMARK_SOURCE=\"#{@cmark.source}\"" - cmd << "-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=\"#{@dispatch.source}\"" - cmd << "-DSWIFT_PATH_TO_LLVM_BUILD=\"#{@llvm.install}\"" - cmd << "-DSWIFT_PATH_TO_CLANG_BUILD=\"#{@clang.install}\"" - cmd << "-DSWIFT_PATH_TO_CMARK_BUILD=\"#{@cmark.install}\"" + cmd << "-DSWIFT_PATH_TO_LLVM_SOURCE=\"#{@llvm.sources}\"" + cmd << "-DSWIFT_PATH_TO_CLANG_SOURCE=\"#{@clang.sources}\"" + cmd << "-DSWIFT_PATH_TO_CMARK_SOURCE=\"#{@cmark.sources}\"" + cmd << "-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=\"#{@dispatch.sources}\"" + cmd << "-DSWIFT_PATH_TO_LLVM_BUILD=\"#{@llvm.installs}\"" + cmd << "-DSWIFT_PATH_TO_CLANG_BUILD=\"#{@clang.installs}\"" + cmd << "-DSWIFT_PATH_TO_CMARK_BUILD=\"#{@cmark.installs}\"" # -DSWIFT_WINDOWS_x86_64_ICU_UC_INCLUDE="%swift_source_dir%/icu/include"^ # -DSWIFT_WINDOWS_x86_64_ICU_UC="%swift_source_dir%/icu/lib64/icuuc.lib"^ # -DSWIFT_WINDOWS_x86_64_ICU_I18N_INCLUDE="%swift_source_dir%/icu/include"^ @@ -119,7 +119,7 @@ def configure message "Swift Configure is completed." end - def compile + def build puts "Implement Me" end @@ -128,7 +128,7 @@ def install end def prepare - execute "mkdir -p #{@build}" + execute "mkdir -p #{@builds}" # targetFile = "/usr/bin/armv7-none-linux-androideabi-ld.gold" # if File.exist?(targetFile) # return @@ -144,8 +144,8 @@ def prepare def make prepare configure - compile - install + # build + # install end def checkout diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index c128b0be..cd8b5fb0 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -7,31 +7,31 @@ class Builder < Tool - attr_reader :build, :install, :sources + attr_reader :builds, :installs, :sources def initialize(component, arch) @component = component @arch = arch @sources = "#{Config.sources}/#{component}" @patches = "#{Config.patches}/#{component}" - @build = "#{Config.build}/#{component}/#{arch}" - @install = "#{Config.install}/#{component}/#{arch}" + @builds = "#{Config.build}/#{component}/#{arch}" + @installs = "#{Config.install}/#{component}/#{arch}" end def lib - return @install + "/lib" + return @installs + "/lib" end def bin - return @install + "/bin" + return @installs + "/bin" end def include - return @install + "/include" + return @installs + "/include" end def usr - return @install + "/usr" + return @installs + "/usr" end def checkoutIfNeeded(localPath, repoURL) From b395e8473464bfc216613243e06b741ea0923bb9 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 23:17:36 +0100 Subject: [PATCH 39/66] Scripts upade --- Scripts/Builders/CMarkBuilder.rb | 2 +- Scripts/Builders/ClangBuilder.rb | 2 +- Scripts/Builders/CompilerRTBuilder.rb | 2 +- Scripts/Builders/LLVMBuilder.rb | 2 +- Scripts/Builders/SwiftBuilder.rb | 31 ++++++++++++++++++++------- Scripts/Common/Builder.rb | 4 ++++ Scripts/Common/Lib.rb | 8 +++---- 7 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Scripts/Builders/CMarkBuilder.rb b/Scripts/Builders/CMarkBuilder.rb index ca31a846..e9111cda 100644 --- a/Scripts/Builders/CMarkBuilder.rb +++ b/Scripts/Builders/CMarkBuilder.rb @@ -19,7 +19,7 @@ def configure end def checkout - checkoutIfNeeded(@sources, "https://github.com/commonmark/cmark.git") + checkoutIfNeeded(@sources, "https://github.com/apple/swift-cmark.git") end def build diff --git a/Scripts/Builders/ClangBuilder.rb b/Scripts/Builders/ClangBuilder.rb index 96a8597b..419fcb9b 100644 --- a/Scripts/Builders/ClangBuilder.rb +++ b/Scripts/Builders/ClangBuilder.rb @@ -7,7 +7,7 @@ def initialize(arch = Arch.default) end def checkout - checkoutIfNeeded(@sources, "https://git.llvm.org/git/clang.git") + checkoutIfNeeded(@sources, "https://github.com/apple/swift-clang.git") end end diff --git a/Scripts/Builders/CompilerRTBuilder.rb b/Scripts/Builders/CompilerRTBuilder.rb index 2494ccb6..8d04f0cf 100644 --- a/Scripts/Builders/CompilerRTBuilder.rb +++ b/Scripts/Builders/CompilerRTBuilder.rb @@ -7,7 +7,7 @@ def initialize(arch = Arch.default) end def checkout - checkoutIfNeeded(@sources, "https://git.llvm.org/git/compiler-rt.git") + checkoutIfNeeded(@sources, "https://github.com/apple/swift-compiler-rt.git") end end diff --git a/Scripts/Builders/LLVMBuilder.rb b/Scripts/Builders/LLVMBuilder.rb index 5b4b6feb..a971b65f 100644 --- a/Scripts/Builders/LLVMBuilder.rb +++ b/Scripts/Builders/LLVMBuilder.rb @@ -44,7 +44,7 @@ def make end def checkout - checkoutIfNeeded(@sources, "https://git.llvm.org/git/llvm.git") + checkoutIfNeeded(@sources, "https://github.com/apple/swift-llvm.git") end def prepare() diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index c6aa554f..d2e176b6 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -91,25 +91,37 @@ def compileNew end def configure + prepare # See: SWIFT_GIT_ROOT/docs/WindowsBuild.md cmd = [] cmd << "cd #{@builds} &&" cmd << "cmake -G Ninja" - # -DCMAKE_C_COMPILER="%llvm_bin_dir%/clang-cl.exe"^ - # -DCMAKE_CXX_COMPILER="%llvm_bin_dir%/clang-cl.exe"^ + cmd << "-DCMAKE_C_COMPILER=\"#{@llvm.bin}/clang\"" + cmd << "-DCMAKE_CXX_COMPILER=\"#{@llvm.bin}/clang++\"" # cmd << "-DCMAKE_CXX_FLAGS="-Wno-c++98-compat -Wno-c++98-compat-pedantic"^ # cmd << "-DCMAKE_EXE_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^ # cmd << "-DCMAKE_SHARED_LINKER_FLAGS="/INCREMENTAL:NO"^ cmd << "-DCMAKE_INSTALL_PREFIX=\"#{@installs}\"" cmd << "-DCMAKE_BUILD_TYPE=Release" + cmd << "-DSWIFT_INCLUDE_TESTS=NO" cmd << "-DSWIFT_INCLUDE_DOCS=NO" + cmd << "-DSWIFT_BUILD_SOURCEKIT=NO" + cmd << "-DSWIFT_BUILD_SYNTAXPARSERLIB=NO" cmd << "-DSWIFT_PATH_TO_LLVM_SOURCE=\"#{@llvm.sources}\"" cmd << "-DSWIFT_PATH_TO_CLANG_SOURCE=\"#{@clang.sources}\"" cmd << "-DSWIFT_PATH_TO_CMARK_SOURCE=\"#{@cmark.sources}\"" cmd << "-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=\"#{@dispatch.sources}\"" - cmd << "-DSWIFT_PATH_TO_LLVM_BUILD=\"#{@llvm.installs}\"" - cmd << "-DSWIFT_PATH_TO_CLANG_BUILD=\"#{@clang.installs}\"" - cmd << "-DSWIFT_PATH_TO_CMARK_BUILD=\"#{@cmark.installs}\"" + cmd << "-DSWIFT_PATH_TO_LLVM_BUILD=\"#{@llvm.builds}\"" + cmd << "-DSWIFT_PATH_TO_CLANG_BUILD=\"#{@llvm.builds}\"" + cmd << "-DSWIFT_PATH_TO_CMARK_BUILD=\"#{@cmark.builds}\"" + cmd << "-DLLVM_BUILD_LIBRARY_DIR=\"#{@llvm.lib}\"" + cmd << "-DLLVM_BUILD_MAIN_INCLUDE_DIR=\"#{@llvm.include}\"" + cmd << "-DLLVM_BUILD_BINARY_DIR=\"#{@llvm.bin}\"" + cmd << "-DLLVM_BUILD_MAIN_SRC_DIR=\"#{@llvm.sources}\"" + # Both lines not needed after setting C/CXX compillers + # cmd << "-DCMAKE_PREFIX_PATH=#{@llvm.lib}/cmake/clang" + # cmd << "-DClang_DIR=#{@llvm.lib}/cmake/clang" + # # -DSWIFT_WINDOWS_x86_64_ICU_UC_INCLUDE="%swift_source_dir%/icu/include"^ # -DSWIFT_WINDOWS_x86_64_ICU_UC="%swift_source_dir%/icu/lib64/icuuc.lib"^ # -DSWIFT_WINDOWS_x86_64_ICU_I18N_INCLUDE="%swift_source_dir%/icu/include"^ @@ -120,7 +132,8 @@ def configure end def build - puts "Implement Me" + execute "cd #{@builds} && ninja" + logBuildCompleted() end def install @@ -129,6 +142,8 @@ def install def prepare execute "mkdir -p #{@builds}" + # Fix for missed file: `CMake Error at cmake/modules/SwiftSharedCMakeConfig.cmake:196 (include):` + execute "touch \"#{@cmark.builds}/src/CMarkExports.cmake\"" # targetFile = "/usr/bin/armv7-none-linux-androideabi-ld.gold" # if File.exist?(targetFile) # return @@ -153,8 +168,8 @@ def checkout end def clean - execute "rm -rf #{@build}" - execute "rm -rf #{@install}" + execute "rm -rf #{@builds}" + execute "rm -rf #{@installs}" end end diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index cd8b5fb0..9120a6df 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -34,6 +34,10 @@ def usr return @installs + "/usr" end + def logBuildCompleted + message "\"#{@component}\" build is completed." + end + def checkoutIfNeeded(localPath, repoURL) if File.exist?(localPath) message "Repository \"#{repoURL}\" seems already checked out to \"#{localPath}\"." diff --git a/Scripts/Common/Lib.rb b/Scripts/Common/Lib.rb index 1fa00a1c..755a8e0d 100644 --- a/Scripts/Common/Lib.rb +++ b/Scripts/Common/Lib.rb @@ -13,19 +13,19 @@ def self.ndk end def self.llvm - return "llvm" + return "swift-llvm" end def self.cmark - return "cmark" + return "swift-cmark" end def self.clang - return "clang" + return "swift-clang" end def self.crt - return "compiler-rt" + return "swift-compiler-rt" end def self.curl From 145db0e084816ceca47e9e5a4163aabce790df61 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 23:26:30 +0100 Subject: [PATCH 40/66] Scripts update. --- Scripts/Builders/LLVMBuilder.rb | 30 +++++++++++++++--------------- Scripts/Common/Builder.rb | 8 ++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Scripts/Builders/LLVMBuilder.rb b/Scripts/Builders/LLVMBuilder.rb index a971b65f..899caeb1 100644 --- a/Scripts/Builders/LLVMBuilder.rb +++ b/Scripts/Builders/LLVMBuilder.rb @@ -4,8 +4,6 @@ class LLVMBuilder < Builder def initialize(arch = Arch.default) super(Lib.llvm, arch) - @clang = ClangBuilder.new() - @crt = CompilerRTBuilder.new() end def configure @@ -13,9 +11,9 @@ def configure # - LLVM Getting Started: https://llvm.org/docs/GettingStarted.html#requirements # - CLANG Getting Started: http://clang.llvm.org/get_started.html cmd = [] - cmd << "cd #{@build} &&" + cmd << "cd #{@builds} &&" cmd << "cmake -G Ninja" - cmd << "-DCMAKE_INSTALL_PREFIX=#{@install}" + cmd << "-DCMAKE_INSTALL_PREFIX=#{@installs}" cmd << "-DCMAKE_BUILD_TYPE=Release" # See: https://stackoverflow.com/questions/40122657/build-llvm-clang4-0-for-android-armeabi # Line below still cause build failure. @@ -23,17 +21,17 @@ def configure # cmd << "-DLLVM_DEFAULT_TARGET_TRIPLE=\"arm-linux-androideabi\"" cmd << @sources execute cmd.join(" ") - message "LLVM Configure is completed." + logConfigureCompleted() end - def compile - execute "cd #{@build} && ninja" - message "LLVM Build is completed." + def build + execute "cd #{@builds} && ninja" + logBuildCompleted() end def install - execute "cd #{@build} && ninja install" - message "LLVM Install is completed." + execute "cd #{@builds} && ninja install" + logInstallCompleted() end def make @@ -48,17 +46,19 @@ def checkout end def prepare() - execute "mkdir -p #{@build}" + execute "mkdir -p #{@builds}" # Making needed SymLinks. See: https://llvm.org/docs/GettingStarted.html#git-mirror message "Making symbolic links..." - execute "ln -svf \"#{@clang.sources}\" \"#{@sources}/tools\"" - execute "ln -svf \"#{@crt.sources}\" \"#{@sources}/projects\"" + @clang = ClangBuilder.new() + @crt = CompilerRTBuilder.new() + execute "ln -svf \"#{@clang.sources}\" \"#{@sources}/tools/clang\"" + execute "ln -svf \"#{@crt.sources}\" \"#{@sources}/projects/compiler-rt\"" message "LLVM Prepare is Done!" end def clean - execute "rm -rf #{@build}" - execute "rm -rf #{@install}" + execute "rm -rf #{@builds}" + execute "rm -rf #{@installs}" end end diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index 9120a6df..7dc81e4c 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -38,6 +38,14 @@ def logBuildCompleted message "\"#{@component}\" build is completed." end + def logConfigureCompleted + message "\"#{@component}\" configuring is completed." + end + + def logInstallCompleted + message "\"#{@component}\" install is completed." + end + def checkoutIfNeeded(localPath, repoURL) if File.exist?(localPath) message "Repository \"#{repoURL}\" seems already checked out to \"#{localPath}\"." From 7b376e478b3991482c70f20818ae547db81447a6 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Tue, 18 Dec 2018 23:32:45 +0100 Subject: [PATCH 41/66] Fixes compile issue. --- Scripts/Builders/LLVMBuilder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Builders/LLVMBuilder.rb b/Scripts/Builders/LLVMBuilder.rb index 899caeb1..7d5dc7f6 100644 --- a/Scripts/Builders/LLVMBuilder.rb +++ b/Scripts/Builders/LLVMBuilder.rb @@ -37,7 +37,7 @@ def install def make prepare configure - compile + build install end From 372f40f25ed662190fb4c7fe240d7c7d2f22b244 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Wed, 19 Dec 2018 00:53:46 +0100 Subject: [PATCH 42/66] update. --- Scripts/Builders/AndroidBuilder.rb | 4 ++-- Scripts/Builders/CMarkBuilder.rb | 6 +++--- Scripts/Builders/SwiftBuilder.rb | 30 +++++++++++++++++------------- Scripts/Common/Lib.rb | 2 +- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Scripts/Builders/AndroidBuilder.rb b/Scripts/Builders/AndroidBuilder.rb index dca1c4e6..88e79b97 100755 --- a/Scripts/Builders/AndroidBuilder.rb +++ b/Scripts/Builders/AndroidBuilder.rb @@ -19,7 +19,7 @@ def setup cmd = [] cmd << "#{@sources}/build/tools/make-standalone-toolchain.sh" cmd << "--platform=android-#{@api}" - cmd << "--install-dir=#{@install}" + cmd << "--install-dir=#{@installs}" if @arch == Arch.armv7a cmd << "--toolchain=arm-linux-androideabi-4.9" elsif @arch == Arch.x86 @@ -31,7 +31,7 @@ def setup end def clean() - execute "rm -rf #{@install}/" + execute "rm -rf #{@installs}/" end end diff --git a/Scripts/Builders/CMarkBuilder.rb b/Scripts/Builders/CMarkBuilder.rb index e9111cda..42ceafd3 100644 --- a/Scripts/Builders/CMarkBuilder.rb +++ b/Scripts/Builders/CMarkBuilder.rb @@ -15,7 +15,7 @@ def configure cmd << "-DCMAKE_BUILD_TYPE=Release" cmd << @sources execute cmd.join(" ") - message "LLVM Configure is completed." + logConfigureCompleted end def checkout @@ -24,12 +24,12 @@ def checkout def build execute "cd #{@builds} && ninja" - message "CMark Build is completed." + logBuildCompleted end def install execute "cd #{@builds} && ninja install" - message "CMark Install is completed." + logInstallCompleted end def make diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index d2e176b6..61e3a7a8 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -107,17 +107,19 @@ def configure cmd << "-DSWIFT_INCLUDE_DOCS=NO" cmd << "-DSWIFT_BUILD_SOURCEKIT=NO" cmd << "-DSWIFT_BUILD_SYNTAXPARSERLIB=NO" - cmd << "-DSWIFT_PATH_TO_LLVM_SOURCE=\"#{@llvm.sources}\"" - cmd << "-DSWIFT_PATH_TO_CLANG_SOURCE=\"#{@clang.sources}\"" - cmd << "-DSWIFT_PATH_TO_CMARK_SOURCE=\"#{@cmark.sources}\"" - cmd << "-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=\"#{@dispatch.sources}\"" - cmd << "-DSWIFT_PATH_TO_LLVM_BUILD=\"#{@llvm.builds}\"" - cmd << "-DSWIFT_PATH_TO_CLANG_BUILD=\"#{@llvm.builds}\"" - cmd << "-DSWIFT_PATH_TO_CMARK_BUILD=\"#{@cmark.builds}\"" - cmd << "-DLLVM_BUILD_LIBRARY_DIR=\"#{@llvm.lib}\"" - cmd << "-DLLVM_BUILD_MAIN_INCLUDE_DIR=\"#{@llvm.include}\"" - cmd << "-DLLVM_BUILD_BINARY_DIR=\"#{@llvm.bin}\"" - cmd << "-DLLVM_BUILD_MAIN_SRC_DIR=\"#{@llvm.sources}\"" + + # cmd << "-DSWIFT_PATH_TO_LLVM_SOURCE=\"#{@llvm.sources}\"" + # cmd << "-DSWIFT_PATH_TO_CLANG_SOURCE=\"#{@clang.sources}\"" + # cmd << "-DSWIFT_PATH_TO_CMARK_SOURCE=\"#{@cmark.sources}\"" + # cmd << "-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=\"#{@dispatch.sources}\"" + # cmd << "-DSWIFT_PATH_TO_LLVM_BUILD=\"#{@llvm.builds}\"" + # cmd << "-DSWIFT_PATH_TO_CLANG_BUILD=\"#{@llvm.builds}\"" + # cmd << "-DSWIFT_PATH_TO_CMARK_BUILD=\"#{@cmark.builds}\"" + # cmd << "-DLLVM_BUILD_LIBRARY_DIR=\"#{@llvm.lib}\"" + # cmd << "-DLLVM_BUILD_MAIN_INCLUDE_DIR=\"#{@llvm.include}\"" + # cmd << "-DLLVM_BUILD_BINARY_DIR=\"#{@llvm.bin}\"" + # cmd << "-DLLVM_BUILD_MAIN_SRC_DIR=\"#{@llvm.sources}\"" + # Both lines not needed after setting C/CXX compillers # cmd << "-DCMAKE_PREFIX_PATH=#{@llvm.lib}/cmake/clang" # cmd << "-DClang_DIR=#{@llvm.lib}/cmake/clang" @@ -128,7 +130,7 @@ def configure # -DSWIFT_WINDOWS_x86_64_ICU_I18N="%swift_source_dir%/icu/lib64/icuin.lib"^ cmd << @sources execute cmd.join(" ") - message "Swift Configure is completed." + logConfigureCompleted end def build @@ -138,12 +140,14 @@ def build def install puts "Implement Me" + logInstallCompleted end def prepare execute "mkdir -p #{@builds}" # Fix for missed file: `CMake Error at cmake/modules/SwiftSharedCMakeConfig.cmake:196 (include):` - execute "touch \"#{@cmark.builds}/src/CMarkExports.cmake\"" + # execute "touch \"#{@cmark.builds}/src/CMarkExports.cmake\"" + # targetFile = "/usr/bin/armv7-none-linux-androideabi-ld.gold" # if File.exist?(targetFile) # return diff --git a/Scripts/Common/Lib.rb b/Scripts/Common/Lib.rb index 755a8e0d..dce601db 100644 --- a/Scripts/Common/Lib.rb +++ b/Scripts/Common/Lib.rb @@ -1,7 +1,7 @@ class Lib def self.swift - return "Swift" + return "swift" end def self.icu From bef907ec4f35d8cc46c9dcb944a0386ae5363f52 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Wed, 19 Dec 2018 15:18:21 +0100 Subject: [PATCH 43/66] Update. --- Scripts/Builders/SwiftBuilder.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 61e3a7a8..00bbfb24 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -108,13 +108,18 @@ def configure cmd << "-DSWIFT_BUILD_SOURCEKIT=NO" cmd << "-DSWIFT_BUILD_SYNTAXPARSERLIB=NO" - # cmd << "-DSWIFT_PATH_TO_LLVM_SOURCE=\"#{@llvm.sources}\"" + # Making Ninja verbose. See: https://github.com/ninja-build/ninja/issues/900#issuecomment-132346047 + cmd << "-DCMAKE_VERBOSE_MAKEFILE=ON" + + cmd << "-DSWIFT_PATH_TO_LLVM_SOURCE=\"#{@llvm.sources}\"" + cmd << "-DSWIFT_PATH_TO_LLVM_BUILD=\"#{@llvm.builds}\"" + + cmd << "-DSWIFT_PATH_TO_CMARK_SOURCE=\"#{@cmark.sources}\"" + cmd << "-DSWIFT_PATH_TO_CMARK_BUILD=\"#{@cmark.builds}\"" + # cmd << "-DSWIFT_PATH_TO_CLANG_SOURCE=\"#{@clang.sources}\"" - # cmd << "-DSWIFT_PATH_TO_CMARK_SOURCE=\"#{@cmark.sources}\"" # cmd << "-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=\"#{@dispatch.sources}\"" - # cmd << "-DSWIFT_PATH_TO_LLVM_BUILD=\"#{@llvm.builds}\"" # cmd << "-DSWIFT_PATH_TO_CLANG_BUILD=\"#{@llvm.builds}\"" - # cmd << "-DSWIFT_PATH_TO_CMARK_BUILD=\"#{@cmark.builds}\"" # cmd << "-DLLVM_BUILD_LIBRARY_DIR=\"#{@llvm.lib}\"" # cmd << "-DLLVM_BUILD_MAIN_INCLUDE_DIR=\"#{@llvm.include}\"" # cmd << "-DLLVM_BUILD_BINARY_DIR=\"#{@llvm.bin}\"" @@ -134,7 +139,7 @@ def configure end def build - execute "cd #{@builds} && ninja" + execute "cd #{@builds} && cmake --build ." logBuildCompleted() end @@ -163,8 +168,8 @@ def prepare def make prepare configure - # build - # install + build + install end def checkout From 6a0b4867334e47040e876328c1d1b10fdb2f17e6 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sat, 22 Dec 2018 20:55:42 +0100 Subject: [PATCH 44/66] Added Lib Dispatch usage. --- Projects/Hello/hello.swift | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/Projects/Hello/hello.swift b/Projects/Hello/hello.swift index 24e44609..7319e29b 100755 --- a/Projects/Hello/hello.swift +++ b/Projects/Hello/hello.swift @@ -2,3 +2,63 @@ // 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 + +let op = BlockOperation { + print("Operation") +} +let opQueue = OperationQueue() +opQueue.addOperations([op], waitUntilFinished: true) + +let sema = DispatchSemaphore(value: 0) + +let queue = DispatchQueue(label: "queueName") +queue.async { + print("XYZ") + sema.signal() +} + +if sema.wait(timeout: .now() + 10) == .timedOut { + print("~~~~~~") +} + +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") +} + +let json = ["name": "Sveta"] +do { + let data = try JSONSerialization.data(withJSONObject: json, options: []) + struct Person: Decodable { + let name: String + } + + let person = try JSONDecoder().decode(Person.self, from: data) + print(person.name) + +} catch { + print(error) +} From d9bb74b640a1df0bfe23d3a0c5e4ec6fdc7ca038 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sat, 22 Dec 2018 21:45:45 +0100 Subject: [PATCH 45/66] Simplification. --- Rakefile | 2 -- Scripts/Builders/ICUBuilder.rb | 60 ++++++++++++++-------------------- Scripts/Common/Builder.rb | 2 +- 3 files changed, 26 insertions(+), 38 deletions(-) diff --git a/Rakefile b/Rakefile index f2342c5b..72839645 100755 --- a/Rakefile +++ b/Rakefile @@ -37,8 +37,6 @@ Building Swift Toolchain. Steps: 2. Configure and Build Sources: rake armv7a:setup:ndk - rake armv7a:build:llvm - rake armv7a:build:cmark rake armv7a:build:icu rake armv7a:build:swift diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index 91bba5c9..3a37c35f 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -22,27 +22,29 @@ def initialize(arch = Arch.default) end def configureHost - cmd = ["cd #{@build} &&"] + cmd = ["cd #{@builds} &&"] + cmd << 'CC="/usr/bin/clang"' + cmd << 'CXX="/usr/bin/clang++"' cmd << 'CFLAGS="-Os"' cmd << 'CXXFLAGS="--std=c++11"' - cmd << "#{@sources}/source/runConfigureICU Linux --prefix=#{@install}" + cmd << "#{@sources}/source/runConfigureICU Linux --prefix=#{@installs}" cmd << "--enable-static --enable-shared=no --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no" cmd << "--enable-layoutex=no --enable-tools=no --enable-tests=no --enable-samples=no --enable-dyload=no" execute cmd.join(" ") end def configure - if !@host.nil? && !File.exist?(@host.build) + if !@host.nil? && !File.exist?(@host.builds) message "Building Corss-Build Host." @host.prepare @host.configureHost - @host.compile + @host.build message "Corss-Build Host Build completed." end - cmd = ["cd #{@build} &&"] + cmd = ["cd #{@builds} &&"] + cmd << "PATH=#{@ndk.installs}/bin:$PATH" if @arch == Arch.armv7a - cmd << "PATH=#{@ndk.install}/bin:$PATH" cmd << "CFLAGS='-Os -march=armv7-a -mfloat-abi=softfp -mfpu=neon'" cmd << "CXXFLAGS='--std=c++11 -march=armv7-a -mfloat-abi=softfp -mfpu=neon'" cmd << "LDFLAGS='-march=armv7-a -Wl,--fix-cortex-a8'" @@ -50,44 +52,32 @@ def configure cmd << "CXX=arm-linux-androideabi-clang++" cmd << "AR=arm-linux-androideabi-ar" cmd << "RINLIB=arm-linux-androideabi-ranlib" - cmd << "#{@sources}/source/configure --prefix=#{@install}" + cmd << "#{@sources}/source/configure --prefix=#{@installs}" cmd << "--host=arm-linux-androideabi" - cmd << "--with-library-suffix=swift" - cmd << "--enable-static --enable-shared --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no --enable-layoutex=no" - cmd << "--enable-tools=no --enable-tests=no --enable-samples=no --enable-dyload=no" - cmd << "--with-cross-build=#{@host.build}" - cmd << "--with-data-packaging=archive" elsif @arch == Arch.x86 - cmd << "PATH=#{@ndk.install}/bin:$PATH" cmd << "CFLAGS='-Os -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32'" cmd << "CXXFLAGS='--std=c++11 -march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32'" cmd << "CC=i686-linux-android-clang" cmd << "CXX=i686-linux-android-clang++" cmd << "AR=i686-linux-android-ar" cmd << "RINLIB=i686-linux-android-ranlib" - cmd << "#{@sources}/source/configure --prefix=#{@install}" + cmd << "#{@sources}/source/configure --prefix=#{@installs}" cmd << "--host=i686-linux-android" - cmd << "--with-library-suffix=swift" - cmd << "--enable-static --enable-shared --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no --enable-layoutex=no" - cmd << "--enable-tools=no --enable-tests=no --enable-samples=no --enable-dyload=no" - cmd << "--with-cross-build=#{@host.build}" - cmd << "--with-data-packaging=archive" elsif @arch == Arch.aarch64 - cmd << "PATH=#{@ndk.install}/bin:$PATH" cmd << "CFLAGS='-Os'" cmd << "CXXFLAGS='--std=c++11'" cmd << "CC=aarch64-linux-android-clang" cmd << "CXX=aarch64-linux-android-clang++" cmd << "AR=aarch64-linux-android-ar" cmd << "RINLIB=aarch64-linux-android-ranlib" - cmd << "#{@sources}/source/configure --prefix=#{@install}" + cmd << "#{@sources}/source/configure --prefix=#{@installs}" cmd << "--host=aarch64-linux-android" - cmd << "--with-library-suffix=swift" - cmd << "--enable-static --enable-shared --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no --enable-layoutex=no" - cmd << "--enable-tools=no --enable-tests=no --enable-samples=no --enable-dyload=no" - cmd << "--with-cross-build=#{@host.build}" - cmd << "--with-data-packaging=archive" end + cmd << "--with-library-suffix=swift" + cmd << "--enable-static --enable-shared --enable-extras=no --enable-strict=no --enable-icuio=no --enable-layout=no --enable-layoutex=no" + cmd << "--enable-tools=no --enable-tests=no --enable-samples=no --enable-dyload=no" + cmd << "--with-cross-build=#{@host.builds}" + cmd << "--with-data-packaging=archive" execute cmd.join(" ") end @@ -96,7 +86,7 @@ def checkout end def prepare() - execute "mkdir -p #{@build}" + execute "mkdir -p #{@builds}" applyPatchIfNeeded() end @@ -112,23 +102,23 @@ def applyPatchIfNeeded() end end - def compile - execute "cd #{@build} && PATH=#{@ndk.install}/bin:$PATH make -j4" - execute "cd #{@build} && PATH=#{@ndk.install}/bin:$PATH make install" + def build + execute "cd #{@builds} && PATH=#{@ndk.installs}/bin:$PATH make -j4" + execute "cd #{@builds} && PATH=#{@ndk.installs}/bin:$PATH make install" end - def make() + def make prepare configure - compile + build end - def clean() + def clean if !@host.nil? @host.clean end - execute "rm -rf #{@build}" - execute "rm -rf #{@install}" + execute "rm -rf #{@builds}" + execute "rm -rf #{@installs}" end end diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index 7dc81e4c..b697058e 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -52,7 +52,7 @@ def checkoutIfNeeded(localPath, repoURL) else dir = File.dirname(localPath) execute "mkdir -p \"#{dir}\"" - execute "cd \"#{dir}\" && git clone --depth=10 #{repoURL}" + execute "cd \"#{dir}\" && git clone --depth=10 #{repoURL} \"#{localPath}\"" message "#{repoURL} checkout to \"#{localPath}\" is completed." end end From 8569c26922429a82ffed8ed0b8d3840c7dce95e6 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sat, 22 Dec 2018 21:47:54 +0100 Subject: [PATCH 46/66] Added logging. --- Scripts/Builders/ICUBuilder.rb | 10 +++++++++- Scripts/Builders/SwiftBuilder.rb | 32 +++++++++++++++++++++++++++----- Scripts/Common/Lib.rb | 8 ++++---- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index 3a37c35f..0d2916e1 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -34,11 +34,12 @@ def configureHost end def configure - if !@host.nil? && !File.exist?(@host.builds) + if !@host.nil? && !File.exist?(@host.bin) message "Building Corss-Build Host." @host.prepare @host.configureHost @host.build + @host.install message "Corss-Build Host Build completed." end @@ -79,6 +80,7 @@ def configure cmd << "--with-cross-build=#{@host.builds}" cmd << "--with-data-packaging=archive" execute cmd.join(" ") + logConfigureCompleted end def checkout @@ -104,13 +106,19 @@ def applyPatchIfNeeded() def build execute "cd #{@builds} && PATH=#{@ndk.installs}/bin:$PATH make -j4" + logBuildCompleted + end + + def install execute "cd #{@builds} && PATH=#{@ndk.installs}/bin:$PATH make install" + logInstallCompleted end def make prepare configure build + install end def clean diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 00bbfb24..232b31b2 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -96,8 +96,23 @@ def configure cmd = [] cmd << "cd #{@builds} &&" cmd << "cmake -G Ninja" - cmd << "-DCMAKE_C_COMPILER=\"#{@llvm.bin}/clang\"" - cmd << "-DCMAKE_CXX_COMPILER=\"#{@llvm.bin}/clang++\"" + + # cmd << "-DCMAKE_C_COMPILER=\"#{@llvm.bin}/clang\"" + # cmd << "-DCMAKE_CXX_COMPILER=\"#{@llvm.bin}/clang++\"" + + cmd << "-DCMAKE_C_COMPILER=/usr/bin/clang" + cmd << "-DCMAKE_CXX_COMPILER=/usr/bin/clang++" + + # See: + # - https://stackoverflow.com/questions/10712972/what-is-the-use-of-fno-stack-protector + # - https://reviews.llvm.org/D34264 + # - https://bugzilla.mozilla.org/show_bug.cgi?id=731316 + cFlags = "-Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector" + cmd << "-DCMAKE_C_FLAGS=\"#{cFlags}\"" + cmd << "-DCMAKE_CXX_FLAGS=\"#{cFlags}\"" + + # cmd << "-DCLANG_VERSION_MAJOR=\"7\" -DCLANG_VERSION_MINOR=\"0\" -DCLANG_VERSION_PATCH=\"0\"" + # cmd << "-DCMAKE_CXX_FLAGS="-Wno-c++98-compat -Wno-c++98-compat-pedantic"^ # cmd << "-DCMAKE_EXE_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^ # cmd << "-DCMAKE_SHARED_LINKER_FLAGS="/INCREMENTAL:NO"^ @@ -109,16 +124,23 @@ def configure cmd << "-DSWIFT_BUILD_SYNTAXPARSERLIB=NO" # Making Ninja verbose. See: https://github.com/ninja-build/ninja/issues/900#issuecomment-132346047 - cmd << "-DCMAKE_VERBOSE_MAKEFILE=ON" + # cmd << "-DCMAKE_VERBOSE_MAKEFILE=ON" cmd << "-DSWIFT_PATH_TO_LLVM_SOURCE=\"#{@llvm.sources}\"" cmd << "-DSWIFT_PATH_TO_LLVM_BUILD=\"#{@llvm.builds}\"" cmd << "-DSWIFT_PATH_TO_CMARK_SOURCE=\"#{@cmark.sources}\"" cmd << "-DSWIFT_PATH_TO_CMARK_BUILD=\"#{@cmark.builds}\"" + cmd << "-DSWIFT_CMARK_LIBRARY_DIR=\"#{@cmark.lib}\"" + + cmd << "-DSWIFT_SDKS=LINUX" + + # Seems these vars is unused. + cmd << "-DSWIFT_EXEC=#{@builds}/bin/swiftc" + cmd << "-DLIBDISPATCH_CMAKE_BUILD_TYPE=Release" # cmd << "-DSWIFT_PATH_TO_CLANG_SOURCE=\"#{@clang.sources}\"" - # cmd << "-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=\"#{@dispatch.sources}\"" + cmd << "-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=\"#{@dispatch.sources}\"" # cmd << "-DSWIFT_PATH_TO_CLANG_BUILD=\"#{@llvm.builds}\"" # cmd << "-DLLVM_BUILD_LIBRARY_DIR=\"#{@llvm.lib}\"" # cmd << "-DLLVM_BUILD_MAIN_INCLUDE_DIR=\"#{@llvm.include}\"" @@ -144,7 +166,7 @@ def build end def install - puts "Implement Me" + execute "cd #{@builds} && ninja install" logInstallCompleted end diff --git a/Scripts/Common/Lib.rb b/Scripts/Common/Lib.rb index dce601db..f268299c 100644 --- a/Scripts/Common/Lib.rb +++ b/Scripts/Common/Lib.rb @@ -13,19 +13,19 @@ def self.ndk end def self.llvm - return "swift-llvm" + return "llvm" end def self.cmark - return "swift-cmark" + return "cmark" end def self.clang - return "swift-clang" + return "clang" end def self.crt - return "swift-compiler-rt" + return "compiler-rt" end def self.curl From e66b24671f746c7891d618f70ef63bc98fbb2547 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sat, 22 Dec 2018 22:30:09 +0100 Subject: [PATCH 47/66] update. --- Scripts/Builders/SwiftBuilder.rb | 47 ++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 232b31b2..262b3411 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -38,10 +38,10 @@ def initialize(arch = Arch.default) super(Lib.swift, arch) @icu = ICUBuilder.new(arch) @ndk = AndroidBuilder.new(arch) - @cmark = CMarkBuilder.new(arch) - @llvm = LLVMBuilder.new(arch) - @clang = ClangBuilder.new(arch) - @dispatch = DispatchBuilder.new(arch) + # @cmark = CMarkBuilder.new(arch) + # @llvm = LLVMBuilder.new(arch) + # @clang = ClangBuilder.new(arch) + # @dispatch = DispatchBuilder.new(arch) end def compileOLD @@ -66,7 +66,7 @@ def compileOLD execute cmd.join(" ") end - def compileNew + def compileOld2 cmd = ["cd #{@sources} &&"] cmd << "./swift/utils/build-script --release --android" cmd << "--android-ndk #{@ndk.sources}" @@ -90,7 +90,7 @@ def compileNew execute cmd.join(" ") end - def configure + def configureOld prepare # See: SWIFT_GIT_ROOT/docs/WindowsBuild.md cmd = [] @@ -161,15 +161,36 @@ def configure end def build - execute "cd #{@builds} && cmake --build ." + cmd = ["cd #{@sources} &&"] + cmd << "./utils/build-script --release --skip-reconfigure" + cmd << "--assertions --no-swift-stdlib-assertions --swift-enable-ast-verifier=0" + # cmd << "--android" + # cmd << "--android-ndk #{@ndk.sources}" + # cmd << "--android-api-level #{@ndk.api}" + # cmd << "--android-icu-uc #{@icu.lib}/libicuucswift.so" + # cmd << "--android-icu-uc-include #{@icu.sources}/source/common" + # 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 << "--install-swift" + cmd << "--libdispatch --install-libdispatch" + cmd << "--foundation --install-foundation" + cmd << "--build-swift-static-stdlib --build-swift-static-sdk-overlay" + 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" + # 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 << "'--llvm-install-components=llvm-cov;llvm-profdata;IndexStore'" + cmd << "--install-prefix=/usr" + cmd << "--install-destdir=#{@installs}" + cmd << "--build-dir #{@builds}" + execute cmd.join(" ") logBuildCompleted() end - def install - execute "cd #{@builds} && ninja install" - logInstallCompleted - end - def prepare execute "mkdir -p #{@builds}" # Fix for missed file: `CMake Error at cmake/modules/SwiftSharedCMakeConfig.cmake:196 (include):` @@ -189,9 +210,7 @@ def prepare def make prepare - configure build - install end def checkout From 574e105a55a514caa13a2d4dbafbb3d5c40a8437 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 00:46:06 +0100 Subject: [PATCH 48/66] Update. --- Scripts/Builders/SwiftBuilder.rb | 75 ++++++++++---------------------- 1 file changed, 23 insertions(+), 52 deletions(-) diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 262b3411..459eddb9 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -38,10 +38,6 @@ def initialize(arch = Arch.default) super(Lib.swift, arch) @icu = ICUBuilder.new(arch) @ndk = AndroidBuilder.new(arch) - # @cmark = CMarkBuilder.new(arch) - # @llvm = LLVMBuilder.new(arch) - # @clang = ClangBuilder.new(arch) - # @dispatch = DispatchBuilder.new(arch) end def compileOLD @@ -49,49 +45,9 @@ def compileOLD # 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" - - cmd << "./swift/utils/build-script --release --android" - cmd << "--android-ndk #{@ndk.sources}" - cmd << "--android-api-level #{@ndk.api}" - cmd << "--android-icu-uc #{@icu.lib}/libicuucswift.so" - cmd << "--android-icu-uc-include #{@icu.sources}/source/common" - 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 << "--libdispatch --install-libdispatch" - cmd << "--foundation --install-foundation" - cmd << "--install-prefix=/usr" - cmd << "--install-destdir=#{@install}" - cmd << "--build-dir #{@build}" - execute cmd.join(" ") - end - - def compileOld2 - cmd = ["cd #{@sources} &&"] - cmd << "./swift/utils/build-script --release --android" - cmd << "--android-ndk #{@ndk.sources}" - cmd << "--android-api-level #{@ndk.api}" - cmd << "--android-icu-uc #{@icu.lib}/libicuucswift.so" - cmd << "--android-icu-uc-include #{@icu.sources}/source/common" - 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 << "--libdispatch --install-libdispatch" - cmd << "--foundation --install-foundation" - cmd << "--llbuild --install-llbuild" - cmd << "--lldb --install-lldb" - cmd << "--swiftpm --install-swiftpm" - cmd << "--xctest --install-xctest" - cmd << "--install-swift" - cmd << "'--swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;dev'" - cmd << "--install-prefix=/usr" - cmd << "--install-destdir=#{@install}" - cmd << "--build-dir #{@build}" - execute cmd.join(" ") end def configureOld - prepare # See: SWIFT_GIT_ROOT/docs/WindowsBuild.md cmd = [] cmd << "cd #{@builds} &&" @@ -163,21 +119,36 @@ def configureOld def build cmd = ["cd #{@sources} &&"] cmd << "./utils/build-script --release --skip-reconfigure" + # cmd << "--dry-run" + # cmd << "--verbose-build" cmd << "--assertions --no-swift-stdlib-assertions --swift-enable-ast-verifier=0" - # cmd << "--android" - # cmd << "--android-ndk #{@ndk.sources}" - # cmd << "--android-api-level #{@ndk.api}" - # cmd << "--android-icu-uc #{@icu.lib}/libicuucswift.so" - # cmd << "--android-icu-uc-include #{@icu.sources}/source/common" - # 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 << "--android" + cmd << "--android-ndk #{@ndk.sources}" + cmd << "--android-api-level #{@ndk.api}" + cmd << "--android-icu-uc #{@icu.lib}/libicuucswift.so" + cmd << "--android-icu-uc-include #{@icu.sources}/source/common" + 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 << "--install-swift" 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" From a3681dff791ebd3bf7b95f00e3528cd127e626a9 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 01:27:50 +0100 Subject: [PATCH 49/66] Update. --- Scripts/Builders/ICUBuilder.rb | 4 ++-- Scripts/Builders/SwiftBuilder.rb | 18 ++++++++++-------- Scripts/Common/Arch.rb | 4 ++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index 0d2916e1..d57b84b4 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -16,8 +16,8 @@ def initialize(arch = Arch.default) @gitRepoRoot = "#{Config.sources}/#{Lib.icu}" @sources = "#{@gitRepoRoot}/icu4c" @ndk = AndroidBuilder.new(arch) - if arch != "linux" - @host = ICUBuilder.new("linux") + if arch != Arch.host + @host = ICUBuilder.new(Arch.host) end end diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 459eddb9..53283f36 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -123,14 +123,16 @@ def build # cmd << "--verbose-build" cmd << "--assertions --no-swift-stdlib-assertions --swift-enable-ast-verifier=0" - cmd << "--android" - cmd << "--android-ndk #{@ndk.sources}" - cmd << "--android-api-level #{@ndk.api}" - cmd << "--android-icu-uc #{@icu.lib}/libicuucswift.so" - cmd << "--android-icu-uc-include #{@icu.sources}/source/common" - 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" + if @arch != Arch.host + cmd << "--android" + cmd << "--android-ndk #{@ndk.sources}" + cmd << "--android-api-level #{@ndk.api}" + cmd << "--android-icu-uc #{@icu.lib}/libicuucswift.so" + cmd << "--android-icu-uc-include #{@icu.sources}/source/common" + 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" + end cmd << "--install-swift" cmd << "--libdispatch --install-libdispatch" diff --git a/Scripts/Common/Arch.rb b/Scripts/Common/Arch.rb index ae3d86f1..4de753bc 100644 --- a/Scripts/Common/Arch.rb +++ b/Scripts/Common/Arch.rb @@ -4,6 +4,10 @@ def self.default return armv7a end + def self.host + return "host" + end + def self.x86 return "x86" end From 66b4d3ffd10157af3551cffb5691427f997c550b Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 01:30:30 +0100 Subject: [PATCH 50/66] Update. --- Scripts/Common/Builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index b697058e..c1f26870 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -14,8 +14,8 @@ def initialize(component, arch) @arch = arch @sources = "#{Config.sources}/#{component}" @patches = "#{Config.patches}/#{component}" - @builds = "#{Config.build}/#{component}/#{arch}" - @installs = "#{Config.install}/#{component}/#{arch}" + @builds = "#{Config.build}/#{arch}/#{component}" + @installs = "#{Config.install}/#{arch}/#{component}" end def lib From 58d212e4057716a57fcc55e69255dbbe99fdc3a0 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 09:51:16 +0100 Subject: [PATCH 51/66] Simplification. --- Projects/Hello/hello.swift | 3 + Rakefile | 6 +- Scripts/Builders/CurlBuilder.rb | 1 - Scripts/Builders/DispatchBuilder.rb | 1 - Scripts/Builders/FoundationBuilder.rb | 1 - Scripts/Builders/HelloProjectBuilder.rb | 34 ++++---- Scripts/Builders/OpenSSLBuilder.rb | 1 - Scripts/Builders/SwiftBuilder.rb | 29 +++---- Scripts/Common/Config.rb | 104 +----------------------- Scripts/Common/Location.rb | 5 ++ 10 files changed, 43 insertions(+), 142 deletions(-) diff --git a/Projects/Hello/hello.swift b/Projects/Hello/hello.swift index 7319e29b..8ff93f57 100755 --- a/Projects/Hello/hello.swift +++ b/Projects/Hello/hello.swift @@ -3,9 +3,11 @@ // as Workflow will support Dispatch and Foundation frameworks compilation. print("Hello, This Is Swift!") +/* import Foundation import Dispatch + let op = BlockOperation { print("Operation") } @@ -62,3 +64,4 @@ do { } catch { print(error) } +*/ diff --git a/Rakefile b/Rakefile index 72839645..7dd077e5 100755 --- a/Rakefile +++ b/Rakefile @@ -37,8 +37,8 @@ Building Swift Toolchain. Steps: 2. Configure and Build Sources: rake armv7a:setup:ndk - rake armv7a:build:icu - rake armv7a:build:swift + rake armv7a:make:icu + rake armv7a:make:swift 3. Build `Hello` project. Execute: "rake project:hello:build" @@ -301,7 +301,7 @@ namespace :project do desc "Project Hello: Build" task :build do - HelloProjectBuilder.new().make + HelloProjectBuilder.new().build end desc "Project Hello: Verify" diff --git a/Scripts/Builders/CurlBuilder.rb b/Scripts/Builders/CurlBuilder.rb index ba870f9a..0493fa7a 100644 --- a/Scripts/Builders/CurlBuilder.rb +++ b/Scripts/Builders/CurlBuilder.rb @@ -1,5 +1,4 @@ require_relative "../Common/Builder.rb" -require_relative "../Common/Config.rb" class CurlBuilder < Builder diff --git a/Scripts/Builders/DispatchBuilder.rb b/Scripts/Builders/DispatchBuilder.rb index 6bf9fee6..0db98da6 100644 --- a/Scripts/Builders/DispatchBuilder.rb +++ b/Scripts/Builders/DispatchBuilder.rb @@ -1,5 +1,4 @@ require_relative "../Common/Builder.rb" -require_relative "../Common/Config.rb" # See: # - Dispatch build script: https://github.com/readdle/swift-android-toolchain/blob/master/build/Linux/040_build_corelibs_libdispatch.sh diff --git a/Scripts/Builders/FoundationBuilder.rb b/Scripts/Builders/FoundationBuilder.rb index ae76d33f..25e2872e 100644 --- a/Scripts/Builders/FoundationBuilder.rb +++ b/Scripts/Builders/FoundationBuilder.rb @@ -1,5 +1,4 @@ require_relative "../Common/Builder.rb" -require_relative "../Common/Config.rb" # See: # - Libdispatch issues with CMake: https://forums.swift.org/t/libdispatch-switched-to-cmake/6665/7 diff --git a/Scripts/Builders/HelloProjectBuilder.rb b/Scripts/Builders/HelloProjectBuilder.rb index 6cc9854b..70fe414a 100755 --- a/Scripts/Builders/HelloProjectBuilder.rb +++ b/Scripts/Builders/HelloProjectBuilder.rb @@ -1,38 +1,34 @@ require_relative "../Common/Builder.rb" -require_relative "../Common/Config.rb" # See: # - Build error: No such module "SwiftGlibc" – https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20160919/002955.html class HelloProjectBuilder < Builder - def initialize() - super() - @buildDir = Config.buildRoot + "/hello" - @executablePath = @buildDir + "/hello" - @projectRoot = "#{Config.projectsRoot}/Hello" + def initialize(arch = Arch.default) + super("Hello", arch) + @executable = @builds + "/hello" + @projectRoot = "#{Config.projects}/Hello" end def build - cmd = ["cd #{@buildDir} &&"] - cmd << "PATH=#{Config.swiftBuildRoot}/swift-linux-x86_64/bin:$PATH" + prepare + swift = SwiftBuilder.new() + ndk = AndroidBuilder.new() + cmd = ["cd #{@builds} &&"] + cmd << "PATH=#{swift.installs}/usr/bin:$PATH" cmd << "swiftc" - cmd << "-tools-directory #{Config.ndkSourcesRoot}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin" + cmd << "-tools-directory #{ndk.sources}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin" cmd << "-target armv7-none-linux-androideabi" # Targeting android-armv7. - cmd << "-sdk #{Config.ndkSourcesRoot}/platforms/android-#{Config.androidAPI}/arch-arm" # Use the same NDK path and API version as you used to build the stdlib in the previous step. - cmd << "-L #{Config.ndkSourcesRoot}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a" # Link the Android NDK's libc++ and libgcc. - cmd << "-L #{Config.ndkSourcesRoot}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x" + cmd << "-sdk #{ndk.sources}/platforms/android-#{ndk.api}/arch-arm" # Use the same NDK path and API version as you used to build the stdlib in the previous step. + cmd << "-L #{ndk.sources}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a" # Link the Android NDK's libc++ and libgcc. + cmd << "-L #{ndk.sources}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x" cmd << "#{@projectRoot}/hello.swift" execute cmd.join(" ") - execute "readelf -h #{@executablePath}" + execute "readelf -h #{@executable}" end def prepare() - execute "mkdir -p #{@buildDir}" - end - - def make - prepare - build + execute "mkdir -p #{@builds}" end end diff --git a/Scripts/Builders/OpenSSLBuilder.rb b/Scripts/Builders/OpenSSLBuilder.rb index 7d495ad9..d1e4c272 100644 --- a/Scripts/Builders/OpenSSLBuilder.rb +++ b/Scripts/Builders/OpenSSLBuilder.rb @@ -1,5 +1,4 @@ require_relative "../Common/Builder.rb" -require_relative "../Common/Config.rb" # See: # - Compiling the latest OpenSSL for Android: https://stackoverflow.com/questions/11929773/compiling-the-latest-openssl-for-android diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 53283f36..42b39936 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -118,6 +118,7 @@ def configureOld def build cmd = ["cd #{@sources} &&"] + cmd << "SKIP_BUILD_SWIFT_STATIC_LIBDISPATCH=1 SKIP_BUILD_STATIC_FOUNDATION=1" cmd << "./utils/build-script --release --skip-reconfigure" # cmd << "--dry-run" # cmd << "--verbose-build" @@ -143,11 +144,11 @@ def build # 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" + # 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"' + cmd << '--llvm-targets-to-build="ARM;AArch64;X86"' # TODO: Try it # cmd << "--skip-test-android-host" @@ -155,7 +156,10 @@ def build # 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;sourcekit-inproc'" + cmd << "'--swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;license'" + cmd << "'--llvm-install-components=llvm-cov;llvm-profdata;IndexStore'" cmd << "--install-prefix=/usr" cmd << "--install-destdir=#{@installs}" @@ -169,16 +173,13 @@ def prepare # Fix for missed file: `CMake Error at cmake/modules/SwiftSharedCMakeConfig.cmake:196 (include):` # execute "touch \"#{@cmark.builds}/src/CMarkExports.cmake\"" - # targetFile = "/usr/bin/armv7-none-linux-androideabi-ld.gold" - # if File.exist?(targetFile) - # return - # end - # puts "Making symbolic link to \"#{targetFile}\"..." - # cmd = ["sudo"] - # cmd << "ln -svf #{@ndk.sources}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/ld.gold" - # cmd << targetFile - # execute cmd.join(" ") - # execute "ls -a /usr/bin/*ld.gold" + if @arch != Arch.host + 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 -a /usr/bin/*ld.gold" + # FIXME: Remove simlink once done. + end end def make diff --git a/Scripts/Common/Config.rb b/Scripts/Common/Config.rb index eab1873f..f90cf6d1 100755 --- a/Scripts/Common/Config.rb +++ b/Scripts/Common/Config.rb @@ -2,104 +2,10 @@ class Config - def self.sources(component) - return sourcesRoot + "/" + component - end - - def self.verify - puts "- Project Root Path: \t\"#{root}\"" - puts "- Android NDK Path: \t\"#{ndkSourcesRoot}\"" - puts "- ICU Sources Path: \t\"#{icuSourcesRoot}\"" - puts "- ICU Patches Path: \t\"#{icuPatchesRoot}\"" - puts "- Swift Sources Path: \t\"#{swiftSourcesRoot}\"" - puts "- Build root Path: \t\"#{buildRoot}\"" - puts "- Install root Path: \t\"#{installRoot}\"" - end - - def self.androidAPI - return "21" - end - def self.root return File.realpath(File.dirname(__FILE__) + "/../../") end - # Sources - - def self.ndkSourcesRoot - return "#{sourcesRoot}/android-ndk-r18b" - end - - def self.icuSourcesRoot - return "#{sourcesRoot}/icu" - end - - def self.swiftSourcesRoot - return "#{sourcesRoot}/swift" - end - - def self.curlSourcesRoot - return "#{sourcesRoot}/curl" - end - - def self.opensslSourcesRoot - return "#{sourcesRoot}/openssl" - end - - def self.xmlSourcesRoot - return "#{sourcesRoot}/xml" - end - - def self.sourcesRoot - return "#{root}/Sources" - end - - # Builds - - def self.buildRoot - return "#{root}/Build" - end - - def self.swiftBuildRoot - return "#{buildRoot}/swift" - end - - # Install - - def self.installRoot - return "#{root}/Install" - end - - def self.ndkInstallRoot - return "#{installRoot}/android" - end - - def self.dispatchInstallRoot - return "#{installRoot}/dispatch" - end - - def self.icuInstallRoot - return "#{installRoot}/icu" - end - - def self.curlInstallRoot - return "#{installRoot}/curl" - end - - def self.xmlInstallRoot - return "#{installRoot}/xml" - end - - # Misc - - def self.icuPatchesRoot - return "#{root}/Patches/icu" - end - - def self.projectsRoot - return "#{root}/Projects" - end - def self.sources return "#{root}/#{Location.sources}" end @@ -120,14 +26,8 @@ def self.patches return "#{root}/#{Location.patches}" end - def self.getEnvVariable(name) - result = ENV[name] - if result.nil? - puts "Environment variable \"#{name}\" is not found. Did you completed Vagrant setup?" - puts "Check \"config.vm.provision\" setting in Vagrantfile..." - abort - end - return result + def self.projects + return "#{root}/#{Location.projects}" end end diff --git a/Scripts/Common/Location.rb b/Scripts/Common/Location.rb index 512c16c8..6b251fc3 100644 --- a/Scripts/Common/Location.rb +++ b/Scripts/Common/Location.rb @@ -19,4 +19,9 @@ def self.downloads def self.patches return "Patches" end + + def self.projects + return "Projects" + end + end From a2d32061065788a6f529c487b03095bb206afb6d Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 10:22:23 +0100 Subject: [PATCH 52/66] Update. --- Rakefile | 26 ++++++++++++------------- Scripts/ADBHelper.rb | 18 ++++++++++------- Scripts/Builders/HelloProjectBuilder.rb | 5 ++++- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Rakefile b/Rakefile index 7dd077e5..1ef382ea 100755 --- a/Rakefile +++ b/Rakefile @@ -40,19 +40,17 @@ Building Swift Toolchain. Steps: rake armv7a:make:icu rake armv7a:make:swift -3. Build `Hello` project. - Execute: "rake project:hello:build" +3. Install Android Tools for macOS. See: https://stackoverflow.com/questions/17901692/set-up-adb-on-mac-os-x -4. Install Android Tools for macOS. See: https://stackoverflow.com/questions/17901692/set-up-adb-on-mac-os-x +4. Connect Android device to Host. Enable USB Debugging on Android device. Verify that device is connected. + host$ rake project:hello:verify -5. Connect Android device to Host. Enable USB Debugging on Android device. Verify that device is connected. - Execute: "rake project:hello:verify" +5. Build, Deploy and run `Hello` Project to Android Device. + rake project:hello:build + rake project:hello:install + rake project:hello:run -6. Deploy and run Hello Project to Android Device. - Execute: "rake project:hello:install" - Execute: "rake project:hello:run" - -7. Repeat steps 2...6 for other architectures. +7. Repeat steps 2 and 6 for other architectures. \n EOM puts help @@ -311,7 +309,7 @@ namespace :project do desc "Project Hello: Install on Android" task :install do - binary = "#{Config.buildRoot}/hello/hello" + binary = HelloProjectBuilder.new().executable helper = ADBHelper.new() helper.deployLibs helper.deployProducts([binary]) @@ -319,12 +317,12 @@ namespace :project do desc "Project Hello: Run on Android" task :run do - ADBHelper.new().run("hello") + ADBHelper.new().run(HelloProjectBuilder.new().executableName) end desc "Project Hello: Cleanup on Android" - task :cleanup do - ADBHelper.new().cleanup("hello") + task :clean do + ADBHelper.new().cleanup(HelloProjectBuilder.new().executableName) end desc "Project Hello: Deploy and Run on Android" diff --git a/Scripts/ADBHelper.rb b/Scripts/ADBHelper.rb index 1a79be31..056eb464 100755 --- a/Scripts/ADBHelper.rb +++ b/Scripts/ADBHelper.rb @@ -1,5 +1,8 @@ require_relative "Common/Config.rb" require_relative "Common/Tool.rb" +require_relative "Builders/ICUBuilder.rb" +require_relative "Builders/SwiftBuilder.rb" +require_relative "Builders/AndroidBuilder.rb" # See also: # - Enable adb debugging on your device – https://developer.android.com/studio/command-line/adb#Enabling @@ -9,29 +12,30 @@ class ADBHelper < Tool def initialize() super() @destinationDirPath = "/data/local/tmp" + @swift = SwiftBuilder.new() + @ndk = AndroidBuilder.new() + @icu = ICUBuilder.new() end def verify() - # execute "sudo apt-get install android-tools-adb" - # execute "sudo adb devices" # To run daemon. + # 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() - swiftBuildDirPath = "#{Config.swiftBuildRoot}/swift-linux-x86_64/lib/swift/android" - Dir[swiftBuildDirPath + "/*.so"].each { |lib| + Dir["#{@swift.installs}/usr/lib/swift/android" + "/*.so"].each { |lib| cmd = "adb push #{lib} #{@destinationDirPath}" execute cmd } - icuLibsDirPath = "#{Config.icuInstallRoot}/armv7a/lib" - Dir[icuLibsDirPath + "/*.so*"].select { |lib| !File.symlink?(lib) } .each { |lib| + 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 cmd = "adb push #{lib} #{@destinationDirPath}/#{destName}" execute cmd } - cxxLibPath = "#{Config.ndkSourcesRoot}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so" + cxxLibPath = "#{@ndk.sources}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so" execute "adb push #{cxxLibPath} #{@destinationDirPath}" end diff --git a/Scripts/Builders/HelloProjectBuilder.rb b/Scripts/Builders/HelloProjectBuilder.rb index 70fe414a..31f23aba 100755 --- a/Scripts/Builders/HelloProjectBuilder.rb +++ b/Scripts/Builders/HelloProjectBuilder.rb @@ -4,9 +4,12 @@ # - Build error: No such module "SwiftGlibc" – https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20160919/002955.html class HelloProjectBuilder < Builder + attr_reader :executable, :executableName + def initialize(arch = Arch.default) super("Hello", arch) - @executable = @builds + "/hello" + @executableName = "hello" + @executable = @builds + "/" + @executableName @projectRoot = "#{Config.projects}/Hello" end From ecb4aa8f603c446376c4ea4207f3049827ab75cd Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 11:12:02 +0100 Subject: [PATCH 53/66] Added support for checking out certain revision. --- Rakefile | 18 ------------------ Scripts/Builders/CMarkBuilder.rb | 2 +- Scripts/Builders/ClangBuilder.rb | 2 +- Scripts/Builders/CompilerRTBuilder.rb | 2 +- Scripts/Builders/DispatchBuilder.rb | 2 +- Scripts/Builders/FoundationBuilder.rb | 2 +- Scripts/Builders/ICUBuilder.rb | 2 +- Scripts/Builders/LLVMBuilder.rb | 2 +- Scripts/Builders/SwiftBuilder.rb | 2 +- Scripts/Common/Builder.rb | 11 +++++++---- 10 files changed, 15 insertions(+), 30 deletions(-) diff --git a/Rakefile b/Rakefile index 1ef382ea..632e9a7b 100755 --- a/Rakefile +++ b/Rakefile @@ -202,24 +202,6 @@ namespace :armv7a do end -namespace :update do - - desc "Updated Git repositories: `swift/utils/update-checkout`" - task :swift do - SwiftBuilder.new().update - end - -end - -namespace :help do - - desc "Show Build options: `swift/utils/build-script --help`" - task :swift do - SwiftBuilder.new().help - end - -end - namespace :foundation do desc "Build libFoundation" diff --git a/Scripts/Builders/CMarkBuilder.rb b/Scripts/Builders/CMarkBuilder.rb index 42ceafd3..8bb5f744 100644 --- a/Scripts/Builders/CMarkBuilder.rb +++ b/Scripts/Builders/CMarkBuilder.rb @@ -19,7 +19,7 @@ def configure end def checkout - checkoutIfNeeded(@sources, "https://github.com/apple/swift-cmark.git") + checkoutIfNeeded(@sources, "https://github.com/apple/swift-cmark.git", "32fa49671d0fc5d1f65d2bcbabfb1511a9d65c27") end def build diff --git a/Scripts/Builders/ClangBuilder.rb b/Scripts/Builders/ClangBuilder.rb index 419fcb9b..7e58c24b 100644 --- a/Scripts/Builders/ClangBuilder.rb +++ b/Scripts/Builders/ClangBuilder.rb @@ -7,7 +7,7 @@ def initialize(arch = Arch.default) end def checkout - checkoutIfNeeded(@sources, "https://github.com/apple/swift-clang.git") + checkoutIfNeeded(@sources, "https://github.com/apple/swift-clang.git", "41ac4c42625c7a881ef7a9d2c8fe6f61daacbca0") end end diff --git a/Scripts/Builders/CompilerRTBuilder.rb b/Scripts/Builders/CompilerRTBuilder.rb index 8d04f0cf..4de5a1ca 100644 --- a/Scripts/Builders/CompilerRTBuilder.rb +++ b/Scripts/Builders/CompilerRTBuilder.rb @@ -7,7 +7,7 @@ def initialize(arch = Arch.default) end def checkout - checkoutIfNeeded(@sources, "https://github.com/apple/swift-compiler-rt.git") + checkoutIfNeeded(@sources, "https://github.com/apple/swift-compiler-rt.git", "d4667fe980efc317baf2641bc29ce1d41a1a0a6b") end end diff --git a/Scripts/Builders/DispatchBuilder.rb b/Scripts/Builders/DispatchBuilder.rb index 0db98da6..149eacaf 100644 --- a/Scripts/Builders/DispatchBuilder.rb +++ b/Scripts/Builders/DispatchBuilder.rb @@ -71,7 +71,7 @@ def clean end def checkout - checkoutIfNeeded(@sources, "https://github.com/apple/swift-corelibs-libdispatch.git") + checkoutIfNeeded(@sources, "https://github.com/apple/swift-corelibs-libdispatch.git", "afa6cc3d1c42935c5a1016ec7ae13ddcbb1853d4") end end diff --git a/Scripts/Builders/FoundationBuilder.rb b/Scripts/Builders/FoundationBuilder.rb index 25e2872e..fe856cae 100644 --- a/Scripts/Builders/FoundationBuilder.rb +++ b/Scripts/Builders/FoundationBuilder.rb @@ -106,7 +106,7 @@ def clean end def checkout - checkoutIfNeeded(@sources, "https://github.com/apple/swift-corelibs-foundation") + checkoutIfNeeded(@sources, "https://github.com/apple/swift-corelibs-foundation", "a7f12d0851780b2c196733b2710a8ff2ae56bdcd") end end diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index d57b84b4..4e5a1182 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -84,7 +84,7 @@ def configure end def checkout - checkoutIfNeeded(@gitRepoRoot, "https://github.com/unicode-org/icu.git") + checkoutIfNeeded(@gitRepoRoot, "https://github.com/unicode-org/icu.git", "2e86b08fcda87e279efdcb8f9f3310cb6b9150af") end def prepare() diff --git a/Scripts/Builders/LLVMBuilder.rb b/Scripts/Builders/LLVMBuilder.rb index 7d5dc7f6..076d6de6 100644 --- a/Scripts/Builders/LLVMBuilder.rb +++ b/Scripts/Builders/LLVMBuilder.rb @@ -42,7 +42,7 @@ def make end def checkout - checkoutIfNeeded(@sources, "https://github.com/apple/swift-llvm.git") + checkoutIfNeeded(@sources, "https://github.com/apple/swift-llvm.git", "f63b283c7143aef31863d5915c28ee79ed390be3") end def prepare() diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 42b39936..57ac8b06 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -188,7 +188,7 @@ def make end def checkout - checkoutIfNeeded(@sources, "https://github.com/apple/swift.git") + checkoutIfNeeded(@sources, "https://github.com/apple/swift.git", "8e38b67d66b41af9062627653963384db0a799eb") end def clean diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index c1f26870..3ddaf3e4 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -46,13 +46,16 @@ def logInstallCompleted message "\"#{@component}\" install is completed." end - def checkoutIfNeeded(localPath, repoURL) + def checkoutIfNeeded(localPath, repoURL, revision) if File.exist?(localPath) message "Repository \"#{repoURL}\" seems already checked out to \"#{localPath}\"." else - dir = File.dirname(localPath) - execute "mkdir -p \"#{dir}\"" - execute "cd \"#{dir}\" && git clone --depth=10 #{repoURL} \"#{localPath}\"" + execute "mkdir -p \"#{localPath}\"" + # Checking out specific SHA - https://stackoverflow.com/a/43136160/1418981 + execute "cd \"#{localPath}\" && git init && git remote add origin \"#{repoURL}\"" + execute "cd \"#{localPath}\" && git config --local uploadpack.allowReachableSHA1InWant true" + execute "cd \"#{localPath}\" && git fetch --depth 10 origin #{revision}" + execute "cd \"#{dir}\" && git checkout FETCH_HEAD" message "#{repoURL} checkout to \"#{localPath}\" is completed." end end From 4042e795a9face68a58a021d8bde09dd0b648a51 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 11:17:41 +0100 Subject: [PATCH 54/66] Added patch removalroutine. --- Scripts/Builders/ICUBuilder.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index 4e5a1182..00f079b7 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -104,9 +104,16 @@ def applyPatchIfNeeded() end end + def removePatchIfNeeded + message "Removing previously applied patch..." + execute "cd \"#{@gitRepoRoot}\" && git reset --hard" + execute "cd \"#{@gitRepoRoot}\" && git clean -f" + end + def build execute "cd #{@builds} && PATH=#{@ndk.installs}/bin:$PATH make -j4" logBuildCompleted + removePatchIfNeeded end def install From ea0f091e15e503ae337bcb13f5f8d6fa455bfc8e Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 12:02:39 +0100 Subject: [PATCH 55/66] Simplification. --- Rakefile | 247 +++++++++++++------------------ Scripts/Builders/ICUBuilder.rb | 10 +- Scripts/Builders/SwiftBuilder.rb | 18 ++- 3 files changed, 129 insertions(+), 146 deletions(-) diff --git a/Rakefile b/Rakefile index 632e9a7b..6fb6d6bd 100755 --- a/Rakefile +++ b/Rakefile @@ -27,81 +27,83 @@ task :usage do Building Swift Toolchain. Steps: -1. Checkout Sources. - rake checkout:icu - rake checkout:llvm - rake checkout:swift - rake checkout:ndk +1. Get Sources and Tools. + host$ rake checkout + host$ rake download Alternatively you can download Android NDK manually form https://developer.android.com/ndk/downloads/ and put archive to Downloads folder. -2. Configure and Build Sources: - rake armv7a:setup:ndk - rake armv7a:make:icu - rake armv7a:make:swift +2. Build all Swift components for armv7a: + box$ rake armv7a:build 3. Install Android Tools for macOS. See: https://stackoverflow.com/questions/17901692/set-up-adb-on-mac-os-x 4. Connect Android device to Host. Enable USB Debugging on Android device. Verify that device is connected. - host$ rake project:hello:verify + host$ rake verify 5. Build, Deploy and run `Hello` Project to Android Device. - rake project:hello:build - rake project:hello:install - rake project:hello:run + box$ rake hello:build + host$ rake hello:deploy -7. Repeat steps 2 and 6 for other architectures. -\n EOM puts help - system "rake -T" + system "rake -T | grep --invert-match develop" end -namespace :verify do - desc "Verify environment variables" - task :environment do - Config.verify - end +desc "Verify ADB shell setup." +task :verify do + ADBHelper.new().verify end -namespace :checkout do +desc "Show more actions (for Developers)." +task :more do + system "rake -T | grep develop" +end - desc "Checkout Swift, libDispatch, libFoundation, CMark" - task :swift do - SwiftBuilder.new().checkout - DispatchBuilder.new().checkout - FoundationBuilder.new().checkout - CMarkBuilder.new().checkout - end +desc "Checkout Sources of all Components from Git." +task :checkout do + SwiftBuilder.new().checkout + DispatchBuilder.new().checkout + FoundationBuilder.new().checkout + CMarkBuilder.new().checkout + ICUBuilder.new().checkout + LLVMBuilder.new().checkout + ClangBuilder.new().checkout + CompilerRTBuilder.new().checkout +end - desc "Checkout ICU" - task :icu do - ICUBuilder.new().checkout - end +desc "Download Android NDK" +task :download do + AndroidBuilder.new().download +end + +namespace :armv7a do - desc "Checkout LLVM, Clang, Compiler-RT" - task :llvm do - LLVMBuilder.new().checkout - ClangBuilder.new().checkout - CompilerRTBuilder.new().checkout + desc "Setup NDK Toolchain." + task :setup do + AndroidBuilder.new(Arch.armv7a).setup end - desc "Download Android NDK" - task :ndk do - AndroidBuilder.new().download + desc "Build Swift Toolchain." + task build: [":develop:install:hello", ":develop:run:helo"] do end end -namespace :armv7a do +namespace :hello do - namespace :setup do - desc "Setup NDK Toolchain." - task :ndk do - AndroidBuilder.new(Arch.armv7a).setup - end + desc "Builds sample project" + task :build do + HelloProjectBuilder.new().build end + desc "Deploy and Run on Android" + task deploy: [":develop:make:icu", ":develop:make:swift"] do + end +end + +namespace :develop do + namespace :configure do desc "Configure ICU" task :icu do @@ -157,6 +159,14 @@ namespace :armv7a do task :cmark do CMarkBuilder.new(Arch.armv7a).install end + + desc "Install Hello project on Android" + task :hello do + binary = HelloProjectBuilder.new().executable + helper = ADBHelper.new() + helper.deployLibs + helper.deployProducts([binary]) + end end namespace :make do @@ -176,6 +186,14 @@ namespace :armv7a do task :cmark do CMarkBuilder.new(Arch.armv7a).make end + desc "Configure, Build and Install libDispatch" + task :dispatch do + DispatchBuilder.new().make + end + desc "Configure, Build and Install libFoundation" + task :foundation do + FoundationBuilder.new().make + end end namespace :clean do @@ -194,123 +212,72 @@ namespace :armv7a do SwiftBuilder.new(Arch.armv7a).clean end - desc "LLVM Swift." + desc "Clean LLVM." task :llvm do LLVMBuilder.new(Arch.armv7a).clean end - end - -end - -namespace :foundation do - - desc "Build libFoundation" - task :build do - FoundationBuilder.new().make - end - - desc "Clean libFoundation" - task :clean do - FoundationBuilder.new().clean - end - -end - -namespace :dispatch do - - desc "Build libDispatch" - task :build do - DispatchBuilder.new().make - end - - desc "Clean libDispatch" - task :clean do - DispatchBuilder.new().clean - end - - desc "Rebuild libDispatch" - task rebuild: [:clean, :build] do - end - -end -namespace :xml do - - desc "Checkout libXML" - task :checkout do - XMLBuilder.new().checkout - end - - desc "Build libXML" - task :make do - XMLBuilder.new().make - end - -end + desc "Clean libDispatch" + task :dispatch do + DispatchBuilder.new().clean + end -namespace :curl do + desc "Clean libFoundation" + task :foundation do + FoundationBuilder.new().clean + end - desc "Checkout curl" - task :checkout do - CurlBuilder.new().checkout + desc "Clean Hello project." + task :hello do + ADBHelper.new().cleanup(HelloProjectBuilder.new().executableName) + end end - desc "Build curl" - task :make do - CurlBuilder.new().make + namespace :run do + desc "Run Hello project on Android" + task :helo do + ADBHelper.new().run(HelloProjectBuilder.new().executableName) + end end -end + namespace :xml do -namespace :openssl do + desc "Checkout libXML" + task :checkout do + XMLBuilder.new().checkout + end - desc "Checkout OpenSSL" - task :checkout do - OpenSSLBuilder.new().checkout - end + desc "Build libXML" + task :make do + XMLBuilder.new().make + end - desc "Make OpenSSL" - task :make do - OpenSSLBuilder.new().make end -end - -namespace :project do - namespace :hello do + namespace :curl do - desc "Project Hello: Build" - task :build do - HelloProjectBuilder.new().build + desc "Checkout curl" + task :checkout do + CurlBuilder.new().checkout end - desc "Project Hello: Verify" - task :verify do - ADBHelper.new().verify + desc "Build curl" + task :make do + CurlBuilder.new().make end - desc "Project Hello: Install on Android" - task :install do - binary = HelloProjectBuilder.new().executable - helper = ADBHelper.new() - helper.deployLibs - helper.deployProducts([binary]) - end + end - desc "Project Hello: Run on Android" - task :run do - ADBHelper.new().run(HelloProjectBuilder.new().executableName) - end + namespace :openssl do - desc "Project Hello: Cleanup on Android" - task :clean do - ADBHelper.new().cleanup(HelloProjectBuilder.new().executableName) + desc "Checkout OpenSSL" + task :checkout do + OpenSSLBuilder.new().checkout end - desc "Project Hello: Deploy and Run on Android" - task deploy: [:install, :run] do + desc "Make OpenSSL" + task :make do + OpenSSLBuilder.new().make end - end - end diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index 00f079b7..2aeed0d1 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -22,6 +22,7 @@ def initialize(arch = Arch.default) end def configureHost + prepare cmd = ["cd #{@builds} &&"] cmd << 'CC="/usr/bin/clang"' cmd << 'CXX="/usr/bin/clang++"' @@ -36,13 +37,13 @@ def configureHost def configure if !@host.nil? && !File.exist?(@host.bin) message "Building Corss-Build Host." - @host.prepare @host.configureHost @host.build @host.install message "Corss-Build Host Build completed." end + prepare cmd = ["cd #{@builds} &&"] cmd << "PATH=#{@ndk.installs}/bin:$PATH" if @arch == Arch.armv7a @@ -89,7 +90,6 @@ def checkout def prepare() execute "mkdir -p #{@builds}" - applyPatchIfNeeded() end def applyPatchIfNeeded() @@ -104,13 +104,16 @@ def applyPatchIfNeeded() end end - def removePatchIfNeeded + def removePatchIfNeeded() message "Removing previously applied patch..." execute "cd \"#{@gitRepoRoot}\" && git reset --hard" execute "cd \"#{@gitRepoRoot}\" && git clean -f" end def build + prepare + removePatchIfNeeded + applyPatchIfNeeded execute "cd #{@builds} && PATH=#{@ndk.installs}/bin:$PATH make -j4" logBuildCompleted removePatchIfNeeded @@ -122,7 +125,6 @@ def install end def make - prepare configure build install diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 57ac8b06..7c49fe11 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -166,22 +166,36 @@ def build cmd << "--build-dir #{@builds}" execute cmd.join(" ") logBuildCompleted() + removeLinkerSymLink() end def prepare + removeLinkerSymLink() execute "mkdir -p #{@builds}" # Fix for missed file: `CMake Error at cmake/modules/SwiftSharedCMakeConfig.cmake:196 (include):` # execute "touch \"#{@cmark.builds}/src/CMarkExports.cmake\"" + setupLinkerSymLink() + end - if @arch != Arch.host + 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 -a /usr/bin/*ld.gold" + 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 From 604a40e093ee7e86ac943847c5a02138c08ef8dd Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 12:17:45 +0100 Subject: [PATCH 56/66] Simplification. --- Rakefile | 359 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 182 insertions(+), 177 deletions(-) diff --git a/Rakefile b/Rakefile index 6fb6d6bd..7bc72498 100755 --- a/Rakefile +++ b/Rakefile @@ -36,12 +36,13 @@ Building Swift Toolchain. Steps: 2. Build all Swift components for armv7a: box$ rake armv7a:build -3. Install Android Tools for macOS. See: https://stackoverflow.com/questions/17901692/set-up-adb-on-mac-os-x - -4. Connect Android device to Host. Enable USB Debugging on Android device. Verify that device is connected. +3. Enable USB Debugging on Android device. Install Android Tools for macOS. Connect Android device and Verify ADB shell setup. host$ rake verify -5. Build, Deploy and run `Hello` Project to Android Device. + See: How to Install Android Tools for macOS: https://stackoverflow.com/questions/17901692/set-up-adb-on-mac-os-x + See: How to Enable USB Debugging on Android device: https://developer.android.com/studio/debug/dev-options + +4. Build, Deploy and run Demo project to Android Device. box$ rake hello:build host$ rake hello:deploy @@ -85,12 +86,12 @@ namespace :armv7a do end desc "Build Swift Toolchain." - task build: [":develop:install:hello", ":develop:run:helo"] do + task build: [":develop:make:icu", ":develop:make:swift"] do end end -namespace :hello do +namespace :project do desc "Builds sample project" task :build do @@ -98,186 +99,190 @@ namespace :hello do end desc "Deploy and Run on Android" - task deploy: [":develop:make:icu", ":develop:make:swift"] do + task deploy: [":develop:install:hello", ":develop:run:helo"] do end end namespace :develop do - namespace :configure do - desc "Configure ICU" - task :icu do - ICUBuilder.new(Arch.armv7a).configure - end - desc "Configure Swift" - task :swift do - SwiftBuilder.new(Arch.armv7a).configure - end - desc "Configure LLVM" - task :llvm do - LLVMBuilder.new(Arch.armv7a).configure - end - desc "Configure CMark" - task :cmark do - CMarkBuilder.new(Arch.armv7a).configure - end - end - - namespace :build do - desc "Build ICU" - task :icu do - ICUBuilder.new(Arch.armv7a).build + namespace :armv7a do + + namespace :configure do + desc "Configure ICU" + task :icu do + ICUBuilder.new(Arch.armv7a).configure + end + desc "Configure Swift" + task :swift do + SwiftBuilder.new(Arch.armv7a).configure + end + desc "Configure LLVM" + task :llvm do + LLVMBuilder.new(Arch.armv7a).configure + end + desc "Configure CMark" + task :cmark do + CMarkBuilder.new(Arch.armv7a).configure + end + end + + namespace :build do + desc "Build ICU" + task :icu do + ICUBuilder.new(Arch.armv7a).build + end + desc "Build Swift" + task :swift do + SwiftBuilder.new(Arch.armv7a).build + end + desc "Build LLVM" + task :llvm do + LLVMBuilder.new(Arch.armv7a).build + end + desc "Build CMark" + task :cmark do + CMarkBuilder.new(Arch.armv7a).build + end + end + + namespace :install do + desc "Install ICU" + task :icu do + ICUBuilder.new(Arch.armv7a).install + end + desc "Install Swift" + task :swift do + SwiftBuilder.new(Arch.armv7a).install + end + desc "Install LLVM" + task :llvm do + LLVMBuilder.new(Arch.armv7a).install + end + desc "Install CMark" + task :cmark do + CMarkBuilder.new(Arch.armv7a).install + end + + desc "Install Hello project on Android" + task :hello do + binary = HelloProjectBuilder.new(Arch.armv7a).executable + helper = ADBHelper.new() + helper.deployLibs + helper.deployProducts([binary]) + end + end + + namespace :make do + desc "Configure, Build and Install ICU" + task :icu do + ICUBuilder.new(Arch.armv7a).make + end + desc "Configure, Build and Install Swift" + task :swift do + SwiftBuilder.new(Arch.armv7a).make + end + desc "Configure, Build and Install LLVM" + task :llvm do + LLVMBuilder.new(Arch.armv7a).make + end + desc "Configure, Build and Install CMark" + task :cmark do + CMarkBuilder.new(Arch.armv7a).make + end + desc "Configure, Build and Install libDispatch" + task :dispatch do + DispatchBuilder.new().make + end + desc "Configure, Build and Install libFoundation" + task :foundation do + FoundationBuilder.new().make + end + end + + namespace :clean do + desc "Clean ICU." + task :icu do + ICUBuilder.new(Arch.armv7a).clean + end + + desc "Clean NDK." + task :ndk do + AndroidBuilder.new(Arch.armv7a).clean + end + + desc "Clean Swift." + task :swift do + SwiftBuilder.new(Arch.armv7a).clean + end + + desc "Clean LLVM." + task :llvm do + LLVMBuilder.new(Arch.armv7a).clean + end + + desc "Clean libDispatch" + task :dispatch do + DispatchBuilder.new().clean + end + + desc "Clean libFoundation" + task :foundation do + FoundationBuilder.new().clean + end + + desc "Clean Hello project." + task :hello do + ADBHelper.new().cleanup(HelloProjectBuilder.new(Arch.armv7a).executableName) + end + end + + namespace :run do + desc "Run Hello project on Android" + task :helo do + ADBHelper.new().run(HelloProjectBuilder.new(Arch.armv7a).executableName) + end + end + + namespace :xml do + + desc "Checkout libXML" + task :checkout do + XMLBuilder.new().checkout + end + + desc "Build libXML" + task :make do + XMLBuilder.new().make + end + + end + + namespace :curl do + + desc "Checkout curl" + task :checkout do + CurlBuilder.new().checkout + end + + desc "Build curl" + task :make do + CurlBuilder.new().make + end + end - desc "Build Swift" - task :swift do - SwiftBuilder.new(Arch.armv7a).build - end - desc "Build LLVM" - task :llvm do - LLVMBuilder.new(Arch.armv7a).build - end - desc "Build CMark" - task :cmark do - CMarkBuilder.new(Arch.armv7a).build - end - end - namespace :install do - desc "Install ICU" - task :icu do - ICUBuilder.new(Arch.armv7a).install - end - desc "Install Swift" - task :swift do - SwiftBuilder.new(Arch.armv7a).install - end - desc "Install LLVM" - task :llvm do - LLVMBuilder.new(Arch.armv7a).install - end - desc "Install CMark" - task :cmark do - CMarkBuilder.new(Arch.armv7a).install - end - - desc "Install Hello project on Android" - task :hello do - binary = HelloProjectBuilder.new().executable - helper = ADBHelper.new() - helper.deployLibs - helper.deployProducts([binary]) - end - end - - namespace :make do - desc "Configure, Build and Install ICU" - task :icu do - ICUBuilder.new(Arch.armv7a).make - end - desc "Configure, Build and Install Swift" - task :swift do - SwiftBuilder.new(Arch.armv7a).make - end - desc "Configure, Build and Install LLVM" - task :llvm do - LLVMBuilder.new(Arch.armv7a).make - end - desc "Configure, Build and Install CMark" - task :cmark do - CMarkBuilder.new(Arch.armv7a).make - end - desc "Configure, Build and Install libDispatch" - task :dispatch do - DispatchBuilder.new().make - end - desc "Configure, Build and Install libFoundation" - task :foundation do - FoundationBuilder.new().make - end - end - - namespace :clean do - desc "Clean ICU." - task :icu do - ICUBuilder.new(Arch.armv7a).clean - end - - desc "Clean NDK." - task :ndk do - AndroidBuilder.new(Arch.armv7a).clean - end + namespace :openssl do + + desc "Checkout OpenSSL" + task :checkout do + OpenSSLBuilder.new().checkout + end - desc "Clean Swift." - task :swift do - SwiftBuilder.new(Arch.armv7a).clean + desc "Make OpenSSL" + task :make do + OpenSSLBuilder.new().make + end end - desc "Clean LLVM." - task :llvm do - LLVMBuilder.new(Arch.armv7a).clean - end - - desc "Clean libDispatch" - task :dispatch do - DispatchBuilder.new().clean - end - - desc "Clean libFoundation" - task :foundation do - FoundationBuilder.new().clean - end - - desc "Clean Hello project." - task :hello do - ADBHelper.new().cleanup(HelloProjectBuilder.new().executableName) - end - end - - namespace :run do - desc "Run Hello project on Android" - task :helo do - ADBHelper.new().run(HelloProjectBuilder.new().executableName) - end - end - - namespace :xml do - - desc "Checkout libXML" - task :checkout do - XMLBuilder.new().checkout - end - - desc "Build libXML" - task :make do - XMLBuilder.new().make - end - - end - - namespace :curl do - - desc "Checkout curl" - task :checkout do - CurlBuilder.new().checkout - end - - desc "Build curl" - task :make do - CurlBuilder.new().make - end - - end - - namespace :openssl do - - desc "Checkout OpenSSL" - task :checkout do - OpenSSLBuilder.new().checkout - end - - desc "Make OpenSSL" - task :make do - OpenSSLBuilder.new().make - end end end From fd1985067317d9b33764a9180f23a11e8aff916f Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 12:22:40 +0100 Subject: [PATCH 57/66] Simplification. --- Rakefile | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Rakefile b/Rakefile index 7bc72498..102417c6 100755 --- a/Rakefile +++ b/Rakefile @@ -27,13 +27,17 @@ task :usage do Building Swift Toolchain. Steps: +Note: Every time you see host$ – this means that command should be executed on HOST macOS computer. + Every time you see box$ – this means that command should be executed on virtual GUEST Linux OS. + 1. Get Sources and Tools. host$ rake checkout host$ rake download Alternatively you can download Android NDK manually form https://developer.android.com/ndk/downloads/ and put archive to Downloads folder. -2. Build all Swift components for armv7a: +2. Setup and Build all Swift components for armv7a: + box$ rake armv7a:setup box$ rake armv7a:build 3. Enable USB Debugging on Android device. Install Android Tools for macOS. Connect Android device and Verify ADB shell setup. @@ -43,8 +47,8 @@ Building Swift Toolchain. Steps: See: How to Enable USB Debugging on Android device: https://developer.android.com/studio/debug/dev-options 4. Build, Deploy and run Demo project to Android Device. - box$ rake hello:build - host$ rake hello:deploy + box$ rake armv7a:project:build + host$ rake armv7a:project:deploy EOM puts help @@ -86,23 +90,24 @@ namespace :armv7a do end desc "Build Swift Toolchain." - task build: [":develop:make:icu", ":develop:make:swift"] do + task build: [":develop:armv7a:make:icu", ":develop:armv7a:make:swift"] do end -end + namespace :project do -namespace :project do + desc "Builds Sample project" + task :build do + HelloProjectBuilder.new(Arch.armv7a).build + end - desc "Builds sample project" - task :build do - HelloProjectBuilder.new().build + desc "Deploy and Run on Android" + task deploy: [":develop:armv7a:install:project", ":develop:armv7a:run:project"] do + end end - desc "Deploy and Run on Android" - task deploy: [":develop:install:hello", ":develop:run:helo"] do - end end + namespace :develop do namespace :armv7a do From f3c3d01786cfe0bc5a776e620d410d33fc354ab0 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 12:25:34 +0100 Subject: [PATCH 58/66] Update. --- Downloads/Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Downloads/Readme.md b/Downloads/Readme.md index 8935dd0e..e8fd802d 100644 --- a/Downloads/Readme.md +++ b/Downloads/Readme.md @@ -1 +1 @@ -# Automatically or Manually downloadded ICU, libXML, ... and Android NDK archives will be placed here +# Automatically or Manually downloadded Android NDK archive will be placed here From 220d12807717e7dbd5886335d910cb00f52dda7e Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 12:28:29 +0100 Subject: [PATCH 59/66] Simplification --- Scripts/ADBHelper.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Scripts/ADBHelper.rb b/Scripts/ADBHelper.rb index 056eb464..97dd49f4 100755 --- a/Scripts/ADBHelper.rb +++ b/Scripts/ADBHelper.rb @@ -1,8 +1,4 @@ -require_relative "Common/Config.rb" require_relative "Common/Tool.rb" -require_relative "Builders/ICUBuilder.rb" -require_relative "Builders/SwiftBuilder.rb" -require_relative "Builders/AndroidBuilder.rb" # See also: # - Enable adb debugging on your device – https://developer.android.com/studio/command-line/adb#Enabling From 74f5c2f62796fc7f5f030e3fd7fd039353d26639 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 12:32:05 +0100 Subject: [PATCH 60/66] Bump. --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 3eefcb9d..7dea76ed 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +1.0.1 From d2ade31c3d2a64c250bd51b992d8954fe96b902c Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 12:40:21 +0100 Subject: [PATCH 61/66] Fixes. --- Rakefile | 10 +++++----- Scripts/Common/Builder.rb | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 102417c6..fda8d38d 100755 --- a/Rakefile +++ b/Rakefile @@ -31,14 +31,15 @@ Note: Every time you see host$ – this means that command should be executed on Every time you see box$ – this means that command should be executed on virtual GUEST Linux OS. 1. Get Sources and Tools. - host$ rake checkout - host$ rake download + box$ rake checkout + box$ rake download Alternatively you can download Android NDK manually form https://developer.android.com/ndk/downloads/ and put archive to Downloads folder. -2. Setup and Build all Swift components for armv7a: +2. Setup and Build all Swift components and Sample project for armv7a: box$ rake armv7a:setup box$ rake armv7a:build + box$ rake armv7a:project:build 3. Enable USB Debugging on Android device. Install Android Tools for macOS. Connect Android device and Verify ADB shell setup. host$ rake verify @@ -46,8 +47,7 @@ Note: Every time you see host$ – this means that command should be executed on See: How to Install Android Tools for macOS: https://stackoverflow.com/questions/17901692/set-up-adb-on-mac-os-x See: How to Enable USB Debugging on Android device: https://developer.android.com/studio/debug/dev-options -4. Build, Deploy and run Demo project to Android Device. - box$ rake armv7a:project:build +4. Deploy and run Demo project to Android Device. host$ rake armv7a:project:deploy EOM diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index 3ddaf3e4..8585c329 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -55,7 +55,7 @@ def checkoutIfNeeded(localPath, repoURL, revision) execute "cd \"#{localPath}\" && git init && git remote add origin \"#{repoURL}\"" execute "cd \"#{localPath}\" && git config --local uploadpack.allowReachableSHA1InWant true" execute "cd \"#{localPath}\" && git fetch --depth 10 origin #{revision}" - execute "cd \"#{dir}\" && git checkout FETCH_HEAD" + execute "cd \"#{localPath}\" && git checkout FETCH_HEAD" message "#{repoURL} checkout to \"#{localPath}\" is completed." end end From 9bb890c4186fdd0b157a299f059f324495d5176d Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 12:46:13 +0100 Subject: [PATCH 62/66] Fixes. --- Scripts/Common/Builder.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Scripts/Common/Builder.rb b/Scripts/Common/Builder.rb index 8585c329..aec74477 100755 --- a/Scripts/Common/Builder.rb +++ b/Scripts/Common/Builder.rb @@ -55,7 +55,8 @@ def checkoutIfNeeded(localPath, repoURL, revision) execute "cd \"#{localPath}\" && git init && git remote add origin \"#{repoURL}\"" execute "cd \"#{localPath}\" && git config --local uploadpack.allowReachableSHA1InWant true" execute "cd \"#{localPath}\" && git fetch --depth 10 origin #{revision}" - execute "cd \"#{localPath}\" && git checkout FETCH_HEAD" + # Disable warning about detached HEAD - https://stackoverflow.com/a/45652159/1418981 + execute "cd \"#{localPath}\" && git -c advice.detachedHead=false checkout FETCH_HEAD" message "#{repoURL} checkout to \"#{localPath}\" is completed." end end From 79804db2b20f37062c78a55cd91649837304a6d1 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 13:06:00 +0100 Subject: [PATCH 63/66] Fixes. --- Scripts/Builders/AndroidBuilder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Scripts/Builders/AndroidBuilder.rb b/Scripts/Builders/AndroidBuilder.rb index 88e79b97..f8f82a20 100755 --- a/Scripts/Builders/AndroidBuilder.rb +++ b/Scripts/Builders/AndroidBuilder.rb @@ -18,7 +18,7 @@ def download() def setup cmd = [] cmd << "#{@sources}/build/tools/make-standalone-toolchain.sh" - cmd << "--platform=android-#{@api}" + cmd << "--platform=android-#{api}" cmd << "--install-dir=#{@installs}" if @arch == Arch.armv7a cmd << "--toolchain=arm-linux-androideabi-4.9" @@ -31,7 +31,7 @@ def setup end def clean() - execute "rm -rf #{@installs}/" + execute "rm -rf \"#{@installs}/\"" end end From 9e1cf73814848b8307b98a4a04e4a025d5b3496b Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 13:18:35 +0100 Subject: [PATCH 64/66] Fixes. --- Rakefile | 4 ++-- Scripts/Builders/ICUBuilder.rb | 33 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Rakefile b/Rakefile index fda8d38d..1f4d3575 100755 --- a/Rakefile +++ b/Rakefile @@ -90,7 +90,7 @@ namespace :armv7a do end desc "Build Swift Toolchain." - task build: [":develop:armv7a:make:icu", ":develop:armv7a:make:swift"] do + task build: ["develop:armv7a:make:icu", "develop:armv7a:make:swift"] do end namespace :project do @@ -101,7 +101,7 @@ namespace :armv7a do end desc "Deploy and Run on Android" - task deploy: [":develop:armv7a:install:project", ":develop:armv7a:run:project"] do + task deploy: ["develop:armv7a:install:project", "develop:armv7a:run:project"] do end end diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index 2aeed0d1..90afe4bc 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -23,6 +23,7 @@ def initialize(arch = Arch.default) def configureHost prepare + applyPatchIfNeeded(false) cmd = ["cd #{@builds} &&"] cmd << 'CC="/usr/bin/clang"' cmd << 'CXX="/usr/bin/clang++"' @@ -44,6 +45,8 @@ def configure end prepare + applyPatchIfNeeded(false) + applyPatchIfNeeded cmd = ["cd #{@builds} &&"] cmd << "PATH=#{@ndk.installs}/bin:$PATH" if @arch == Arch.armv7a @@ -92,31 +95,33 @@ def prepare() execute "mkdir -p #{@builds}" end - def applyPatchIfNeeded() + def applyPatchIfNeeded(shouldApply = true) originalFile = "#{@sources}/source/configure" backupFile = "#{@sources}/source/configure.orig" patchFile = "#{@patches}/configure.patch" - if !File.exist? backupFile - puts "Patching ICU..." - execute "patch --backup #{originalFile} #{patchFile}" + if shouldApply + if !File.exist? backupFile + puts "Patching ICU..." + execute "patch --backup #{originalFile} #{patchFile}" + else + puts "Backup file \"#{backupFile}\" exists. Seems you already patched ICU. Skipping..." + end else - puts "Backup file \"#{backupFile}\" exists. Seems you already patched ICU. Skipping..." + message "Removing previously applied patch..." + execute "cd \"#{@gitRepoRoot}\" && git checkout #{originalFile}" + if File.exist? backupFile + execute "rm -fv #{backupFile}" + end end end - def removePatchIfNeeded() - message "Removing previously applied patch..." - execute "cd \"#{@gitRepoRoot}\" && git reset --hard" - execute "cd \"#{@gitRepoRoot}\" && git clean -f" - end - def build prepare - removePatchIfNeeded - applyPatchIfNeeded execute "cd #{@builds} && PATH=#{@ndk.installs}/bin:$PATH make -j4" + if !@host.nil? + applyPatchIfNeeded(false) + end logBuildCompleted - removePatchIfNeeded end def install From 9172c02ca9e01a49617ed50bd94bc9e7db0ea0f6 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 13:34:40 +0100 Subject: [PATCH 65/66] Fixes. --- Scripts/Builders/ICUBuilder.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/Scripts/Builders/ICUBuilder.rb b/Scripts/Builders/ICUBuilder.rb index 90afe4bc..1fd745bc 100755 --- a/Scripts/Builders/ICUBuilder.rb +++ b/Scripts/Builders/ICUBuilder.rb @@ -118,9 +118,6 @@ def applyPatchIfNeeded(shouldApply = true) def build prepare execute "cd #{@builds} && PATH=#{@ndk.installs}/bin:$PATH make -j4" - if !@host.nil? - applyPatchIfNeeded(false) - end logBuildCompleted end From 5ab2ef34dd13003fcef6e29d73f34570902e4872 Mon Sep 17 00:00:00 2001 From: Vlad Gorloff Date: Sun, 23 Dec 2018 15:30:27 +0100 Subject: [PATCH 66/66] Fixes. --- Rakefile | 6 +++--- Scripts/Builders/SwiftBuilder.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 1f4d3575..443a7ee0 100755 --- a/Rakefile +++ b/Rakefile @@ -169,7 +169,7 @@ namespace :develop do end desc "Install Hello project on Android" - task :hello do + task :project do binary = HelloProjectBuilder.new(Arch.armv7a).executable helper = ADBHelper.new() helper.deployLibs @@ -236,14 +236,14 @@ namespace :develop do end desc "Clean Hello project." - task :hello do + task :project do ADBHelper.new().cleanup(HelloProjectBuilder.new(Arch.armv7a).executableName) end end namespace :run do desc "Run Hello project on Android" - task :helo do + task :project do ADBHelper.new().run(HelloProjectBuilder.new(Arch.armv7a).executableName) end end diff --git a/Scripts/Builders/SwiftBuilder.rb b/Scripts/Builders/SwiftBuilder.rb index 7c49fe11..e0cf5eb8 100755 --- a/Scripts/Builders/SwiftBuilder.rb +++ b/Scripts/Builders/SwiftBuilder.rb @@ -165,8 +165,8 @@ def build cmd << "--install-destdir=#{@installs}" cmd << "--build-dir #{@builds}" execute cmd.join(" ") - logBuildCompleted() removeLinkerSymLink() + logBuildCompleted() end def prepare