Skip to content

Commit df53994

Browse files
committed
[benchmarks] Add support for building the benchmarks via build-script against the just created toolchain.
Now one can on Darwin/Linux build the benchmarks via swiftpm from build-script by passing in: ``` build-script $NORMAL_ARGS --install-swift --install-swiftpm --install-llbuild --toolchain-benchmarks --swiftpm --llbuild ``` This is done using the infrastructure that BenL added for sourcekit-lsp.
1 parent f39defa commit df53994

File tree

6 files changed

+134
-3
lines changed

6 files changed

+134
-3
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
5+
import argparse
6+
import os
7+
import subprocess
8+
9+
10+
def main():
11+
parser = argparse.ArgumentParser()
12+
parser.add_argument('--verbose', '-v', action='store_true')
13+
parser.add_argument('--package-path', type=str, required=True)
14+
parser.add_argument('--build-path', type=str, required=True)
15+
parser.add_argument('--toolchain', type=str, required=True)
16+
17+
# Build the debug/release versions.
18+
args = parser.parse_args()
19+
swiftbuild_path = os.path.join(args.toolchain, 'usr', 'bin', 'swift-build')
20+
swiftbuild_args = [
21+
swiftbuild_path,
22+
'--package-path', args.package_path,
23+
'--build-path', args.build_path,
24+
'--configuration', 'debug',
25+
]
26+
if args.verbose:
27+
swiftbuild_args.append('--verbose')
28+
subprocess.call(swiftbuild_args)
29+
30+
swiftbuild_args = [
31+
swiftbuild_path,
32+
'--package-path', args.package_path,
33+
'--build-path', args.build_path,
34+
'--configuration', 'release',
35+
'-Xswiftc', '-Xllvm',
36+
'-Xswiftc', '-align-module-to-page-size',
37+
]
38+
if args.verbose:
39+
swiftbuild_args.append('--verbose')
40+
subprocess.call(swiftbuild_args)
41+
42+
43+
if __name__ == "__main__":
44+
main()

utils/build-script

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,17 @@ class BuildScriptInvocation(object):
244244
"--android-icu-i18n-include, and --android-icu-data "
245245
"must be specified")
246246

247-
if args.legacy_impl and (args.build_indexstoredb or
248-
args.build_sourcekitlsp):
247+
targets_needing_toolchain = [
248+
'build_indexstoredb',
249+
'build_sourcekitlsp',
250+
'build_toolchainbenchmarks',
251+
]
252+
has_target_needing_toolchain = \
253+
bool(sum(getattr(args, x) for x in targets_needing_toolchain))
254+
if args.legacy_impl and has_target_needing_toolchain:
249255
diagnostics.fatal(
250256
"--legacy-impl is incompatible with building packages needing "
251-
"a toolchain (indexstore-db or sourcekit-lsp)")
257+
"a toolchain (%s)" % ", ".join(targets_needing_toolchain))
252258

253259
@staticmethod
254260
def apply_default_arguments(toolchain, args):
@@ -879,6 +885,8 @@ class BuildScriptInvocation(object):
879885
product_classes.append(products.IndexStoreDB)
880886
if self.args.build_sourcekitlsp:
881887
product_classes.append(products.SourceKitLSP)
888+
if self.args.build_toolchainbenchmarks:
889+
product_classes.append(products.ToolchainBenchmarks)
882890
return product_classes
883891

884892
def execute(self):

utils/build_swift/driver_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ def create_argument_parser():
546546
help='build IndexStoreDB')
547547
option(['--sourcekit-lsp'], toggle_true('build_sourcekitlsp'),
548548
help='build SourceKitLSP')
549+
option(['--toolchain-benchmarks'],
550+
toggle_true('build_toolchainbenchmarks'),
551+
help='build Swift Benchmarks using swiftpm against the just built '
552+
'toolchain')
549553

550554
option('--xctest', toggle_true('build_xctest'),
551555
help='build xctest')

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
'build_swiftevolve': False,
8989
'build_indexstoredb': False,
9090
'build_sourcekitlsp': False,
91+
'build_toolchainbenchmarks': False,
9192
'build_tvos': True,
9293
'build_tvos_device': False,
9394
'build_tvos_simulator': False,
@@ -448,6 +449,7 @@ class IgnoreOption(_BaseOption):
448449
EnableOption('--libicu', dest='build_libicu'),
449450
EnableOption('--indexstore-db', dest='build_indexstoredb'),
450451
EnableOption('--sourcekit-lsp', dest='build_sourcekitlsp'),
452+
EnableOption('--toolchain-benchmarks', dest='build_toolchainbenchmarks'),
451453
EnableOption('--long-test'),
452454
EnableOption('--show-sdks'),
453455
EnableOption('--stress-test'),

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#
1111
# ----------------------------------------------------------------------------
1212

13+
from .benchmarks import ToolchainBenchmarks
1314
from .cmark import CMark
1415
from .foundation import Foundation
1516
from .indexstoredb import IndexStoreDB
@@ -47,4 +48,5 @@
4748
'SwiftEvolve',
4849
'IndexStoreDB',
4950
'SourceKitLSP',
51+
'ToolchainBenchmarks',
5052
]
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# swift_build_support/products/benchmarks.py --------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
import os
14+
import platform
15+
16+
from . import product
17+
from .. import shell
18+
from .. import targets
19+
20+
21+
# Build against the current installed toolchain.
22+
class ToolchainBenchmarks(product.Product):
23+
@classmethod
24+
def product_source_name(cls):
25+
return "benchmarks"
26+
27+
@classmethod
28+
def is_build_script_impl_product(cls):
29+
return False
30+
31+
def do_build(self, host_target):
32+
run_build_script_helper(host_target, self, self.args)
33+
34+
def do_test(self, host_target):
35+
"""Just run a single instance of the command for both .debug and
36+
.release.
37+
"""
38+
cmdline = ['--num-iters=1', 'XorLoop']
39+
debug_bench = os.path.join(self.build_dir, 'debug', 'SwiftBench')
40+
shell.call([debug_bench] + cmdline)
41+
42+
release_bench = os.path.join(self.build_dir, 'release', 'SwiftBench')
43+
shell.call([release_bench] + cmdline)
44+
45+
46+
def run_build_script_helper(host_target, product, args):
47+
toolchain_path = args.install_destdir
48+
if platform.system() == 'Darwin':
49+
# The prefix is an absolute path, so concatenate without os.path.
50+
toolchain_path += \
51+
targets.darwin_toolchain_prefix(args.install_prefix)
52+
53+
# Our source_dir is expected to be './$SOURCE_ROOT/benchmarks'. That is due
54+
# the assumption that each product is in its own build directory. This
55+
# product is not like that and has its package/tools instead in
56+
# ./$SOURCE_ROOT/swift/benchmark.
57+
package_path = os.path.join(product.source_dir, '..', 'swift', 'benchmark')
58+
package_path = os.path.abspath(package_path)
59+
60+
# We use a separate python helper to enable quicker iteration when working
61+
# on this by avoiding going through build-script to test small changes.
62+
helper_path = os.path.join(package_path, 'utils', 'build_script_helper.py')
63+
64+
build_cmd = [
65+
helper_path,
66+
'--verbose',
67+
'--package-path', package_path,
68+
'--build-path', product.build_dir,
69+
'--toolchain', toolchain_path,
70+
]
71+
shell.call(build_cmd)

0 commit comments

Comments
 (0)