Skip to content

Commit 498d4f7

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 498d4f7

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

utils/swift_build_support/swift_build_support/products/indexstoredb.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def should_install(self, host_target):
6060
def install(self, host_target):
6161
pass
6262

63+
def supports_cross_compilation(self):
64+
"""
65+
Whether the product can be built for a different architecture than the
66+
host by passing --cross-compile-host to it.
67+
"""
68+
return False
69+
6370
@classmethod
6471
def get_dependencies(cls):
6572
return [cmark.CMark,
@@ -108,18 +115,24 @@ def run_build_script_helper(action, host_target, product, args,
108115
if not clean:
109116
helper_cmd.append('--no-clean')
110117

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-
]
118+
# Pass Cross compile host info
119+
if product.supports_cross_compilation() and product.has_cross_compile_hosts():
120+
if product.is_darwin_host(host_target):
121+
if len(args.cross_compile_hosts) != 1:
122+
raise RuntimeError("Cross-Compiling indexstoredb to multiple " +
123+
"targets is not supported")
124+
helper_cmd += ['--cross-compile-host', args.cross_compile_hosts[0]]
125+
elif product.is_cross_compile_target(host_target):
126+
helper_cmd.extend(['--cross-compile-host', host_target])
127+
build_toolchain_path = install_destdir + args.install_prefix
128+
resource_dir = '%s/lib/swift' % build_toolchain_path
129+
helper_cmd += [
130+
'--cross-compile-config',
131+
targets.StdlibDeploymentTarget.get_target_for_name(host_target).platform
132+
.swiftpm_config(args, output_dir=build_toolchain_path,
133+
swift_toolchain=toolchain_path,
134+
resource_path=resource_dir)
135+
]
123136

124137
if action == 'install' and product.product_name() == "sourcekitlsp":
125138
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/sourcekitlsp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def install(self, host_target):
5959
indexstoredb.run_build_script_helper(
6060
'install', host_target, self, self.args, clean=False)
6161

62+
def supports_cross_compilation(self):
63+
return True
64+
6265
@classmethod
6366
def get_dependencies(cls):
6467
return [cmark.CMark,

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)