Skip to content

Commit 37dc138

Browse files
committed
[build-script] Cross-compile sourcekit-lsp for arm64
Currently, when building an open source toolchain, SourceKit-LSP is only built for x86_64. Copy the cross-compilation config from swiftpm.py to also produce a fat sourcekit-lsp executable for both x86_64 and arm64. rdar://78039145
1 parent b36cbed commit 37dc138

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

utils/swift_build_support/swift_build_support/products/indexstoredb.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,24 @@ def run_build_script_helper(action, host_target, product, args,
108108
if not clean:
109109
helper_cmd.append('--no-clean')
110110

111-
if not product.is_darwin_host(
112-
host_target) and product.is_cross_compile_target(host_target):
113-
helper_cmd.extend(['--cross-compile-host', host_target])
114-
build_toolchain_path = install_destdir + args.install_prefix
115-
resource_dir = '%s/lib/swift' % build_toolchain_path
116-
helper_cmd += [
117-
'--cross-compile-config',
118-
targets.StdlibDeploymentTarget.get_target_for_name(host_target).platform
119-
.swiftpm_config(args, output_dir=build_toolchain_path,
120-
swift_toolchain=toolchain_path,
121-
resource_path=resource_dir)
122-
]
111+
# Pass Cross compile host info
112+
if product.has_cross_compile_hosts():
113+
if product.is_darwin_host(host_target):
114+
if len(args.cross_compile_hosts) != 1:
115+
raise RuntimeError("Cross-Compiling indexstoredb to multiple " +
116+
"targets is not supported")
117+
helper_cmd += ['--cross-compile-host', args.cross_compile_hosts[0]]
118+
elif product.is_cross_compile_target(host_target):
119+
helper_cmd.extend(['--cross-compile-host', host_target])
120+
build_toolchain_path = install_destdir + args.install_prefix
121+
resource_dir = '%s/lib/swift' % build_toolchain_path
122+
helper_cmd += [
123+
'--cross-compile-config',
124+
targets.StdlibDeploymentTarget.get_target_for_name(host_target).platform
125+
.swiftpm_config(args, output_dir=build_toolchain_path,
126+
swift_toolchain=toolchain_path,
127+
resource_path=resource_dir)
128+
]
123129

124130
if action == 'install' and product.product_name() == "sourcekitlsp":
125131
helper_cmd.extend([

utils/swift_build_support/swift_build_support/products/product.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ def is_cross_compile_target(self, host_target):
244244
return self.args.cross_compile_hosts and \
245245
host_target in self.args.cross_compile_hosts
246246

247+
def has_cross_compile_hosts(self):
248+
return self.args.cross_compile_hosts
249+
247250
def generate_darwin_toolchain_file(self, platform, arch):
248251
shell.makedirs(self.build_dir)
249252
toolchain_file = os.path.join(self.build_dir, 'BuildScriptToolchain.cmake')

utils/swift_build_support/swift_build_support/products/swiftdriver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from . import llvm
2222
from . import product
2323
from . import swift
24-
from . import swiftpm
2524
from . import xctest
2625
from .. import shell
2726
from .. import targets
@@ -128,7 +127,7 @@ def run_build_script_helper(action, host_target, product, args):
128127
'--lit-test-dir', lit_test_dir
129128
]
130129
# Pass Cross compile host info
131-
if swiftpm.SwiftPM.has_cross_compile_hosts(args):
130+
if product.has_cross_compile_hosts():
132131
if product.is_darwin_host(host_target):
133132
helper_cmd += ['--cross-compile-hosts']
134133
for cross_compile_host in args.cross_compile_hosts:

utils/swift_build_support/swift_build_support/products/swiftpm.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def run_bootstrap_script(self, action, host_target, additional_params=[]):
9393
]
9494

9595
# Pass Cross compile host info
96-
if self.has_cross_compile_hosts(self.args):
96+
if self.has_cross_compile_hosts():
9797
if self.is_darwin_host(host_target):
9898
helper_cmd += ['--cross-compile-hosts']
9999
for cross_compile_host in self.args.cross_compile_hosts:
@@ -133,10 +133,6 @@ def clean(self, host_target):
133133
def should_install(self, host_target):
134134
return self.args.install_swiftpm
135135

136-
@classmethod
137-
def has_cross_compile_hosts(self, args):
138-
return args.cross_compile_hosts
139-
140136
def install(self, host_target):
141137
install_destdir = self.host_install_destdir(host_target)
142138
install_prefix = install_destdir + self.args.install_prefix

0 commit comments

Comments
 (0)