From d232ba7a932028aadf50c1aeb004990a60e4abcc Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Thu, 26 Sep 2024 14:12:44 -0700 Subject: [PATCH] Build sourcekit-lsp for multiple arches and lipo them Instead of building SourceKit-LSP using SwiftPM's multi-arch xcbuild backend, build it for only one arch at a time and then run `lipo` to merge the two resulting binaries. This should allow us to share build products between building installing and testing and also eliminates other quirks resulting from the xcbuild backend. --- Utilities/build-script-helper.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/Utilities/build-script-helper.py b/Utilities/build-script-helper.py index 33b929a8f..0643006bb 100755 --- a/Utilities/build-script-helper.py +++ b/Utilities/build-script-helper.py @@ -70,22 +70,15 @@ def swiftpm_bin_path(swift_exec: str, swiftpm_args: List[str], additional_env: D def get_build_target(swift_exec: str, args: argparse.Namespace, cross_compile: bool = False) -> str: """Returns the target-triple of the current machine or for cross-compilation.""" - try: - command = [swift_exec, '-print-target-info'] - if cross_compile: - cross_compile_json = json.load(open(args.cross_compile_config)) - command += ['-target', cross_compile_json["target"]] - target_info_json = subprocess.check_output(command, stderr=subprocess.PIPE, universal_newlines=True).strip() - args.target_info = json.loads(target_info_json) - if '-apple-macosx' in args.target_info["target"]["unversionedTriple"]: - return args.target_info["target"]["unversionedTriple"] - return args.target_info["target"]["triple"] - except Exception as e: - # Temporary fallback for Darwin. - if platform.system() == 'Darwin': - return 'x86_64-apple-macosx' - else: - fatal_error(str(e)) + command = [swift_exec, '-print-target-info'] + if cross_compile: + cross_compile_json = json.load(open(args.cross_compile_config)) + command += ['-target', cross_compile_json["target"]] + target_info_json = subprocess.check_output(command, stderr=subprocess.PIPE, universal_newlines=True).strip() + args.target_info = json.loads(target_info_json) + if '-apple-macosx' in args.target_info["target"]["unversionedTriple"]: + return args.target_info["target"]["unversionedTriple"] + return args.target_info["target"]["triple"] # ----------------------------------------------------------------------------- # Build SourceKit-LSP @@ -144,7 +137,7 @@ def get_swiftpm_options(swift_exec: str, args: argparse.Namespace, suppress_verb if args.cross_compile_host: if build_os.startswith('macosx') and args.cross_compile_host.startswith('macosx-'): - swiftpm_args += ["--arch", "x86_64", "--arch", "arm64"] + swiftpm_args += ["--arch", args.cross_compile_host[7:]] elif args.cross_compile_host.startswith('android-'): print('Cross-compiling for %s' % args.cross_compile_host) swiftpm_args += ['--destination', args.cross_compile_config]