Skip to content

Commit 9c992a7

Browse files
authored
Merge pull request #76730 from ahoppen/ahoppen/lsp-cross-compile
[build] Build sourcekit-lsp for multiple arches and lipo them
2 parents 9461af4 + 04e78e0 commit 9c992a7

File tree

2 files changed

+106
-73
lines changed

2 files changed

+106
-73
lines changed

utils/swift_build_support/swift_build_support/products/indexstoredb.py

Lines changed: 31 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from . import swiftsyntax
2727
from . import xctest
2828
from .. import shell
29-
from .. import targets
3029

3130

3231
class IndexStoreDB(product.Product):
@@ -50,14 +49,13 @@ def should_build(self, host_target):
5049
return True
5150

5251
def build(self, host_target):
53-
run_build_script_helper('build', host_target, self, self.args)
52+
self.run_build_script_helper('build', host_target)
5453

5554
def should_test(self, host_target):
5655
return self.args.test_indexstoredb
5756

5857
def test(self, host_target):
59-
run_build_script_helper('test', host_target, self, self.args,
60-
self.args.test_indexstoredb_sanitize_all)
58+
self.run_build_script_helper('test', host_target)
6159

6260
def should_install(self, host_target):
6361
return False
@@ -81,64 +79,32 @@ def get_dependencies(cls):
8179
swiftpm.SwiftPM,
8280
swiftsyntax.SwiftSyntax]
8381

84-
85-
def run_build_script_helper(action, host_target, product, args,
86-
sanitize_all=False, clean=False):
87-
script_path = os.path.join(
88-
product.source_dir, 'Utilities', 'build-script-helper.py')
89-
90-
install_destdir = product.host_install_destdir(host_target)
91-
toolchain_path = product.native_toolchain_path(host_target)
92-
is_release = product.is_release()
93-
configuration = 'release' if is_release else 'debug'
94-
helper_cmd = [
95-
script_path,
96-
action,
97-
'--package-path', product.source_dir,
98-
'--build-path', product.build_dir,
99-
'--configuration', configuration,
100-
'--toolchain', toolchain_path,
101-
'--ninja-bin', product.toolchain.ninja,
102-
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH,
103-
]
104-
if args.verbose_build:
105-
helper_cmd.append('--verbose')
106-
107-
if sanitize_all:
108-
helper_cmd.append('--sanitize-all')
109-
elif args.enable_asan:
110-
helper_cmd.extend(['--sanitize', 'address'])
111-
elif args.enable_ubsan:
112-
helper_cmd.extend(['--sanitize', 'undefined'])
113-
elif args.enable_tsan:
114-
helper_cmd.extend(['--sanitize', 'thread'])
115-
116-
if clean:
117-
helper_cmd.append('--clean')
118-
119-
# Pass Cross compile host info unless we're testing.
120-
# It doesn't make sense to run tests of the cross compile host.
121-
if product.has_cross_compile_hosts() and action != 'test':
122-
if product.is_darwin_host(host_target):
123-
if len(args.cross_compile_hosts) != 1:
124-
raise RuntimeError("Cross-Compiling indexstoredb to multiple " +
125-
"targets is not supported")
126-
helper_cmd += ['--cross-compile-host', args.cross_compile_hosts[0]]
127-
elif product.is_cross_compile_target(host_target):
128-
helper_cmd.extend(['--cross-compile-host', host_target])
129-
build_toolchain_path = install_destdir + args.install_prefix
130-
resource_dir = '%s/lib/swift' % build_toolchain_path
131-
helper_cmd += [
132-
'--cross-compile-config',
133-
targets.StdlibDeploymentTarget.get_target_for_name(host_target).platform
134-
.swiftpm_config(args, output_dir=build_toolchain_path,
135-
swift_toolchain=toolchain_path,
136-
resource_path=resource_dir)
137-
]
138-
139-
if action == 'install' and product.product_name() == "sourcekitlsp":
140-
helper_cmd.extend([
141-
'--prefix', install_destdir + args.install_prefix
142-
])
143-
144-
shell.call(helper_cmd)
82+
def run_build_script_helper(self, action, host_target):
83+
script_path = os.path.join(
84+
self.source_dir, 'Utilities', 'build-script-helper.py')
85+
86+
toolchain_path = self.native_toolchain_path(host_target)
87+
configuration = 'release' if self.is_release() else 'debug'
88+
helper_cmd = [
89+
script_path,
90+
action,
91+
'--package-path', self.source_dir,
92+
'--build-path', self.build_dir,
93+
'--configuration', configuration,
94+
'--toolchain', toolchain_path,
95+
'--ninja-bin', self.toolchain.ninja,
96+
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH,
97+
]
98+
if self.args.verbose_build:
99+
helper_cmd.append('--verbose')
100+
101+
if self.args.test_indexstoredb_sanitize_all:
102+
helper_cmd.append('--sanitize-all')
103+
elif self.args.enable_asan:
104+
helper_cmd.extend(['--sanitize', 'address'])
105+
elif self.args.enable_ubsan:
106+
helper_cmd.extend(['--sanitize', 'undefined'])
107+
elif self.args.enable_tsan:
108+
helper_cmd.extend(['--sanitize', 'thread'])
109+
110+
shell.call(helper_cmd)

utils/swift_build_support/swift_build_support/products/sourcekitlsp.py

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
#
1111
# ----------------------------------------------------------------------------
1212

13+
import os
14+
15+
from build_swift.build_swift.constants import MULTIROOT_DATA_FILE_PATH
16+
1317
from . import cmark
1418
from . import foundation
15-
from . import indexstoredb
1619
from . import libcxx
1720
from . import libdispatch
1821
from . import llbuild
@@ -21,6 +24,8 @@
2124
from . import swift
2225
from . import swiftpm
2326
from . import xctest
27+
from .. import shell
28+
from .. import targets
2429

2530

2631
class SourceKitLSP(product.Product):
@@ -43,24 +48,35 @@ def is_swiftpm_unified_build_product(cls):
4348
def should_build(self, host_target):
4449
return True
4550

51+
def _for_each_host_target(self, base_target, body):
52+
body(base_target)
53+
54+
# For Darwin host, 'build' is only called for the builder.
55+
# Manually iterate the cross compile hosts.
56+
if self.has_cross_compile_hosts() and self.is_darwin_host(base_target):
57+
for target in self.args.cross_compile_hosts:
58+
body(target)
59+
4660
def build(self, host_target):
47-
indexstoredb.run_build_script_helper(
48-
'build', host_target, self, self.args)
61+
self._for_each_host_target(
62+
host_target,
63+
lambda target: self.run_build_script_helper('build', host_target, target)
64+
)
4965

5066
def should_test(self, host_target):
5167
return self.args.test_sourcekitlsp
5268

5369
def test(self, host_target):
54-
indexstoredb.run_build_script_helper(
55-
'test', host_target, self, self.args,
56-
self.args.test_sourcekitlsp_sanitize_all)
70+
self.run_build_script_helper('test', host_target, host_target)
5771

5872
def should_install(self, host_target):
5973
return self.args.install_sourcekitlsp
6074

6175
def install(self, host_target):
62-
indexstoredb.run_build_script_helper(
63-
'install', host_target, self, self.args)
76+
self._for_each_host_target(
77+
host_target,
78+
lambda target: self.run_build_script_helper('install', host_target, target)
79+
)
6480

6581
@classmethod
6682
def get_dependencies(cls):
@@ -73,3 +89,54 @@ def get_dependencies(cls):
7389
xctest.XCTest,
7490
llbuild.LLBuild,
7591
swiftpm.SwiftPM]
92+
93+
def run_build_script_helper(self, action, base_target, host_target):
94+
# base_target is the machine that's driving the build.
95+
# host_target is the target we are bulding for.
96+
script_path = os.path.join(
97+
self.source_dir, 'Utilities', 'build-script-helper.py')
98+
99+
install_destdir = self.host_install_destdir(host_target)
100+
toolchain_path = self.native_toolchain_path(base_target)
101+
configuration = 'release' if self.is_release() else 'debug'
102+
helper_cmd = [
103+
script_path,
104+
action,
105+
'--package-path', self.source_dir,
106+
'--build-path', self.build_dir,
107+
'--configuration', configuration,
108+
'--toolchain', toolchain_path,
109+
'--ninja-bin', self.toolchain.ninja,
110+
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH,
111+
]
112+
if self.args.verbose_build:
113+
helper_cmd.append('--verbose')
114+
115+
if self.args.test_sourcekitlsp_sanitize_all:
116+
helper_cmd.append('--sanitize-all')
117+
elif self.args.enable_asan:
118+
helper_cmd += ['--sanitize', 'address']
119+
elif self.args.enable_ubsan:
120+
helper_cmd += ['--sanitize', 'undefined']
121+
elif self.args.enable_tsan:
122+
helper_cmd += ['--sanitize', 'thread']
123+
124+
if self.has_cross_compile_hosts():
125+
helper_cmd += ['--cross-compile-host', host_target]
126+
if self.is_cross_compile_target(host_target) and \
127+
not self.is_darwin_host(host_target):
128+
build_toolchain_path = install_destdir + self.args.install_prefix
129+
resource_dir = '%s/lib/swift' % build_toolchain_path
130+
helper_cmd += [
131+
'--cross-compile-config',
132+
targets.StdlibDeploymentTarget.get_target_for_name(host_target)
133+
.platform
134+
.swiftpm_config(self.args, output_dir=build_toolchain_path,
135+
swift_toolchain=toolchain_path,
136+
resource_path=resource_dir)
137+
]
138+
139+
if action == 'install':
140+
helper_cmd += ['--prefix', install_destdir + self.args.install_prefix]
141+
142+
shell.call(helper_cmd)

0 commit comments

Comments
 (0)