swift: fix on-device build

This commit is contained in:
Butta 2021-09-27 17:16:31 +05:30
parent a522f80f0f
commit ded7d319a1
6 changed files with 30 additions and 21 deletions

View File

@ -120,9 +120,11 @@ termux_step_pre_configure() {
patch -p1 < $TERMUX_PKG_BUILDER_DIR/../libllvm/clang-lib-Driver-ToolChains-Linux.cpp.patch patch -p1 < $TERMUX_PKG_BUILDER_DIR/../libllvm/clang-lib-Driver-ToolChains-Linux.cpp.patch
cd .. cd ..
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \ if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
$TERMUX_PKG_BUILDER_DIR/swiftpm-driver-lsp-termux-flags | \ sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
sed "s%\@CCTERMUX_HOST_PLATFORM\@%${CCTERMUX_HOST_PLATFORM}%g" | patch -p1 $TERMUX_PKG_BUILDER_DIR/swiftpm-driver-lsp-termux-flags | \
sed "s%\@CCTERMUX_HOST_PLATFORM\@%${CCTERMUX_HOST_PLATFORM}%g" | patch -p1
fi
} }
termux_step_make() { termux_step_make() {

View File

@ -10,7 +10,7 @@ index 58f8676..7fa6a46 100755
import shutil import shutil
import subprocess import subprocess
import sys import sys
@@ -50,25 +51,28 @@ def get_swiftpm_options(args): @@ -50,25 +51,29 @@ def get_swiftpm_options(args):
os.path.join(args.toolchain, 'lib', 'swift', 'Block'), os.path.join(args.toolchain, 'lib', 'swift', 'Block'),
] ]
@ -29,6 +29,7 @@ index 58f8676..7fa6a46 100755
+ if 'ANDROID_DATA' in os.environ or (args.cross_compile_host and re.match( + if 'ANDROID_DATA' in os.environ or (args.cross_compile_host and re.match(
+ 'android-', args.cross_compile_host)): + 'android-', args.cross_compile_host)):
+ swiftpm_args += [ + swiftpm_args += [
+ '-Xlinker', '-landroid-spawn',
+ '-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android', + '-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android',
+ # SwiftPM will otherwise try to compile against GNU strerror_r on + # SwiftPM will otherwise try to compile against GNU strerror_r on
+ # Android and fail. + # Android and fail.

View File

@ -16,20 +16,20 @@ index b7503ecdd6..c643c2c9a5 100644
# Only build libdispatch for the host if the host tools are being built and # Only build libdispatch for the host if the host tools are being built and
# specifically if these two libraries that depend on it are built. # specifically if these two libraries that depend on it are built.
- if(SWIFT_INCLUDE_TOOLS AND (SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT)) - if(SWIFT_INCLUDE_TOOLS AND (SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT))
+ if(NOT ${SWIFT_HOST_VARIANT_SDK} STREQUAL ANDROID AND SWIFT_INCLUDE_TOOLS AND (SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT)) + if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Android AND SWIFT_INCLUDE_TOOLS AND (SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT))
set(SWIFT_BUILD_HOST_DISPATCH TRUE) set(SWIFT_BUILD_HOST_DISPATCH TRUE)
endif() endif()
@@ -976,7 +976,8 @@ if (LLVM_ENABLE_DOXYGEN) @@ -976,7 +976,8 @@ if (LLVM_ENABLE_DOXYGEN)
message(STATUS "Doxygen: enabled")
endif() endif()
if(SWIFT_ENABLE_DISPATCH) -if(SWIFT_ENABLE_DISPATCH)
- include(Libdispatch) +# Use the Termux libdispatch when cross-compiling instead.
+# Use the Termux libdispatch instead. +if(SWIFT_ENABLE_DISPATCH AND ${CMAKE_HOST_SYSTEM_NAME} STREQUAL Android)
+# include(Libdispatch) include(Libdispatch)
endif() endif()
# Add all of the subdirectories, where we actually do work.
diff --git a/swift/localization/CMakeLists.txt b/swift/localization/CMakeLists.txt diff --git a/swift/localization/CMakeLists.txt b/swift/localization/CMakeLists.txt
index 07a3585a66c..461a98b6856 100644 index 07a3585a66c..461a98b6856 100644
--- a/swift/localization/CMakeLists.txt --- a/swift/localization/CMakeLists.txt

View File

@ -24,7 +24,7 @@ index e986475..83916c3 100755
if platform.system() == 'Darwin': if platform.system() == 'Darwin':
shared_lib_ext = '.dylib' shared_lib_ext = '.dylib'
@@ -96,7 +97,11 @@ def get_swiftpm_options(args): @@ -96,8 +97,13 @@ def get_swiftpm_options(args):
os.path.join(args.toolchain, 'lib', 'swift', 'Block'), os.path.join(args.toolchain, 'lib', 'swift', 'Block'),
] ]
@ -35,8 +35,10 @@ index e986475..83916c3 100755
+ if 'ANDROID_DATA' in os.environ or (args.cross_compile_hosts and re.match( + if 'ANDROID_DATA' in os.environ or (args.cross_compile_hosts and re.match(
+ 'android-', args.cross_compile_hosts[0])): + 'android-', args.cross_compile_hosts[0])):
swiftpm_args += [ swiftpm_args += [
+ '-Xlinker', '-landroid-spawn',
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android', '-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android',
# SwiftPM will otherwise try to compile against GNU strerror_r on # SwiftPM will otherwise try to compile against GNU strerror_r on
# Android and fail.
@@ -177,8 +185,13 @@ def handle_invocation(args): @@ -177,8 +185,13 @@ def handle_invocation(args):
if args.sysroot: if args.sysroot:
env['SDKROOT'] = args.sysroot env['SDKROOT'] = args.sysroot

View File

@ -77,3 +77,15 @@ index 78072f5b..fb78b54f 100644
// User arguments (from -Xlinker and -Xswiftc) should follow generated arguments to allow user overrides // User arguments (from -Xlinker and -Xswiftc) should follow generated arguments to allow user overrides
args += buildParameters.linkerFlags args += buildParameters.linkerFlags
args += stripInvalidArguments(buildParameters.swiftCompilerFlags) args += stripInvalidArguments(buildParameters.swiftCompilerFlags)
diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap
index 1f673fdd..e51616cb 100755
--- a/swiftpm/Utilities/bootstrap
+++ b/swiftpm/Utilities/bootstrap
@@ -800,6 +800,7 @@ def get_swiftpm_flags(args):
if 'ANDROID_DATA' in os.environ or (args.cross_compile_hosts and re.match(
'android-', args.cross_compile_hosts)):
build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
+ build_flags.extend(["-Xlinker", "-landroid-spawn"])
# On ELF platforms, remove the host toolchain's stdlib absolute rpath from
# installed executables and shared libraries.

View File

@ -5,7 +5,7 @@
if args.cross_compile_host: if args.cross_compile_host:
- swiftpm_args += ['--destination', args.cross_compile_config] - swiftpm_args += ['--destination', args.cross_compile_config]
+ swiftpm_args += ['--destination', args.cross_compile_config, '-Xcc', '-I@TERMUX_PREFIX@/include', '-Xswiftc', '-Xclang-linker', '-Xswiftc', '--target=@CCTERMUX_HOST_PLATFORM@', '-Xlinker', '-landroid-spawn', '-Xlinker', '-rpath', '-Xlinker', '@TERMUX_PREFIX@/lib'] + swiftpm_args += ['--destination', args.cross_compile_config, '-Xcc', '-I@TERMUX_PREFIX@/include', '-Xswiftc', '-Xclang-linker', '-Xswiftc', '--target=@CCTERMUX_HOST_PLATFORM@', '-Xlinker', '-rpath', '-Xlinker', '@TERMUX_PREFIX@/lib']
return swiftpm_args return swiftpm_args
@ -13,14 +13,6 @@ diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap
index 1f673fdd..e51616cb 100755 index 1f673fdd..e51616cb 100755
--- a/swiftpm/Utilities/bootstrap --- a/swiftpm/Utilities/bootstrap
+++ b/swiftpm/Utilities/bootstrap +++ b/swiftpm/Utilities/bootstrap
@@ -800,6 +800,7 @@ def get_swiftpm_flags(args):
if 'ANDROID_DATA' in os.environ or (args.cross_compile_hosts and re.match(
'android-', args.cross_compile_hosts)):
build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
+ build_flags.extend(["-Xlinker", "-landroid-spawn"])
# On ELF platforms, remove the host toolchain's stdlib absolute rpath from
# installed executables and shared libraries.
@@ -811,7 +812,7 @@ def get_swiftpm_flags(args): @@ -811,7 +812,7 @@ def get_swiftpm_flags(args):
if build_target == 'x86_64-apple-macosx' and "macosx-arm64" in cross_compile_hosts: if build_target == 'x86_64-apple-macosx' and "macosx-arm64" in cross_compile_hosts:
build_flags += ["--arch", "x86_64", "--arch", "arm64"] build_flags += ["--arch", "x86_64", "--arch", "arm64"]
@ -39,7 +31,7 @@ index 91a8d57..48bffd6 100755
if args.cross_compile_hosts: if args.cross_compile_hosts:
- swiftpm_args += [ '--destination', args.cross_compile_config ] - swiftpm_args += [ '--destination', args.cross_compile_config ]
+ swiftpm_args += [ '--destination', args.cross_compile_config, '-Xcc', '-I@TERMUX_PREFIX@/include', '-Xswiftc', '-Xclang-linker', '-Xswiftc', '--target=@CCTERMUX_HOST_PLATFORM@', '-Xlinker', '-landroid-spawn', '-Xlinker', '-rpath', '-Xlinker', '@TERMUX_PREFIX@/lib'] + swiftpm_args += [ '--destination', args.cross_compile_config, '-Xcc', '-I@TERMUX_PREFIX@/include', '-Xswiftc', '-Xclang-linker', '-Xswiftc', '--target=@CCTERMUX_HOST_PLATFORM@', '-Xlinker', '-rpath', '-Xlinker', '@TERMUX_PREFIX@/lib']
if 'ANDROID_DATA' in os.environ or (args.cross_compile_hosts and re.match( if 'ANDROID_DATA' in os.environ or (args.cross_compile_hosts and re.match(
'android-', args.cross_compile_hosts[0])): 'android-', args.cross_compile_hosts[0])):