Skip to content

Commit cfe118d

Browse files
committed
Add clangc flag to runner.py
'--clangc' provides a way to build Xcode projects with a custom clang binary, by adding 'CC=clangc' flag to xcode. With '--clang-source-path', the 'run' script builds clang binary from the clang source in the path and provides this binary path to 'runner.py' using the '--clangc' flag.
1 parent 36d3a10 commit cfe118d

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

project_future.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,9 @@ def add_arguments(parser):
583583
parser.add_argument("--report-time-path",
584584
help='export time for building each xcode build target to the specified json file',
585585
type=os.path.abspath)
586+
parser.add_argument("--clangc",
587+
help='clang executable to build Xcode projects',
588+
type=os.path.abspath)
586589

587590
def add_minimal_arguments(parser):
588591
"""Add common arguments to parser."""

run

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@ def main():
3737
if not args.skip_build:
3838
build_swift_toolchain(workspace, args)
3939

40+
clang_flags = []
41+
if args.clang_source_path or args.clangc:
42+
clangc = args.clangc
43+
if args.clang_source_path:
44+
clangc = build_clang(workspace, args.clang_source_path)
45+
if clangc:
46+
clang_flags = ['--clangc', clangc]
47+
4048
if not args.skip_runner:
4149
if args.test_incremental:
42-
execute_build_incremental(workspace, args)
50+
execute_build_incremental(workspace, args, clang_flags)
4351
else:
44-
execute_runner(workspace, args)
52+
execute_runner(workspace, args, clang_flags)
4553

4654
return 0
4755

@@ -74,6 +82,17 @@ def parse_args():
7482
parser.add_argument('--swiftc',
7583
metavar='PATH',
7684
help='swiftc executable')
85+
clang_arguments = parser.add_mutually_exclusive_group()
86+
clang_arguments.add_argument('--clang-source-path',
87+
metavar="PATH",
88+
help='Path to llvm-project source. Build a new clang '
89+
'executable from the given path and uses it to '
90+
'build Xcode projects',
91+
type=os.path.abspath)
92+
clang_arguments.add_argument('--clangc',
93+
metavar="PATH",
94+
help='clang executable',
95+
type=os.path.abspath)
7796
parser.add_argument('--skip-build',
7897
action='store_true')
7998
parser.add_argument('--skip-ci-steps',
@@ -161,7 +180,7 @@ def get_sandbox_profile_flags_test():
161180
return sandbox_flags
162181

163182

164-
def execute_runner(workspace, args):
183+
def execute_runner(workspace, args, clang_flags):
165184
swiftc_path = get_swiftc_path(workspace, args.swiftc)
166185
if args.test:
167186
action_filter = 'action.startswith("TestSwiftPackage")'
@@ -193,10 +212,12 @@ def execute_runner(workspace, args):
193212
if args.build_config:
194213
runner_command += ['--build-config=%s' % args.build_config]
195214

215+
runner_command += clang_flags
216+
196217
common.check_execute(runner_command, timeout=9999999)
197218

198219

199-
def execute_build_incremental(workspace, args):
220+
def execute_build_incremental(workspace, args, clang_flags):
200221
swiftc_path = get_swiftc_path(workspace, args.swiftc)
201222
runner_command = [
202223
'./build_incremental.py',
@@ -211,6 +232,7 @@ def execute_build_incremental(workspace, args):
211232
]
212233
if args.sandbox:
213234
runner_command += get_sandbox_profile_flags()
235+
runner_command += clang_flags
214236
common.check_execute(runner_command, timeout=9999999)
215237

216238
def get_preset_name(args):
@@ -270,6 +292,28 @@ def build_swift_toolchain(workspace, args):
270292
raise common.UnsupportedPlatform
271293
common.check_execute(build_command, timeout=9999999)
272294

295+
def build_clang(workspace, source_path):
296+
build_path = os.path.join(workspace, 'build_clang_source_compat')
297+
source_path = os.path.join(source_path, 'llvm')
298+
common.check_execute(['mkdir', '-p', build_path])
299+
300+
with common.DirectoryContext(build_path):
301+
try:
302+
ninja_path = common.check_execute_output(['xcrun', '--find', 'ninja']).strip().decode("utf-8")
303+
cmake_command = [
304+
'xcrun', 'cmake', '-G', 'Ninja',
305+
'-DCMAKE_MAKE_PROGRAM={}'.format(ninja_path),
306+
'-DLLVM_ENABLE_PROJECTS=clang;llvm',
307+
'-DCMAKE_BUILD_TYPE=Release',
308+
'-DCLANG_APPLE_BUILD_VERSION_STRING=13000000',
309+
'-DLLVM_TARGETS_TO_BUILD=X86;AArch64;ARM',
310+
source_path]
311+
common.check_execute(cmake_command)
312+
common.check_execute(['xcrun', 'ninja'])
313+
except:
314+
raise
315+
316+
return os.path.join(build_path, 'bin', 'clang')
273317

274318
if __name__ == '__main__':
275319
sys.exit(main())

runner.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def main():
4242
xcodebuild_flags = args.add_xcodebuild_flags
4343
xcodebuild_flags += (' ' if xcodebuild_flags else '') + 'DEBUG_INFORMATION_FORMAT=dwarf'
4444

45+
# Use clangc for building xcode projects.
46+
if args.clangc:
47+
xcodebuild_flags += ' CC=%s' % args.clangc
48+
4549
swift_flags = args.add_swift_flags
4650

4751
time_reporter = None

0 commit comments

Comments
 (0)