Skip to content

[bootstrap] Add support for cross compile hosts flag #2902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Utilities/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ def add_build_args(parser):
help="paths (relative to the project root) where to install build products [%(default)s]",
default=["/tmp/swiftpm"],
metavar="PATHS")
parser.add_argument(
"--cross-compile-hosts",
dest="cross_compile_hosts",
help="List of cross compile hosts targets.",
default=[])

def add_test_args(parser):
"""Configures the parser with the arguments necessary for the test action."""
Expand Down Expand Up @@ -182,7 +187,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 os.getenv("CROSS_COMPILE_HOSTS"): # Use XCBuild target directory when building for multiple arches.
if 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))
Expand Down Expand Up @@ -356,7 +361,7 @@ def install(args):
# Install the swiftmodule and swiftdoc files.
for module in libswiftpm_modules:
install_binary(args, module + ".swiftmodule", dest)
if not os.getenv("CROSS_COMPILE_HOSTS"): # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
if not args.cross_compile_hosts: # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
install_binary(args, module + ".swiftdoc", dest)

# Install the C headers.
Expand Down Expand Up @@ -403,7 +408,7 @@ def install_binary(args, binary, dest_dir):
note("Installing %s to %s" % (src, dest))

mkdir_p(os.path.dirname(dest))
if os.path.isdir(src) and os.getenv("CROSS_COMPILE_HOSTS"): # Handle swiftmodule directories if compiling for multiple arches.
if os.path.isdir(src) and args.cross_compile_hosts: # Handle swiftmodule directories if compiling for multiple arches.
dir_util.copy_tree(src, dest)
else:
file_util.copy_file(src, dest, update=1)
Expand Down Expand Up @@ -569,11 +574,11 @@ def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
swiftpm_args.append("--use-integrated-swift-driver")

build_target = get_build_target(args)
cross_compile_host = os.getenv("CROSS_COMPILE_HOSTS")
if build_target == 'x86_64-apple-macosx' and cross_compile_host == "macosx-arm64":
cross_compile_hosts = args.cross_compile_hosts
if build_target == 'x86_64-apple-macosx' and "macosx-arm64" in cross_compile_hosts:
swiftpm_args += ["--arch", "x86_64", "--arch", "arm64"]
elif cross_compile_host:
error("cannot cross-compile for %s" % cross_compile_host)
elif cross_compile_hosts:
error("cannot cross-compile for %s" % cross_compile_hosts)

call_swiftpm(args, swiftpm_args)

Expand Down