Skip to content

Commit 907f73d

Browse files
committed
[build-script] Refactor computation of the flags for disabling LLVM tools to its on function.
1 parent 88da17f commit 907f73d

File tree

1 file changed

+83
-71
lines changed

1 file changed

+83
-71
lines changed

utils/build-script-impl

Lines changed: 83 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,83 @@ function is_swift_lto_enabled() {
315315
fi
316316
}
317317

318+
# Compute the cmake flags related to disabling llvm tools as a result of our
319+
# needs for testing LLVM/Swift.
320+
function compute_cmake_llvm_tool_disable_flags() {
321+
if [[ $(false_true "${LLVM_INCLUDE_TESTS}") == "FALSE" ]]; then
322+
return
323+
fi
324+
325+
local OUTPUT=()
326+
local EXTRA_LLVM_CMAKE_OPTIONS=(
327+
# Do not include LLVM tests.
328+
-DLLVM_INCLUDE_TESTS:BOOL=NO
329+
-DCLANG_INCLUDE_TESTS:BOOL=NO
330+
)
331+
332+
# Disable LLVM Tools that Swift does not use for testing.
333+
local LLVM_TOOLS_TO_DISABLE=(
334+
BUGPOINT BUGPOINT_PASSES GOLD LLI LLVM_AS_FUZZER LLVM_C_TEST
335+
LLVM_CXXDUMP LLVM_DIFF LLVM_DIS LLVM_DWP LLVM_EXTRACT LLVM_GO
336+
LLVM_JITLISTENER LLVM_LTO LLVM_MC LLVM_MC_FUZZER LLVM_MCMARKUP
337+
LLVM_PDBDUMP LLVM_READOBJ LLVM_RTDYLD LLVM_SHLIB LLVM_SIZE LLVM_SPLIT
338+
LLVM_STRESS LLVM_SYMBOLIZER MSBUILD OBJ2YAML OPT SANCOV SANSTATS
339+
VERIFY_USELISTORDER XCODE_TOOLCHAIN YAML2OBJ
340+
)
341+
342+
# Disable Clang Tools that Swift does not use for testing.
343+
local CLANG_TOOLS_TO_DISABLE=(
344+
CLANG_CHECK DIAGTOOL SCAN_BUILD SCAN_VIEW CLANG_FORMAT
345+
)
346+
347+
# If in addition we are asked to not generate targets for swift tests,
348+
# then we can disable the building of even more of LLVM.
349+
if [[ $(false_true "${SWIFT_INCLUDE_TESTS}") == "TRUE" ]]; then
350+
EXTRA_LLVM_CMAKE_OPTIONS+=(
351+
# We do not need gtest/FileCheck and friends since we are not
352+
# running any tests.
353+
-DLLVM_INCLUDE_UTILS:BOOL=NO
354+
)
355+
356+
# Disable the rest of the LLVM tools. We do not need any of them.
357+
LLVM_TOOLS_TO_DISABLE+=(
358+
DSYMUTIL LLC LLVM_AR LLVM_AS LLVM_BCANALYZER LLVM_COV
359+
LLVM_DWARFDUMP LLVM_LINK LLVM_NM LLVM_OBJDUMP LLVM_PROFDATA
360+
)
361+
362+
# Disable the rest of the Clang tools. We do not need them.
363+
CLANG_TOOLS_TO_DISABLE+=(
364+
ARCMT_TEST C_ARCMT_TEST C_INDEX_TEST
365+
)
366+
367+
# If in addition, we are not building compiler-rt, then we do not
368+
# even need to build clang.
369+
#
370+
# *NOTE* This may change once we start building the standard library
371+
# *with the just built clang.
372+
if [[ $(true_false "${SKIP_BUILD_COMPILER_RT}") == "TRUE" ]]; then
373+
CLANG_TOOLS_TO_DISABLE+=(
374+
DRIVER
375+
)
376+
fi
377+
fi
378+
379+
for arg in "${EXTRA_LLVM_CMAKE_ARGS[@]}"; do
380+
OUTPUT+=( ${arg} )
381+
done
382+
for tool in "${LLVM_TOOLS_TO_DISABLE[@]}"; do
383+
OUTPUT+=(
384+
-DLLVM_TOOL_${tool}_BUILD:BOOL=NO
385+
)
386+
done
387+
for tool in "${CLANG_TOOLS_TO_DISABLE[@]}"; do
388+
OUTPUT+=(
389+
-DCLANG_TOOL_${tool}_BUILD:BOOL=NO
390+
)
391+
done
392+
echo "${OUTPUT[@]}"
393+
}
394+
318395
# Support for performing isolated actions.
319396
#
320397
# This is part of refactoring more work to be done or controllable via
@@ -669,80 +746,15 @@ function set_build_options_for_host() {
669746
-DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
670747
)
671748

672-
# If we are asked to not generate test targets LLVM, do not generate targets
673-
# for LLVM tools that are used to test LLVM, but are not used to test Swift.
749+
# If we are asked to not generate test targets for LLVM and or Swift,
750+
# disable as many LLVM tools as we can. This improves compile time when
751+
# compiling with LTO.
674752
#
675753
# *NOTE* Currently we do not support testing LLVM via build-script. But in a
676754
# future commit we will.
677-
if [[ $(false_true "${LLVM_INCLUDE_TESTS}") == "TRUE" ]]; then
678-
EXTRA_LLVM_CMAKE_OPTIONS=(
679-
# Do not include LLVM tests.
680-
-DLLVM_INCLUDE_TESTS:BOOL=NO
681-
-DCLANG_INCLUDE_TESTS:BOOL=NO
682-
)
683-
684-
# Disable LLVM Tools that Swift does not use for testing.
685-
LLVM_TOOLS_TO_DISABLE=(
686-
BUGPOINT BUGPOINT_PASSES GOLD LLI LLVM_AS_FUZZER LLVM_C_TEST
687-
LLVM_CXXDUMP LLVM_DIFF LLVM_DIS LLVM_DWP LLVM_EXTRACT LLVM_GO
688-
LLVM_JITLISTENER LLVM_LTO LLVM_MC LLVM_MC_FUZZER LLVM_MCMARKUP
689-
LLVM_PDBDUMP LLVM_READOBJ LLVM_RTDYLD LLVM_SHLIB LLVM_SIZE LLVM_SPLIT
690-
LLVM_STRESS LLVM_SYMBOLIZER MSBUILD OBJ2YAML OPT SANCOV SANSTATS
691-
VERIFY_USELISTORDER XCODE_TOOLCHAIN YAML2OBJ
692-
)
693-
694-
# Disable Clang Tools that Swift does not use for testing.
695-
CLANG_TOOLS_TO_DISABLE=(
696-
CLANG_CHECK DIAGTOOL SCAN_BUILD SCAN_VIEW CLANG_FORMAT
697-
)
698-
699-
# If in addition we are asked to not generate targets for swift tests,
700-
# then we can disable the building of even more of LLVM.
701-
if [[ $(false_true "${SWIFT_INCLUDE_TESTS}") == "TRUE" ]]; then
702-
EXTRA_LLVM_CMAKE_OPTIONS+=(
703-
# We do not need gtest/FileCheck and friends since we are not
704-
# running any tests.
705-
-DLLVM_INCLUDE_UTILS:BOOL=NO
706-
)
707-
708-
# Disable the rest of the LLVM tools. We do not need any of them.
709-
LLVM_TOOLS_TO_DISABLE+=(
710-
DSYMUTIL LLC LLVM_AR LLVM_AS LLVM_BCANALYZER LLVM_COV
711-
LLVM_DWARFDUMP LLVM_LINK LLVM_NM LLVM_OBJDUMP LLVM_PROFDATA
712-
)
713-
714-
# Disable the rest of the Clang tools. We do not need them.
715-
CLANG_TOOLS_TO_DISABLE+=(
716-
ARCMT_TEST C_ARCMT_TEST C_INDEX_TEST
717-
)
718-
719-
# If in addition, we are not building compiler-rt, then we do not
720-
# even need to build clang.
721-
#
722-
# *NOTE* This may change once we start building the standard library
723-
# *with the just built clang.
724-
if [[ $(true_false "${SKIP_BUILD_COMPILER_RT}") == "TRUE" ]]; then
725-
CLANG_TOOLS_TO_DISABLE+=(
726-
DRIVER
727-
)
728-
fi
729-
fi
730-
731-
for arg in "${EXTRA_LLVM_CMAKE_ARGS[@]}"; do
732-
llvm_cmake_options+=( "${arg}" )
733-
done
734-
for tool in "${LLVM_TOOLS_TO_DISABLE[@]}"; do
735-
llvm_cmake_options+=(
736-
-DLLVM_TOOL_${tool}_BUILD:BOOL=NO
737-
)
738-
done
739-
740-
for tool in "${CLANG_TOOLS_TO_DISABLE[@]}"; do
741-
llvm_cmake_options+=(
742-
-DCLANG_TOOL_${tool}_BUILD:BOOL=NO
743-
)
744-
done
745-
fi
755+
for arg in "$(compute_cmake_llvm_tool_disable_flags)"; do
756+
llvm_cmake_options+=( ${arg} )
757+
done
746758

747759
if [[ "${llvm_target_arch}" ]] ; then
748760
llvm_cmake_options+=(

0 commit comments

Comments
 (0)