From 1b43d4626747027599403c13ee4fed0bac5a255c Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Mon, 23 Oct 2023 15:08:19 -0700 Subject: [PATCH] build-llvm.py: Add '--build-targets' It can be useful to select subtargets, like 'clang' or 'llvm-ar', to build single tools when issues are isolated to them, which can reduce build time. This provides tangible benefits when bisecting, as an issue can be isolated down to a single commit in less time. As part of this implementation, the build target parameter is added as a member to LLVM_Builder and changed to a list to be more flexible and fit in more with how customizing the builder works in the rest of tc_build. Signed-off-by: Nathan Chancellor --- build-llvm.py | 18 ++++++++++++++++-- tc_build/llvm.py | 5 +++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/build-llvm.py b/build-llvm.py index c85af110..3f245e61 100755 --- a/build-llvm.py +++ b/build-llvm.py @@ -40,6 +40,17 @@ '''), type=str) +parser.add_argument('--build-targets', + default=['all'], + help=textwrap.dedent('''\ + By default, the 'all' target is used as the build target for the final stage. With + this option, targets such as 'distribution' could be used to generate a slimmer + toolchain or targets such as 'clang' or 'llvm-ar' could be used to just test building + individual tools for a bisect. + + NOTE: This only applies to the final stage build to avoid complicating tc-build internals. + '''), + nargs='+') parser.add_argument('--bolt', help=textwrap.dedent('''\ Optimize the final clang binary with BOLT (Binary Optimization and Layout Tool), which can @@ -526,6 +537,7 @@ tc_build.utils.print_header('Building LLVM (bootstrap)') bootstrap = LLVMBootstrapBuilder() + bootstrap.build_targets = ['distribution'] bootstrap.ccache = not args.no_ccache bootstrap.cmake_defines.update(common_cmake_defines) bootstrap.folders.build = Path(build_folder, 'bootstrap') @@ -540,7 +552,7 @@ bootstrap.check_dependencies() bootstrap.configure() - bootstrap.build('distribution') + bootstrap.build() # If the user did not specify CMAKE_C_FLAGS or CMAKE_CXX_FLAGS, add them as empty # to paste stage 2 to ensure there are no environment issues (since CFLAGS and CXXFLAGS @@ -558,6 +570,7 @@ instrumented = LLVMInstrumentedBuilder() else: instrumented = LLVMSlimInstrumentedBuilder() + instrumented.build_targets = ['all' if args.full_toolchain else 'distribution'] instrumented.cmake_defines.update(common_cmake_defines) # We run the tests on the instrumented stage if the LLVM benchmark was enabled instrumented.check_targets = args.check_targets if 'llvm' in args.pgo else None @@ -571,7 +584,7 @@ tc_build.utils.print_header('Building LLVM (instrumented)') instrumented.configure() - instrumented.build('all' if args.full_toolchain else 'distribution') + instrumented.build() tc_build.utils.print_header('Generating PGO profiles') pgo_builders = [] @@ -648,6 +661,7 @@ instrumented.generate_profdata() # Final build +final.build_targets = args.build_targets final.check_targets = args.check_targets final.cmake_defines.update(common_cmake_defines) final.folders.build = Path(build_folder, 'final') diff --git a/tc_build/llvm.py b/tc_build/llvm.py index 149bec27..e0f267e8 100644 --- a/tc_build/llvm.py +++ b/tc_build/llvm.py @@ -27,6 +27,7 @@ def __init__(self): self.bolt = False self.bolt_builder = None + self.build_targets = ['all'] self.ccache = False self.check_targets = [] # Removes system dependency on terminfo to keep the dynamic library @@ -133,7 +134,7 @@ def bolt_clang(self): if mode == 'instrumentation': clang_inst.unlink() - def build(self, build_target='all'): + def build(self): if not self.folders.build: raise RuntimeError('No build folder set for build()?') if not Path(self.folders.build, 'build.ninja').exists(): @@ -142,7 +143,7 @@ def build(self, build_target='all'): raise RuntimeError('BOLT requested without a builder?') build_start = time.time() - ninja_cmd = ['ninja', '-C', self.folders.build, build_target] + ninja_cmd = ['ninja', '-C', self.folders.build, *self.build_targets] self.run_cmd(ninja_cmd) if self.check_targets: