Skip to content

Commit c4052eb

Browse files
committed
Add a way to specify the number of build jobs
This change adds a '-j' option to the top-level build script. The computed defaults may not always be suitable. Tested by building for Ninja (default), Make (-m), and XCode (-x). I also verified the jobs count via a process monitor.
1 parent 4d1b6e2 commit c4052eb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

utils/build-script

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,13 @@ also build for Apple watchos, but disallow tests that require an watchOS device"
477477
name of the directory under $SWIFT_BUILD_ROOT where the build products will be
478478
placed""",
479479
metavar="PATH")
480+
481+
parser.add_argument("-j", "--jobs",
482+
help="""
483+
the number of parallel build jobs to use""",
484+
type=int,
485+
dest="build_jobs")
486+
480487
parser.add_argument("--extra-swift-args", help=textwrap.dedent("""
481488
Pass through extra flags to swift in the form of a cmake list 'module_regexp;flag'. Can
482489
be called multiple times to add multiple such module_regexp flag pairs. All semicolons
@@ -700,6 +707,8 @@ placed""",
700707
"--cmake-generator", args.cmake_generator,
701708
"--workspace", SWIFT_SOURCE_ROOT
702709
]
710+
if args.build_jobs:
711+
build_script_impl_args += ["--build-jobs", str(args.build_jobs)]
703712
if args.build_foundation:
704713
build_script_impl_args += [
705714
"--foundation-build-type", args.foundation_build_variant

utils/build-script-impl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ KNOWN_SETTINGS=(
182182
darwin-toolchain-application-cert "" "Application Cert name to codesign xctoolchain"
183183
darwin-toolchain-installer-cert "" "Installer Cert name to create installer pkg"
184184
darwin-toolchain-installer-package "" "The path to installer pkg"
185+
build-jobs "" "The number of parallel build jobs to use"
185186

186187
)
187188

@@ -1049,9 +1050,16 @@ case "${CMAKE_GENERATOR}" in
10491050
if [[ "${VERBOSE_BUILD}" ]] ; then
10501051
BUILD_ARGS="${BUILD_ARGS} -v"
10511052
fi
1053+
if [[ "${BUILD_JOBS}" ]] ; then
1054+
BUILD_ARGS="${BUILD_ARGS} -j${BUILD_JOBS}"
1055+
fi
10521056
;;
10531057
'Unix Makefiles')
1054-
BUILD_ARGS="${BUILD_ARGS:--j$(get_make_parallelism)}"
1058+
if [[ "${BUILD_JOBS}" ]] ; then
1059+
BUILD_ARGS="${BUILD_ARGS} -j${BUILD_JOBS}"
1060+
else
1061+
BUILD_ARGS="${BUILD_ARGS:--j$(get_make_parallelism)}"
1062+
fi
10551063
if [[ "${VERBOSE_BUILD}" ]] ; then
10561064
BUILD_ARGS="${BUILD_ARGS} VERBOSE=1"
10571065
fi
@@ -1061,6 +1069,9 @@ case "${CMAKE_GENERATOR}" in
10611069
# but since we're not using proper Xcode 4 schemes, this is the
10621070
# only way to get target-level parallelism.
10631071
BUILD_ARGS="${BUILD_ARGS} -parallelizeTargets"
1072+
if [[ "${BUILD_JOBS}" ]] ; then
1073+
BUILD_ARGS="${BUILD_ARGS} -jobs ${BUILD_JOBS}"
1074+
fi
10641075
BUILD_TARGET_FLAG="-target"
10651076
COMMON_CMAKE_OPTIONS=(
10661077
"${COMMON_CMAKE_OPTIONS[@]}"

0 commit comments

Comments
 (0)