Skip to content
This repository has been archived by the owner on Aug 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #42 from vgorloff/develop
Browse files Browse the repository at this point in the history
RC 1.0.20
  • Loading branch information
vgorloff committed Jun 1, 2019
2 parents cce1203 + ad36f95 commit bf1b9c3
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 85 deletions.
33 changes: 33 additions & 0 deletions Automation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def perform()
elsif action.start_with?("build:") then buildComponent(action.sub("build:", ''))
elsif action.start_with?("clean:") then cleanComponent(action.sub("clean:", ''))
elsif action.start_with?("install:") then installComponent(action.sub("install:", ''))
elsif action.start_with?("patch:") then patchComponent(action.sub("patch:", ''))
elsif action.start_with?("unpatch:") then unpatchComponent(action.sub("unpatch:", ''))
elsif action.start_with?("configure:") then configureComponent(action.sub("configure:", ''))
else usage()
end
end
Expand Down Expand Up @@ -139,6 +142,35 @@ def installComponent(component)
end
end

def configureComponent(component)
if component == "swift" then SwiftBuilder.new().configure
elsif component == "dispatch" then @archsToBuild.each { |arch| DispatchBuilder.new(arch).configure }
else
puts "! Unknown component \"#{component}\"."
usage()
end
end

def patchComponent(component)
if component == "swift" then SwiftBuilder.new().patch
elsif component == "dispatch" then DispatchBuilder.new(Arch.default).patch
elsif component == "foundation" then FoundationBuilder.new(Arch.default).patch
else
puts "! Unknown component \"#{component}\"."
usage()
end
end

def unpatchComponent(component)
if component == "swift" then SwiftBuilder.new().unpatch
elsif component == "dispatch" then DispatchBuilder.new(Arch.default).unpatch
elsif component == "foundation" then FoundationBuilder.new(Arch.default).unpatch
else
puts "! Unknown component \"#{component}\"."
usage()
end
end

def install()
toolchainDir = Config.toolchainDir
if File.exists?(toolchainDir)
Expand All @@ -157,6 +189,7 @@ def copyAssets()
toolchainDir = Config.toolchainDir
FileUtils.copy_entry("#{Config.root}/Assets/Readme.md", "#{toolchainDir}/Readme.md", false, false, true)
FileUtils.copy_entry("#{Config.root}/VERSION", "#{toolchainDir}/VERSION", false, false, true)
FileUtils.copy_entry("#{Config.root}/LICENSE.txt", "#{toolchainDir}/LICENSE.txt", false, false, true)
utils = Dir["#{Config.root}/Assets/swiftc-*"]
utils += Dir["#{Config.root}/Assets/copy-libs-*"]
utils.each { |file|
Expand Down
19 changes: 19 additions & 0 deletions Patches/swift-corelibs-libdispatch/CMakeLists.txt.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 74b7849816c68bf492fd49f76bc735af84bf3ad0..0a1ec4b846243bf0916ce523ea3292340b7fcdf0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,6 +35,14 @@ include(DispatchUtilities)
set(SWIFT_LIBDIR "lib" CACHE PATH "Library folder name, defined by swift main buildscript")
set(INSTALL_LIBDIR "${SWIFT_LIBDIR}" CACHE PATH "Path where the libraries should be installed")

+# User-configurable Android specific options.
+set(SWIFT_ANDROID_API_LEVEL "" CACHE STRING
+ "Version number for the Android API")
+set(SWIFT_ANDROID_NDK_PATH "" CACHE STRING
+ "Path to the directory that contains the Android NDK tools that are executable on the build machine")
+set(SWIFT_ANDROID_NDK_GCC_VERSION "" CACHE STRING
+ "The GCC version to use when building for Android. Currently only 4.9 is supported.")
+
include(DispatchAppleOptions)
include(DispatchSanitization)

This file was deleted.

63 changes: 63 additions & 0 deletions Patches/swift-corelibs-libdispatch/src/CMakeLists.txt.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cefde62a5538b8ff2acbf14baaccefa5ac65b9f0..019aab5c41b3af275b584bc2e9b99625a212bd05 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -120,6 +120,42 @@ if(ENABLE_SWIFT)
set(use_ld_flag -use-ld=gold)
endif()

+ # Android specific configuration.
+ # TODO: Add checks and raise warnings if `SWIFT_ANDROID_*` variables not set.
+ if(CMAKE_SYSTEM_NAME STREQUAL Android)
+ if("${ANDROID_ABI}" STREQUAL "armeabi-v7a")
+ set(SWIFT_SDK_ANDROID_ARCH_NDK_TRIPLE "arm-linux-androideabi")
+ set(SWIFT_SDK_ANDROID_SWIFT_ARCH_NAME "armv7")
+ elseif("${ANDROID_ABI}" STREQUAL "arm64-v8a")
+ set(SWIFT_SDK_ANDROID_ARCH_NDK_TRIPLE "aarch64-linux-android")
+ set(SWIFT_SDK_ANDROID_SWIFT_ARCH_NAME "aarch64")
+ elseif("${ANDROID_ABI}" STREQUAL "x86")
+ set(SWIFT_SDK_ANDROID_ARCH_NDK_TRIPLE "i686-linux-android")
+ set(SWIFT_SDK_ANDROID_SWIFT_ARCH_NAME "i686")
+ elseif("${ANDROID_ABI}" STREQUAL "x86_64")
+ set(SWIFT_SDK_ANDROID_ARCH_NDK_TRIPLE "x86_64-linux-android")
+ set(SWIFT_SDK_ANDROID_SWIFT_ARCH_NAME "x86_64")
+ else()
+ message(FATAL_ERROR "Unknown arch for android SDK: ${ANDROID_ABI}")
+ endif()
+
+ # Get the prebuilt suffix to create the correct toolchain path when using the NDK
+ if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin")
+ set(_swift_android_prebuilt_build "darwin-x86_64")
+ elseif("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
+ set(_swift_android_prebuilt_build "linux-x86_64")
+ endif()
+ set(SWIFT_SDK_ANDROID_ARCH_NDK_PREBUILT_PATH "${SWIFT_ANDROID_NDK_PATH}/toolchains/llvm/prebuilt/${_swift_android_prebuilt_build}")
+
+ # Setting Android specific Swift flags.
+ get_filename_component(swift_android_lib_directory_path ${CMAKE_SWIFT_COMPILER} DIRECTORY)
+ set(swift_android_lib_directory_path ${swift_android_lib_directory_path}/../lib/swift/android/${SWIFT_SDK_ANDROID_SWIFT_ARCH_NAME})
+ get_filename_component(swift_android_lib_directory_path ${swift_android_lib_directory_path} ABSOLUTE)
+
+ set(swift_android_link_flags -L ${swift_android_lib_directory_path} -tools-directory ${SWIFT_SDK_ANDROID_ARCH_NDK_PREBUILT_PATH}/bin)
+ set(swift_android_compile_flags -Xcc -I${SWIFT_ANDROID_NDK_PATH}/sysroot/usr/include -Xcc -I${SWIFT_ANDROID_NDK_PATH}/sysroot/usr/include/${SWIFT_SDK_ANDROID_ARCH_NDK_TRIPLE})
+ endif()
+
add_swift_library(swiftDispatch
CFLAGS
-fblocks
@@ -129,6 +165,7 @@ if(ENABLE_SWIFT)
DispatchStubs
LINK_FLAGS
${use_ld_flag}
+ ${swift_android_link_flags}
-lDispatchStubs
-L $<TARGET_LINKER_FILE_DIR:BlocksRuntime>
-lBlocksRuntime
@@ -160,6 +197,7 @@ if(ENABLE_SWIFT)
# TODO(compnerd) handle /MT builds
$<$<PLATFORM_ID:Windows>:-Xcc>
$<$<PLATFORM_ID:Windows>:-D_DLL>
+ ${swift_android_compile_flags}
TARGET
${CMAKE_C_COMPILER_TARGET})
endif()
21 changes: 10 additions & 11 deletions Patches/swift/cmake/modules/SwiftConfigureSDK.cmake.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/cmake/modules/SwiftConfigureSDK.cmake b/cmake/modules/SwiftConfigureSDK.cmake
index 21e47a6e6382cc19ea192d388677ec3e6276bc86..eb113dd162b20fa63e8e3dce5daf53042cabb999 100644
index f5d77456dd43461154fcd91d16e7751d7355f698..339a5d739c318c4859c3b2892fe97b621ab9819a 100644
--- a/cmake/modules/SwiftConfigureSDK.cmake
+++ b/cmake/modules/SwiftConfigureSDK.cmake
@@ -186,6 +186,16 @@ macro(configure_sdk_unix name architectures)
Expand All @@ -24,17 +24,16 @@ index 21e47a6e6382cc19ea192d388677ec3e6276bc86..eb113dd162b20fa63e8e3dce5daf5304
set(_swift_android_prebuilt_build "linux-x86_64")
endif()
- set(SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_PREBUILT_PATH
- "${SWIFT_ANDROID_NDK_PATH}/toolchains/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${_swift_android_prebuilt_build}")
+ if("${arch}" STREQUAL "i686")
+ set(SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_PREBUILT_PATH
+ "${SWIFT_ANDROID_NDK_PATH}/toolchains/x86-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${_swift_android_prebuilt_build}")
+ if("${arch}" STREQUAL "i686")
+ set(SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_PREBUILT_PATH
+ "${SWIFT_ANDROID_NDK_PATH}/toolchains/x86-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${_swift_android_prebuilt_build}")
+ elseif("${arch}" STREQUAL "x86_64")
+ set(SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_PREBUILT_PATH
+ "${SWIFT_ANDROID_NDK_PATH}/toolchains/x86_64-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${_swift_android_prebuilt_build}")
+ else()
+ set(SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_PREBUILT_PATH
+ "${SWIFT_ANDROID_NDK_PATH}/toolchains/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${_swift_android_prebuilt_build}")
+ endif()
+ set(SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_PREBUILT_PATH
+ "${SWIFT_ANDROID_NDK_PATH}/toolchains/x86_64-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${_swift_android_prebuilt_build}")
+ else()
+ set(SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_PREBUILT_PATH
"${SWIFT_ANDROID_NDK_PATH}/toolchains/${SWIFT_SDK_ANDROID_ARCH_${arch}_NDK_TRIPLE}-${SWIFT_ANDROID_NDK_GCC_VERSION}/prebuilt/${_swift_android_prebuilt_build}")
+ endif()
else()
if(NOT SWIFT_SDK_${prefix}_ARCH_${arch}_PATH)
set(SWIFT_SDK_${prefix}_ARCH_${arch}_PATH "/")
81 changes: 37 additions & 44 deletions Scripts/Builders/DispatchBuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,70 +35,63 @@ def initialize(arch = Arch.default)
@swift = SwiftBuilder.new()
if @arch == Arch.armv7a
@archPath = "armv7"
@includePath = "arm-linux-androideabi"
elsif @arch == Arch.x86
@archPath = "i686"
@includePath = "i686-linux-android"
elsif @arch == Arch.aarch64
@archPath = "aarch64"
@includePath = "aarch64-linux-android"
elsif @arch == Arch.x64
@archPath = "x86_64"
@includePath = "x86_64-linux-android"
end
end

def executeConfigure
# See: /swift/swift-corelibs-libdispatch/INSTALL.md
cmd = []
cmd << "cd #{@builds} &&"
cmd << "cmake -G Ninja" # --debug-output
cmd << "-DCMAKE_INSTALL_PREFIX=/"
# See why we need to use cmake toolchain in NDK v19 - https://gitlab.kitware.com/cmake/cmake/issues/18739
cmd << "-DCMAKE_TOOLCHAIN_FILE=#{@ndk.sources}/build/cmake/android.toolchain.cmake"
cmd << "-DANDROID_STL=c++_static"
cmd << "-DANDROID_TOOLCHAIN=clang"
cmd << "-DANDROID_PLATFORM=android-#{@ndk.api}"

if @arch == Arch.armv7a
cmd << "-DANDROID_ABI=armeabi-v7a"
abi = "armeabi-v7a"
elsif @arch == Arch.x86
cmd << "-DANDROID_ABI=x86"
abi = "x86"
elsif @arch == Arch.aarch64
cmd << "-DANDROID_ABI=arm64-v8a"
abi = "arm64-v8a"
elsif @arch == Arch.x64
cmd << "-DANDROID_ABI=x86_64"
abi = "x86_64"
end
cmd << "-DCMAKE_BUILD_TYPE=Release"
cmd << "-DENABLE_SWIFT=true"
cmd << "-DENABLE_TESTING=false"
cmd << "-DCMAKE_SWIFT_COMPILER=\"#{@swift.builds}/bin/swiftc\""
cmd << "-DCMAKE_PREFIX_PATH=\"#{@swift.builds}/lib/cmake/swift\""
cmd << @sources
execute cmd.join(" ")
fixNinjaBuild()
end

def fixNinjaBuild
if @arch == Arch.host
return
end
file = "#{@builds}/build.ninja"
message "Applying fix for #{file}"
execute "cp -vf #{file} #{file}.orig"
contents = File.readlines(file).join()
if !contents.include?('-tools-directory')
contents = contents.gsub('-use-ld=gold', "-use-ld=gold -L #{@swift.installs}/lib/swift/android/#{@archPath} -tools-directory #{@ndk.toolchain}/bin")
contents = contents.gsub('-module-link-name swiftDispatch', "-module-link-name swiftDispatch -Xcc -I#{@ndk.sources}/sysroot/usr/include -Xcc -I#{@ndk.sources}/sysroot/usr/include/#{@includePath}")
end
File.write(file, contents)
cmd = <<EOM
cd #{@builds} &&
cmake -G Ninja
# --debug-output
# See why we need to use cmake toolchain in NDK v19 - https://gitlab.kitware.com/cmake/cmake/issues/18739
-DCMAKE_TOOLCHAIN_FILE=#{@ndk.sources}/build/cmake/android.toolchain.cmake
-DANDROID_STL=c++_static
-DANDROID_TOOLCHAIN=clang
-DANDROID_PLATFORM=android-#{@ndk.api}
-DANDROID_ABI=#{abi}
-DSWIFT_ANDROID_NDK_PATH=#{@ndk.sources}
-DSWIFT_ANDROID_NDK_GCC_VERSION=#{@ndk.gcc}
-DSWIFT_ANDROID_API_LEVEL=#{@ndk.api}
-DCMAKE_BUILD_TYPE=Release
-DENABLE_SWIFT=true
-DENABLE_TESTING=false
-DCMAKE_SWIFT_COMPILER=\"#{@swift.builds}/bin/swiftc\"
-DCMAKE_PREFIX_PATH=\"#{@swift.builds}/lib/cmake/swift\"
-DCMAKE_INSTALL_PREFIX=/
#{@sources}
EOM
executeCommands cmd
end

def configurePatches(shouldEnable = true)
if @arch == Arch.host && shouldEnable
return
end
configurePatchFile("#{@patches}/CMakeLists.txt.diff", shouldEnable)
configurePatchFile("#{@patches}/src/CMakeLists.txt.diff", shouldEnable)
configurePatchFile("#{@patches}/cmake/modules/SwiftSupport.cmake.diff", shouldEnable)
configurePatchFile("#{@patches}/cmake/modules/DispatchCompilerWarnings.cmake.diff", shouldEnable)
end

def executeBuild
Expand All @@ -108,7 +101,7 @@ def executeBuild
def executeInstall
execute "DESTDIR=#{@installs} cmake --build #{@builds} --target install"
Dir["#{@installs}/lib/swift/android/*.so"].each { |file|
FileUtils.mv(file, "#{File.dirname(file)}/#{@archPath}", :force => true)
FileUtils.mv(file, "#{File.dirname(file)}/#{@archPath}", :force => true)
}
end

Expand Down
2 changes: 1 addition & 1 deletion Scripts/Builders/FoundationBuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def executeConfigure
cmd << "-DCMAKE_SWIFT_COMPILER=\"#{@swift.builds}/bin/swiftc\""

cmd << @sources
execute cmd.join(" ")
execute cmd.join(" \\\n")
end

def executeBuild
Expand Down
20 changes: 12 additions & 8 deletions Scripts/Common/Builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def clang
def configure()
logConfigureStarted()
prepare()
configurePatches(false)
configurePatches()
unpatch()
patch()
executeConfigure()
logConfigureCompleted()
end
Expand Down Expand Up @@ -116,6 +116,14 @@ def executeInstall()
# Base class does nothing
end

def patch()
configurePatches(true)
end

def unpatch()
configurePatches(false)
end

def configurePatches(shouldEnable = true)
# Base class does nothing
end
Expand Down Expand Up @@ -177,7 +185,7 @@ def prepare()
end

def clean
configurePatches(false)
unpatch()
removeBuilds()
cleanGitRepo()
end
Expand All @@ -186,7 +194,7 @@ def make
configure()
build()
install()
configurePatches(false)
unpatch()
end

def cleanGitRepo
Expand Down Expand Up @@ -231,10 +239,6 @@ def addFile(replacementFile, destinationFile, shouldApply = true)

def configurePatchFile(patchFile, shouldApply = true)
originalFile = patchFile.sub(@patches, @sources).sub('.diff', '')
configurePatch(originalFile, patchFile, shouldApply)
end

def configurePatch(originalFile, patchFile, shouldApply = true)
gitRepoRoot = "#{Config.sources}/#{@component}"
backupFile = "#{originalFile}.orig"
if shouldApply
Expand Down
15 changes: 7 additions & 8 deletions Scripts/Common/Revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,20 @@ class Revision
# See also: $ToolChain/Sources/swift/utils/update_checkout/update-checkout-config.json

def self.swift
# 5.1-master: 036e74a6a64438b8f8e5e1546f362ca7490ae233
# 5.0.1: e6047a2f5bccd6e00ee82d35e8e448426640099e
# v5.1 @ master: 036e74a6a64438b8f8e5e1546f362ca7490ae233
return "036e74a6a64438b8f8e5e1546f362ca7490ae233"
end

def self.dispatch
# 5.1-master: a18aa1f600361c1397b810a488a2e073f6f03985
# 5.0.1: 7e7677bcaff3dc19731ab2bf28e69adaa49bb654
return "a18aa1f600361c1397b810a488a2e073f6f03985"
# v5.1 @ master: e8d020e49cdb82513186e63989398db7b7aaefab
# v5.1 @ master: a18aa1f600361c1397b810a488a2e073f6f03985
return "e8d020e49cdb82513186e63989398db7b7aaefab"
end

def self.foundation
# 5.1-master: c5357f39dd15ae858dc72d15bbabe5435376db70
# 5.0.1: ebfbb38a35f02b2372e3e4973065506c3b5dd290
return "c5357f39dd15ae858dc72d15bbabe5435376db70"
# v5.1 @ master: 75fa8e0a0f4dd6d6570cfa51cd6d0901870c9162
# v5.1 @ master: c5357f39dd15ae858dc72d15bbabe5435376db70
return "75fa8e0a0f4dd6d6570cfa51cd6d0901870c9162"
end

def self.cmark
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.19
1.0.20

0 comments on commit bf1b9c3

Please sign in to comment.