@@ -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,18 +307,54 @@ 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 ))
313
+ if system () == "Darwin" :
314
+ llvm_cmake_options .define ('LLVM_BUILTIN_TARGETS' , 'arm64-apple-darwin' )
315
+ llvm_cmake_options .define ('LLVM_RUNTIME_TARGETS' , 'arm64-apple-darwin' )
316
+ llvm_cmake_options .define ('RUNTIMES_BUILD_ALLOW_DARWIN' , 'ON' )
294
317
295
318
if self .args .build_embedded_stdlib and system () == "Darwin" :
296
319
# Ask for Mach-O cross-compilation builtins (for Embedded Swift)
297
320
llvm_cmake_options .define (
298
321
'COMPILER_RT_FORCE_BUILD_BAREMETAL_MACHO_BUILTINS_ARCHS:STRING' ,
299
322
'armv6 armv6m armv7 armv7m armv7em' )
323
+ # TODO we likely need a more generic mechanism to add flags
324
+ # meant for the builtins build system
325
+ llvm_cmake_options .define (
326
+ 'BUILTIN_CMAKE_ARGS' ,
327
+ '-DCOMPILER_RT_FORCE_BUILD_BAREMETAL_MACHO_BUILTINS_ARCHS:'
328
+ 'STRING=armv6 armv6m armv7 armv7m armv7em' )
300
329
301
330
llvm_enable_projects = ['clang' ]
331
+ llvm_enable_runtimes = []
302
332
303
333
if self .args .build_compiler_rt and \
304
334
not self .is_cross_compile_target (host_target ):
305
- llvm_enable_projects .append ('compiler-rt' )
335
+ if self .args .llvm_build_compiler_rt_with_use_runtimes :
336
+ llvm_enable_runtimes .append ('compiler-rt' )
337
+ build_targets .append ("runtimes" )
338
+ # This accounts for previous incremental runs that may have set
339
+ # those in the LLVM CMakeCache.txt
340
+ llvm_cmake_options .undefine ('LLVM_TOOL_COMPILER_RT_BUILD' )
341
+ llvm_cmake_options .undefine ('LLVM_BUILD_EXTERNAL_COMPILER_RT' )
342
+ else :
343
+ # No need to unset anything,
344
+ # since we set LLVM_ENABLE_RUNTIMES explicitly
345
+ llvm_enable_projects .append ('compiler-rt' )
346
+ llvm_cmake_options .define (
347
+ 'LLVM_TOOL_COMPILER_RT_BUILD:BOOL' , 'TRUE' )
348
+ llvm_cmake_options .define (
349
+ 'LLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL' , 'TRUE' )
350
+ else :
351
+ if not self .args .llvm_build_compiler_rt_with_use_runtimes :
352
+ # No need to unset anything,
353
+ # since we set LLVM_ENABLE_RUNTIMES explicitly
354
+ llvm_cmake_options .define (
355
+ 'LLVM_TOOL_COMPILER_RT_BUILD:BOOL' , 'FALSE' )
356
+ llvm_cmake_options .define (
357
+ 'LLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL' , 'FALSE' )
306
358
307
359
if self .args .build_clang_tools_extra :
308
360
llvm_enable_projects .append ('clang-tools-extra' )
@@ -316,18 +368,15 @@ def build(self, host_target):
316
368
if self .args .build_lld :
317
369
llvm_enable_projects .append ('lld' )
318
370
371
+ if self .args .test :
372
+ # LLVMTestingSupport is not built at part of `all`
373
+ # and is required by some Swift tests
374
+ build_targets .append ('LLVMTestingSupport' )
375
+
319
376
llvm_cmake_options .define ('LLVM_ENABLE_PROJECTS' ,
320
377
';' .join (llvm_enable_projects ))
321
-
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' )
378
+ llvm_cmake_options .define ('LLVM_ENABLE_RUNTIMES' ,
379
+ ';' .join (llvm_enable_runtimes ))
331
380
332
381
# NOTE: This is not a dead option! It is relied upon for certain
333
382
# bots/build-configs!
@@ -491,9 +540,21 @@ def install(self, host_target):
491
540
self .args .llvm_install_components != 'all' :
492
541
install_targets = []
493
542
components = self .args .llvm_install_components .split (';' )
543
+ if self .args .llvm_build_compiler_rt_with_use_runtimes and \
544
+ 'compiler-rt' in components :
545
+ # This is a courtesy fallback to avoid breaking downstream presets
546
+ # we are not aware of
547
+ components .remove ('compiler-rt' )
548
+ components .append ('builtins' )
549
+ components .append ('runtimes' )
550
+ print ('warning: replaced legacy LLVM component compiler-rt '
551
+ 'with builtins;runtimes -- consider updating your preset' ,
552
+ flush = True )
553
+
494
554
for component in components :
495
- if self .is_cross_compile_target (host_target ):
496
- if component == 'compiler-rt' :
555
+ if self .is_cross_compile_target (host_target ) \
556
+ or not self .args .build_compiler_rt :
557
+ if component in ['compiler-rt' , 'builtins' , 'runtimes' ]:
497
558
continue
498
559
install_targets .append ('install-{}' .format (component ))
499
560
0 commit comments