@@ -37,11 +37,19 @@ def main():
37
37
if not args .skip_build :
38
38
build_swift_toolchain (workspace , args )
39
39
40
+ additional_runner_args = []
41
+ if args .clang_source_path or args .clang :
42
+ clang = args .clang
43
+ if args .clang_source_path :
44
+ clang = build_clang (workspace , args )
45
+ if clang :
46
+ additional_runner_args = ['--clang' , clang ]
47
+
40
48
if not args .skip_runner :
41
49
if args .test_incremental :
42
- execute_build_incremental (workspace , args )
50
+ execute_build_incremental (workspace , args , additional_runner_args )
43
51
else :
44
- execute_runner (workspace , args )
52
+ execute_runner (workspace , args , additional_runner_args )
45
53
46
54
return 0
47
55
@@ -57,10 +65,10 @@ def parse_args():
57
65
parser .add_argument ("--verbose" ,
58
66
action = 'store_true' )
59
67
parser .add_argument ("--assertions" ,
60
- help = 'Build Swift with asserts' ,
68
+ help = 'Build Swift and/or Clang with asserts' ,
61
69
action = 'store_true' )
62
70
parser .add_argument ("--debug" ,
63
- help = 'Build Swift in debug mode' ,
71
+ help = 'Build Swift and/or Clang in debug mode' ,
64
72
action = 'store_true' )
65
73
parser .add_argument ("--filter-by-tag" ,
66
74
metavar = 'TAG' ,
@@ -74,6 +82,17 @@ def parse_args():
74
82
parser .add_argument ('--swiftc' ,
75
83
metavar = 'PATH' ,
76
84
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 ('--clang' ,
93
+ metavar = "PATH" ,
94
+ help = 'clang executable to build Xcode projects' ,
95
+ type = os .path .abspath )
77
96
parser .add_argument ('--skip-build' ,
78
97
action = 'store_true' )
79
98
parser .add_argument ('--skip-ci-steps' ,
@@ -161,7 +180,7 @@ def get_sandbox_profile_flags_test():
161
180
return sandbox_flags
162
181
163
182
164
- def execute_runner (workspace , args ):
183
+ def execute_runner (workspace , args , additional_runner_args ):
165
184
swiftc_path = get_swiftc_path (workspace , args .swiftc )
166
185
if args .test :
167
186
action_filter = 'action.startswith("TestSwiftPackage")'
@@ -193,10 +212,12 @@ def execute_runner(workspace, args):
193
212
if args .build_config :
194
213
runner_command += ['--build-config=%s' % args .build_config ]
195
214
215
+ runner_command += additional_runner_args
216
+
196
217
common .check_execute (runner_command , timeout = 9999999 )
197
218
198
219
199
- def execute_build_incremental (workspace , args ):
220
+ def execute_build_incremental (workspace , args , additional_runner_args ):
200
221
swiftc_path = get_swiftc_path (workspace , args .swiftc )
201
222
runner_command = [
202
223
'./build_incremental.py' ,
@@ -211,6 +232,7 @@ def execute_build_incremental(workspace, args):
211
232
]
212
233
if args .sandbox :
213
234
runner_command += get_sandbox_profile_flags ()
235
+ runner_command += additional_runner_args
214
236
common .check_execute (runner_command , timeout = 9999999 )
215
237
216
238
def get_preset_name (args ):
@@ -270,6 +292,34 @@ def build_swift_toolchain(workspace, args):
270
292
raise common .UnsupportedPlatform
271
293
common .check_execute (build_command , timeout = 9999999 )
272
294
295
+ def build_clang (workspace , args ):
296
+ build_path = os .path .join (workspace , 'build_clang_source_compat' )
297
+ source_path = os .path .join (args .clang_source_path , 'llvm' )
298
+ common .check_execute (['mkdir' , '-p' , build_path ])
299
+
300
+ with common .DirectoryContext (build_path ):
301
+ # Get path to the ninja binary
302
+ ninja_path = common .check_execute_output (['xcrun' , '--find' , 'ninja' ]).strip ().decode ("utf-8" )
303
+
304
+ build_type = "Debug" if args .debug else "Release"
305
+ assert_on = "True" if args .assertions or args .debug else "False"
306
+
307
+ # Generate a Ninja project with CMake
308
+ cmake_command = [
309
+ 'xcrun' , 'cmake' , '-G' , 'Ninja' ,
310
+ '-DCMAKE_MAKE_PROGRAM={}' .format (ninja_path ),
311
+ '-DLLVM_ENABLE_PROJECTS=clang;llvm' ,
312
+ '-DCMAKE_BUILD_TYPE={}' .format (build_type ),
313
+ '-DLLVM_ENABLE_ASSERTIONS={}' .format (assert_on ),
314
+ '-DCLANG_APPLE_BUILD_VERSION_STRING=13000000' ,
315
+ '-DLLVM_TARGETS_TO_BUILD=X86;AArch64;ARM' ,
316
+ source_path ]
317
+ common .check_execute (cmake_command )
318
+
319
+ # Build the Ninja project to produce the clang executable
320
+ common .check_execute (['xcrun' , 'ninja' ])
321
+
322
+ return os .path .join (build_path , 'bin' , 'clang' )
273
323
274
324
if __name__ == '__main__' :
275
325
sys .exit (main ())
0 commit comments