@@ -37,11 +37,19 @@ def main():
37
37
if not args .skip_build :
38
38
build_swift_toolchain (workspace , args )
39
39
40
+ clang_flag = []
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_flag = ['--clangc' , clangc ]
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 , clang_flag )
43
51
else :
44
- execute_runner (workspace , args )
52
+ execute_runner (workspace , args , clang_flag )
45
53
46
54
return 0
47
55
@@ -74,6 +82,15 @@ 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 to build' ,
89
+ type = os .path .abspath )
90
+ clang_arguments .add_argument ('--clangc' ,
91
+ metavar = "PATH" ,
92
+ help = 'clang executable' ,
93
+ type = os .path .abspath )
77
94
parser .add_argument ('--skip-build' ,
78
95
action = 'store_true' )
79
96
parser .add_argument ('--skip-ci-steps' ,
@@ -161,7 +178,7 @@ def get_sandbox_profile_flags_test():
161
178
return sandbox_flags
162
179
163
180
164
- def execute_runner (workspace , args ):
181
+ def execute_runner (workspace , args , clang_flag ):
165
182
swiftc_path = get_swiftc_path (workspace , args .swiftc )
166
183
if args .test :
167
184
action_filter = 'action.startswith("TestSwiftPackage")'
@@ -193,10 +210,12 @@ def execute_runner(workspace, args):
193
210
if args .build_config :
194
211
runner_command += ['--build-config=%s' % args .build_config ]
195
212
213
+ runner_command += clang_flag
214
+
196
215
common .check_execute (runner_command , timeout = 9999999 )
197
216
198
217
199
- def execute_build_incremental (workspace , args ):
218
+ def execute_build_incremental (workspace , args , clang_flag ):
200
219
swiftc_path = get_swiftc_path (workspace , args .swiftc )
201
220
runner_command = [
202
221
'./build_incremental.py' ,
@@ -211,6 +230,7 @@ def execute_build_incremental(workspace, args):
211
230
]
212
231
if args .sandbox :
213
232
runner_command += get_sandbox_profile_flags ()
233
+ runner_command += clang_flag
214
234
common .check_execute (runner_command , timeout = 9999999 )
215
235
216
236
def get_preset_name (args ):
@@ -270,6 +290,28 @@ def build_swift_toolchain(workspace, args):
270
290
raise common .UnsupportedPlatform
271
291
common .check_execute (build_command , timeout = 9999999 )
272
292
293
+ def build_clang (workspace , source_path ):
294
+ build_path = os .path .join (workspace , 'build_clang_source_compat' )
295
+ source_path = os .path .join (source_path , 'llvm' )
296
+ common .check_execute (['mkdir' , '-p' , build_path ])
297
+
298
+ with common .DirectoryContext (build_path ):
299
+ try :
300
+ ninja_path = common .check_execute_output (['xcrun' , '--find' , 'ninja' ]).strip ().decode ("utf-8" )
301
+ cmake_command = [
302
+ 'xcrun' , 'cmake' , '-G' , 'Ninja' ,
303
+ '-DCMAKE_MAKE_PROGRAM={}' .format (ninja_path ),
304
+ '-DLLVM_ENABLE_PROJECTS=clang;llvm' ,
305
+ '-DCMAKE_BUILD_TYPE=Release' ,
306
+ '-DCLANG_APPLE_BUILD_VERSION_STRING=13000000' ,
307
+ '-DLLVM_TARGETS_TO_BUILD=X86;AArch64;ARM' ,
308
+ source_path ]
309
+ common .check_execute (cmake_command )
310
+ common .check_execute (['xcrun' , 'ninja' ])
311
+ except :
312
+ raise
313
+
314
+ return os .path .join (build_path , 'bin' , 'clang' )
273
315
274
316
if __name__ == '__main__' :
275
317
sys .exit (main ())
0 commit comments