Skip to content

[build-script] Add option to build lld as part of LLVM #41314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -1833,16 +1833,8 @@ for host in "${ALL_HOSTS[@]}"; do
llvm_enable_projects+=("clang-tools-extra")
fi

# On non-Darwin platforms, build lld so we can always have a
# linker that is compatible with the swift we are using to
# compile the stdlib.
#
# This makes it easier to build target stdlibs on systems that
# have old toolchains without more modern linker features.
if [[ "$(uname -s)" != "Darwin" ]] ; then
if [[ ! "${SKIP_BUILD_LLD}" ]]; then
llvm_enable_projects+=("lld")
fi
if [[ ! "${SKIP_BUILD_LLD}" ]]; then
llvm_enable_projects+=("lld")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a build-script unit test that makes sure we don't break this by mistake? Then I think this LGTM. I am also fine if you want to merge this now and write the test in a subsequent PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by a build-script unit test? I don’t think I ever saw unit tests for build-script 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a unit test. @gottesmm Could you take another look?

fi

cmake_options+=(
Expand Down
3 changes: 3 additions & 0 deletions utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ def create_argument_parser():
option(['--build-libparser-only'], toggle_true('build_libparser_only'),
help='build only libParser for SwiftSyntax')

option(['--build-lld'], toggle_true('build_lld'),
help='build lld as part of llvm')

option('--skip-build-clang-tools-extra',
toggle_false('build_clang_tools_extra'),
default=True,
Expand Down
2 changes: 2 additions & 0 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
'build_lldb': False,
'build_libcxx': False,
'build_ninja': False,
'build_lld': False,
'build_osx': True,
'build_playgroundsupport': False,
'build_runtime_with_host_compiler': False,
Expand Down Expand Up @@ -531,6 +532,7 @@ class BuildScriptImplOption(_BaseOption):
EnableOption('--android'),
EnableOption('--build-external-benchmarks'),
EnableOption('--build-ninja'),
EnableOption('--build-lld'),
EnableOption('--build-runtime-with-host-compiler'),
EnableOption('--build-swift-dynamic-sdk-overlay'),
EnableOption('--build-swift-dynamic-stdlib'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,20 @@ def convert_to_impl_arguments(self):
"--llvm-install-components=%s" % args.llvm_install_components
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specifically.

]

# On non-Darwin platforms, build lld so we can always have a
# linker that is compatible with the swift we are using to
# compile the stdlib.
#
# This makes it easier to build target stdlibs on systems that
# have old toolchains without more modern linker features.
#
# On Darwin, only build lld if explicitly requested using --build-lld.
should_build_lld = (platform.system() != 'Darwin' or args.build_lld)
if not should_build_lld:
impl_args += [
"--skip-build-lld"
]

if not args.clean_libdispatch:
impl_args += [
"--skip-clean-libdispatch"
Expand Down
9 changes: 9 additions & 0 deletions validation-test/BuildSystem/build_lld.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# RUN: %empty-directory(%t)
# RUN: mkdir -p %t
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --build-lld 2>&1 | %FileCheck %s

# REQUIRES: standalone_build

# Check that lld is in LLVM_ENABLE_PROJECTS of the llvm-project/llvm build

# CHECK: '-DLLVM_ENABLE_PROJECTS={{[^']*}}lld{{[^']*}}'{{.*}}llvm-project/llvm{{$}}