[build-script] Add a flag for sccache

This adds a flag to enable sccache in order to simplify the build-script
invocation, particularly for new contributors.
This commit is contained in:
Cassie Jones
2020-09-30 16:49:34 -04:00
parent 327f4f8806
commit e01893cb56
10 changed files with 41 additions and 12 deletions

View File

@@ -112,6 +112,8 @@ following (non-exhaustive) set of useful options::
- ``--test``: Test the toolchain after it has been compiled. This is off by default.
- ``--distcc``: Use distcc to speed up the build by distributing the c++ part of
the swift build. This is off by default.
- ``--sccache``: Use sccache to speed up subsequent builds of the compiler by
caching more c++ build artifacts. This is off by default.
More options may be added over time. Please pass ``--help`` to
``build-toolchain`` to see the full set of options.

View File

@@ -33,9 +33,11 @@ Compilation times for the compiler and the standard library can be agonizing, es
```
$ brew install sccache
$ sccache --start-server
$ ./swift/utils/build-script MY_ARGS --cmake-c-launcher $(which sccache) --cmake-cxx-launcher $(which sccache)
$ ./swift/utils/build-script MY_ARGS --sccache
```
If you want to always use sccache, you can `export USE_SCCACHE=1` and the build script will pick it up.
Given the size of artifacts generated, you might also want to bump the cache size from the default 10GB to something larger, say by putting `export SCCACHE_CACHE_SIZE="50G"` in your dotfile(s).
You can run some compiles to see if it is actually doing something by running `sccache --show-stats`. Depending on the exact compilation task you're running, you might see very different cache hit rates. For example, `sccache` is particularly effective if you're rebuilding LLVM, which doesn't change so frequently from the Swift compiler's perspective. On the other hand, if you're changing the compiler's AST, the cache hit rate is likely to be much lower.

View File

@@ -246,15 +246,13 @@ Phew, that's a lot to digest! Now let's proceed to the actual build itself!
```sh
utils/build-script --skip-build-benchmarks \
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "x86_64" \
--cmake-c-launcher="$(which sccache)" --cmake-cxx-launcher="$(which sccache)" \
--release-debuginfo --test
--sccache --release-debuginfo --test
```
- Via Xcode:
```sh
utils/build-script --skip-build-benchmarks \
--skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "x86_64" \
--cmake-c-launcher="$(which sccache)" --cmake-cxx-launcher="$(which sccache)" \
--release-debuginfo --test \
--sccache --release-debuginfo --test \
--xcode
```
This will create a directory

View File

@@ -187,6 +187,11 @@ def validate_arguments(toolchain, args):
fatal_error(
"can't find distcc-pump (please install distcc-pump)")
if args.sccache:
if toolchain.sccache is None:
fatal_error(
"can't find sccache (please install sccache)")
if args.host_target is None or args.stdlib_deployment_targets is None:
fatal_error("unknown operating system")
@@ -523,6 +528,9 @@ class BuildScriptInvocation(object):
"--distcc",
"--distcc-pump=%s" % toolchain.distcc_pump
]
if args.sccache:
args.cmake_c_launcher = toolchain.sccache
args.cmake_cxx_launcher = toolchain.sccache
# *NOTE* We use normal cmake to pass through tsan/ubsan options. We do
# NOT pass them to build-script-impl.
@@ -1064,6 +1072,12 @@ def parse_preset_args():
action=argparse.actions.StoreTrueAction,
nargs=argparse.Nargs.OPTIONAL,
default=os.environ.get('USE_DISTCC') == '1')
parser.add_argument(
"--sccache",
help="use sccache",
action=argparse.actions.StoreTrueAction,
nargs=argparse.Nargs.OPTIONAL,
default=os.environ.get('USE_SCCACHE') == '1')
parser.add_argument(
"--cmake-c-launcher",
help="the absolute path to set CMAKE_C_COMPILER_LAUNCHER",
@@ -1157,6 +1171,10 @@ def main_preset():
fatal_error(
'--distcc can not be used with' +
' --cmake-c-launcher or --cmake-cxx-launcher')
if args.sccache and (args.cmake_c_launcher or args.cmake_cxx_launcher):
fatal_error(
'--sccache can not be used with' +
' --cmake-c-launcher or --cmake-cxx-launcher')
build_script_args = [sys.argv[0]]
if args.dry_run:
@@ -1167,6 +1185,8 @@ def main_preset():
build_script_args += preset_args
if args.distcc:
build_script_args += ["--distcc"]
if args.sccache:
build_script_args += ["--sccache"]
if args.build_jobs:
build_script_args += ["--jobs", str(args.build_jobs)]
if args.swiftsyntax_install_prefix:

View File

@@ -85,13 +85,7 @@ while [ $# -ne 0 ]; do
DISTCC_FLAG="--distcc"
;;
--sccache)
SCCACHE=$(which sccache)
if [[ -z "${SCCACHE}" ]]; then
echo "Error! Asked to use sccache, but could not find sccache in PATH?!"
usage
exit 1
fi
SCCACHE_FLAG="--cmake-c-launcher=${SCCACHE} --cmake-cxx-launcher=${SCCACHE}"
SCCACHE_FLAG="--sccache"
;;
--preset-file)
shift

View File

@@ -387,6 +387,9 @@ def create_argument_parser():
option('--distcc', toggle_true,
default=os.environ.get('USE_DISTCC') == '1',
help='use distcc in pump mode')
option('--sccache', toggle_true,
default=os.environ.get('USE_SCCACHE') == '1',
help='use sccache')
option('--enable-asan', toggle_true,
help='enable Address Sanitizer')
option('--enable-ubsan', toggle_true,

View File

@@ -138,6 +138,7 @@ EXPECTED_DEFAULTS = {
defaults.DARWIN_DEPLOYMENT_VERSION_WATCHOS,
'darwin_xcrun_toolchain': None,
'distcc': False,
'sccache': False,
'dry_run': False,
'enable_asan': False,
'enable_experimental_differentiable_programming': True,
@@ -500,6 +501,7 @@ EXPECTED_OPTIONS = [
EnableOption('--build-swift-static-stdlib'),
EnableOption('--build-swift-stdlib-unittest-extra'),
EnableOption('--distcc'),
EnableOption('--sccache'),
EnableOption('--enable-asan'),
EnableOption('--enable-experimental-differentiable-programming'),
EnableOption('--enable-experimental-concurrency'),

View File

@@ -126,6 +126,10 @@ class CMake(object):
define("CMAKE_C_COMPILER_LAUNCHER:PATH", toolchain.distcc)
define("CMAKE_CXX_COMPILER_LAUNCHER:PATH", toolchain.distcc)
if args.sccache:
define("CMAKE_C_COMPILER_LAUNCHER:PATH", toolchain.sccache)
define("CMAKE_CXX_COMPILER_LAUNCHER:PATH", toolchain.sccache)
if args.cmake_c_launcher:
define("CMAKE_C_COMPILER_LAUNCHER:PATH", args.cmake_c_launcher)
if args.cmake_cxx_launcher:

View File

@@ -62,6 +62,7 @@ _register("llvm_profdata", "llvm-profdata")
_register("llvm_cov", "llvm-cov")
_register("lipo", "lipo")
_register("libtool", "libtool")
_register("sccache", "sccache")
_register("swiftc", "swiftc")

View File

@@ -68,6 +68,9 @@ class ToolchainTestCase(unittest.TestCase):
self.assertTrue(tc.distcc_pump is None or
os.path.basename(tc.distcc_pump) == 'pump' or
os.path.basename(tc.distcc_pump) == 'distcc-pump')
# sccache
self.assertTrue(tc.sccache is None or
os.path.basename(tc.sccache) == 'sccache')
def test_find_tool(self):
tc = host_toolchain()