Skip to content

Commit f68e23a

Browse files
authored
Merge pull request #79329 from gottesmm/pr-295dfc37ee8e5bf71b1249c2717a30c37de1aee2
[build-script] Add an option to force the linker used.
2 parents 2705212 + 3e2a6f6 commit f68e23a

File tree

6 files changed

+62
-2
lines changed

6 files changed

+62
-2
lines changed

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,12 @@ def create_argument_parser():
637637
'`bootstrapping-with-hostlibs`, `crosscompile`, and '
638638
'`crosscompile-with-hostlibs`')
639639

640+
option('--use-linker', store('use_linker'),
641+
choices=['gold', 'lld'],
642+
default=None,
643+
metavar='USE_LINKER',
644+
help='Choose the default linker to use when compiling LLVM/Swift')
645+
640646
# -------------------------------------------------------------------------
641647
in_group('Host and cross-compilation targets')
642648

utils/build_swift/tests/build_swift/test_driver_arguments.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,15 @@ def test_option_swift_compiler_version(self):
478478
with self.assertRaises(ParserError):
479479
self.parse_default_args([option_string, '0.0.0.1'])
480480

481+
def test_option_use_linker(self):
482+
option_string = '--use-linker'
483+
484+
self.parse_default_args([option_string, 'lld'])
485+
self.parse_default_args([option_string, 'gold'])
486+
487+
with self.assertRaises(ParserError):
488+
self.parse_default_args([option_string, 'foo'])
489+
481490
def test_option_swift_user_visible_version(self):
482491
option_string = '--swift-user-visible-version'
483492

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@
335335
'xros_all': False,
336336
'llvm_install_components': defaults.llvm_install_components(),
337337
'clean_install_destdir': False,
338+
'use_linker': None,
338339
}
339340

340341

@@ -891,4 +892,5 @@ class BuildScriptImplOption(_BaseOption):
891892
IgnoreOption('--xros-all'),
892893

893894
StrOption('--llvm-install-components'),
895+
ChoicesOption('--use-linker', dest='use_linker', choices=['gold', 'lld']),
894896
]

utils/swift_build_support/swift_build_support/products/llvm.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def __init__(self, args, toolchain, source_dir, build_dir):
4343
# Add the cmake options for compiler version information.
4444
self.cmake_options.extend(self._version_flags)
4545

46+
# Add linker flags if specified
47+
self.cmake_options.extend(self._use_linker)
48+
4649
@classmethod
4750
def is_build_script_impl_product(cls):
4851
"""is_build_script_impl_product -> bool
@@ -83,6 +86,12 @@ def _version_flags(self):
8386
"clang-{}".format(self.args.clang_compiler_version))
8487
return result
8588

89+
@property
90+
def _use_linker(self):
91+
if self.args.use_linker is None:
92+
return []
93+
return [('CLANG_DEFAULT_LINKER', self.args.use_linker)]
94+
8695
@classmethod
8796
def get_dependencies(cls):
8897
return [cmark.CMark]

utils/swift_build_support/tests/products/test_llvm.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def setUp(self):
4646
compiler_vendor='none',
4747
clang_compiler_version=None,
4848
clang_user_visible_version=None,
49-
darwin_deployment_version_osx='10.9')
49+
darwin_deployment_version_osx='10.9',
50+
use_linker=None)
5051

5152
# Setup shell
5253
shell.dry_run = True
@@ -154,3 +155,35 @@ def test_version_flags(self):
154155
'-DCLANG_REPOSITORY_STRING=clang-2.2.3',
155156
llvm.cmake_options
156157
)
158+
159+
def test_use_linker(self):
160+
self.args.use_linker = None
161+
llvm = LLVM(
162+
args=self.args,
163+
toolchain=self.toolchain,
164+
source_dir='/path/to/src',
165+
build_dir='/path/to/build')
166+
for s in llvm.cmake_options:
167+
self.assertFalse('CLANG_DEFAULT_LINKER' in s)
168+
169+
self.args.use_linker = 'gold'
170+
llvm = LLVM(
171+
args=self.args,
172+
toolchain=self.toolchain,
173+
source_dir='/path/to/src',
174+
build_dir='/path/to/build')
175+
self.assertIn(
176+
'-DCLANG_DEFAULT_LINKER=gold',
177+
llvm.cmake_options
178+
)
179+
180+
self.args.use_linker = 'lld'
181+
llvm = LLVM(
182+
args=self.args,
183+
toolchain=self.toolchain,
184+
source_dir='/path/to/src',
185+
build_dir='/path/to/build')
186+
self.assertIn(
187+
'-DCLANG_DEFAULT_LINKER=lld',
188+
llvm.cmake_options
189+
)

utils/swift_build_support/tests/products/test_llvm_linux_cross_compile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def setUp(self):
4040
clang_compiler_version=None,
4141
clang_user_visible_version=None,
4242
cross_compile_hosts='linux-aarch64',
43-
cross_compile_deps_path='sysroot'
43+
cross_compile_deps_path='sysroot',
44+
use_linker=None
4445
)
4546

4647
# Setup shell

0 commit comments

Comments
 (0)