termux-packages/packages/swift/swiftpm-Utilities-bootstrap

72 lines
3.7 KiB
Plaintext

diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap
index f7439427..5f284c48 100755
--- a/swiftpm/Utilities/bootstrap
+++ b/swiftpm/Utilities/bootstrap
@@ -167,7 +167,7 @@ def parse_build_args(args):
args.clang_path = get_clang_path(args)
args.cmake_path = get_cmake_path(args)
args.ninja_path = get_ninja_path(args)
- if args.cross_compile_hosts: # Use XCBuild target directory when building for multiple arches.
+ if args.cross_compile_hosts and "macosx-arm64" in args.cross_compile_hosts: # Use XCBuild target directory when building for multiple arches.
args.target_dir = os.path.join(args.build_dir, "apple/Products")
else:
args.target_dir = os.path.join(args.build_dir, get_build_target(args))
@@ -232,7 +232,7 @@ def get_ninja_path(args):
def get_build_target(args):
"""Returns the target-triple of the current machine."""
try:
- target_info_json = subprocess.check_output([args.swiftc_path, '-print-target-info'], stderr=subprocess.PIPE, universal_newlines=True).strip()
+ target_info_json = subprocess.check_output([args.swiftc_path, '-print-target-info', '-target', '@SWIFT_ARCH@-unknown-linux-android'], stderr=subprocess.PIPE, universal_newlines=True).strip()
args.target_info = json.loads(target_info_json)
return args.target_info["target"]["unversionedTriple"]
except Exception as e:
@@ -366,7 +368,13 @@ def build_with_cmake(args, cmake_args, source_path, build_dir):
"""Runs CMake if needed, then builds with Ninja."""
cache_path = os.path.join(build_dir, "CMakeCache.txt")
if args.reconfigure or not os.path.isfile(cache_path) or not args.swiftc_path in open(cache_path).read():
- swift_flags = ""
+ if args.cross_compile_hosts:
+ # The termux prefix flag is needed because the Swift flags pass the
+ # standalone toolchain as the sdk, ie the sysroot.
+ swift_flags = os.getenv("TERMUX_SWIFTPM_FLAGS") + " -resource-dir @TERMUX_PREFIX@/lib/swift -Xcc -I@TERMUX_PREFIX@/include"
+ else:
+ swift_flags = ""
+
if args.sysroot:
swift_flags = "-sdk %s" % args.sysroot
@@ -461,6 +463,9 @@ def build_swiftpm_with_cmake(args):
]
else:
cmake_flags = [ "-DFIND_PM_DEPS:BOOL=NO" ]
+ if "android-@SWIFT_ARCH@" in args.cross_compile_hosts:
+ cmake_flags.append("-DCMAKE_SYSTEM_NAME=Android")
+ cmake_flags.append("-DCMAKE_SYSTEM_VERSION=1")
if platform.system() == 'Darwin':
cmake_flags.append("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target(args), g_macos_deployment_target))
@@ -622,8 +631,8 @@ def get_swiftpm_flags(args):
)
# Don't use GNU strerror_r on Android.
- if 'ANDROID_DATA' in os.environ:
- build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
+ 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.
@@ -634,6 +643,12 @@ def get_swiftpm_flags(args):
cross_compile_hosts = args.cross_compile_hosts
if build_target == 'x86_64-apple-macosx' and "macosx-arm64" in cross_compile_hosts:
build_flags += ["--arch", "x86_64", "--arch", "arm64"]
+ elif "android-@SWIFT_ARCH@" in cross_compile_hosts:
+ build_flags.extend([
+ "--destination", "@TERMUX_PKG_BUILDDIR@/swiftpm-android-flags.json",
+ "-Xlinker", "-rpath", "-Xlinker", "@TERMUX_PREFIX@/lib",
+ "-Xcc", "-I@TERMUX_PREFIX@/include",
+ ])
elif cross_compile_hosts:
error("cannot cross-compile for %s" % cross_compile_hosts)