Skip to content

Commit 73b2a4a

Browse files
committed
[bootstrap] Add support for cross compile hosts flag
1 parent d23bd4b commit 73b2a4a

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Utilities/bootstrap

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ def add_build_args(parser):
130130
help="paths (relative to the project root) where to install build products [%(default)s]",
131131
default=["/tmp/swiftpm"],
132132
metavar="PATHS")
133+
parser.add_argument(
134+
"--cross-compile-hosts",
135+
dest="cross_compile_hosts",
136+
help="List of cross compile hosts targets.",
137+
default=[])
133138

134139
def add_test_args(parser):
135140
"""Configures the parser with the arguments necessary for the test action."""
@@ -182,7 +187,7 @@ def parse_build_args(args):
182187
args.clang_path = get_clang_path(args)
183188
args.cmake_path = get_cmake_path(args)
184189
args.ninja_path = get_ninja_path(args)
185-
if os.getenv("CROSS_COMPILE_HOSTS"): # Use XCBuild target directory when building for multiple arches.
190+
if args.cross_compile_hosts: # Use XCBuild target directory when building for multiple arches.
186191
args.target_dir = os.path.join(args.build_dir, "apple/Products")
187192
else:
188193
args.target_dir = os.path.join(args.build_dir, get_build_target(args))
@@ -356,7 +361,7 @@ def install(args):
356361
# Install the swiftmodule and swiftdoc files.
357362
for module in libswiftpm_modules:
358363
install_binary(args, module + ".swiftmodule", dest)
359-
if not os.getenv("CROSS_COMPILE_HOSTS"): # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
364+
if not args.cross_compile_hosts: # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
360365
install_binary(args, module + ".swiftdoc", dest)
361366

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

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

571576
build_target = get_build_target(args)
572-
cross_compile_host = os.getenv("CROSS_COMPILE_HOSTS")
573-
if build_target == 'x86_64-apple-macosx' and cross_compile_host == "macosx-arm64":
577+
cross_compile_hosts = args.cross_compile_hosts
578+
if build_target == 'x86_64-apple-macosx' and "macosx-arm64" in cross_compile_hosts:
574579
swiftpm_args += ["--arch", "x86_64", "--arch", "arm64"]
575-
elif cross_compile_host:
576-
error("cannot cross-compile for %s" % cross_compile_host)
580+
elif cross_compile_hosts:
581+
error("cannot cross-compile for %s" % cross_compile_hosts)
577582

578583
call_swiftpm(args, swiftpm_args)
579584

0 commit comments

Comments
 (0)