Skip to content

Commit

Permalink
Merge pull request #247 from nathanchance/build-targets
Browse files Browse the repository at this point in the history
build-llvm.py: Add '--build-targets'
  • Loading branch information
nathanchance authored Oct 24, 2023
2 parents c22cfcd + 1b43d46 commit 14cce14
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
18 changes: 16 additions & 2 deletions build-llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 = []
Expand Down Expand Up @@ -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')
Expand Down
5 changes: 3 additions & 2 deletions tc_build/llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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:
Expand Down

0 comments on commit 14cce14

Please sign in to comment.