@@ -217,6 +217,22 @@ def should_build(self, host_target):
217
217
# LLVM will always be built in part
218
218
return True
219
219
220
+ @classmethod
221
+ def compute_cmake_args_for_runtimes (cls , host_target ):
222
+ # Swift expects the old layout for the runtime directory
223
+ args_for_runtime = '-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR:BOOL=OFF'
224
+
225
+ if host_target .startswith ('linux' ):
226
+ # This preserves the behaviour we had when using
227
+ # LLVM_BUILD_EXTERNAL COMPILER_RT --
228
+ # that is, having the linker not complaing if symbols used
229
+ # by TSan are undefined (namely the ones for Blocks Runtime)
230
+ # In the long term, we want to remove this and
231
+ # build Blocks Runtime before LLVM
232
+ args_for_runtime += ';-DSANITIZER_COMMON_LINK_FLAGS:STRING=-Wl,-z,undefs'
233
+
234
+ return args_for_runtime
235
+
220
236
def build (self , host_target ):
221
237
"""build() -> void
222
238
@@ -291,6 +307,9 @@ def build(self, host_target):
291
307
llvm_cmake_options .define ('LLVM_INCLUDE_DOCS:BOOL' , 'TRUE' )
292
308
llvm_cmake_options .define ('LLVM_ENABLE_LTO:STRING' , self .args .lto_type )
293
309
llvm_cmake_options .define ('COMPILER_RT_INTERCEPT_LIBDISPATCH' , 'ON' )
310
+ llvm_cmake_options .define (
311
+ 'RUNTIMES_CMAKE_ARGS' ,
312
+ LLVM .compute_cmake_args_for_runtimes (host_target ))
294
313
295
314
if self .args .build_embedded_stdlib and system () == "Darwin" :
296
315
# Ask for Mach-O cross-compilation builtins (for Embedded Swift)
@@ -299,10 +318,12 @@ def build(self, host_target):
299
318
'armv6 armv6m armv7 armv7m armv7em' )
300
319
301
320
llvm_enable_projects = ['clang' ]
321
+ llvm_enable_runtimes = []
302
322
303
323
if self .args .build_compiler_rt and \
304
324
not self .is_cross_compile_target (host_target ):
305
- llvm_enable_projects .append ('compiler-rt' )
325
+ llvm_enable_runtimes .append ('compiler-rt' )
326
+ build_targets .append ("runtimes" )
306
327
307
328
if self .args .build_clang_tools_extra :
308
329
llvm_enable_projects .append ('clang-tools-extra' )
@@ -316,18 +337,20 @@ def build(self, host_target):
316
337
if self .args .build_lld :
317
338
llvm_enable_projects .append ('lld' )
318
339
340
+ if self .args .test :
341
+ # LLVMTestingSupport is not built at part of `all`
342
+ # and is required by some Swift tests
343
+ build_targets .append ('LLVMTestingSupport' )
344
+
319
345
llvm_cmake_options .define ('LLVM_ENABLE_PROJECTS' ,
320
346
';' .join (llvm_enable_projects ))
347
+ llvm_cmake_options .define ('LLVM_ENABLE_RUNTIMES' ,
348
+ ';' .join (llvm_enable_runtimes ))
321
349
322
- # In the near future we are aiming to build compiler-rt with
323
- # LLVM_ENABLE_RUNTIMES
324
- # Until that happens, we need to unset this variable from
325
- # LLVM CMakeCache.txt for two reasons
326
- # * prevent PRs testing this variable to affect other runs landing
327
- # unrelated features
328
- # * avoid fallouts should we land such change and then have to revert
329
- # it to account for unforeseen regressions
330
- llvm_cmake_options .undefine ('LLVM_ENABLE_RUNTIMES' )
350
+ # This accounts for previous incremental runs that may have set
351
+ # those in the LLVM CMakeCache.txt
352
+ llvm_cmake_options .undefine ('LLVM_TOOL_COMPILER_RT_BUILD' )
353
+ llvm_cmake_options .undefine ('LLVM_BUILD_EXTERNAL_COMPILER_RT' )
331
354
332
355
# NOTE: This is not a dead option! It is relied upon for certain
333
356
# bots/build-configs!
@@ -491,9 +514,19 @@ def install(self, host_target):
491
514
self .args .llvm_install_components != 'all' :
492
515
install_targets = []
493
516
components = self .args .llvm_install_components .split (';' )
517
+ if 'compiler-rt' in components :
518
+ # This is a courtesy fallback to avoid breaking downstream presets
519
+ # we are not aware of
520
+ components .remove ('compiler-rt' )
521
+ components .append ('builtins' )
522
+ components .append ('runtimes' )
523
+ print ('warning: replaced legacy LLVM component compiler-rt '
524
+ 'with builtins;runtimes -- consider updating your preset' ,
525
+ flush = True )
526
+
494
527
for component in components :
495
528
if self .is_cross_compile_target (host_target ):
496
- if component == 'compiler-rt' :
529
+ if component in [ 'builtins' , 'runtimes' ] :
497
530
continue
498
531
install_targets .append ('install-{}' .format (component ))
499
532
0 commit comments