@@ -390,7 +390,7 @@ endfunction()
390
390
# [SHARED]
391
391
# [STATIC]
392
392
# [OBJECT]
393
- # [IGNORE_LLVM_UPDATE_COMPILE_FLAGS ]
393
+ # [PURE_SWIFT ]
394
394
# [LLVM_LINK_COMPONENTS comp1 ...]
395
395
# source1 [source2 source3 ...])
396
396
#
@@ -409,10 +409,9 @@ endfunction()
409
409
# LLVM_LINK_COMPONENTS
410
410
# LLVM components this library depends on.
411
411
#
412
- # IGNORE_LLVM_UPDATE_COMPILE_FLAGS
413
- # If set do not use llvm_update_compile_flags to generate cflags/etc. This is
414
- # generally used when compiling a mixed c/c++/swift library and one wants to
415
- # disable this for the swift part.
412
+ # PURE_SWIFT
413
+ # This has two effects if set: we do not use llvm_update_compile_flags to
414
+ # generate cflags/etc and we leave the linking mode of the library as swift.
416
415
#
417
416
# source1 ...
418
417
# Sources to add into this library.
@@ -421,7 +420,7 @@ function(add_swift_host_library name)
421
420
SHARED
422
421
STATIC
423
422
OBJECT
424
- IGNORE_LLVM_UPDATE_COMPILE_FLAGS )
423
+ PURE_SWIFT )
425
424
set(single_parameter_options)
426
425
set(multiple_parameter_options
427
426
LLVM_LINK_COMPONENTS)
@@ -467,7 +466,7 @@ function(add_swift_host_library name)
467
466
468
467
add_library(${name} ${libkind} ${ASHL_SOURCES} )
469
468
add_dependencies(${name} ${LLVM_COMMON_DEPENDS} )
470
- if (NOT ASHL_IGNORE_LLVM_UPDATE_COMPILE_FLAGS )
469
+ if (NOT ASHL_PURE_SWIFT )
471
470
llvm_update_compile_flags(${name} )
472
471
endif()
473
472
swift_common_llvm_config(${name} ${ASHL_LLVM_LINK_COMPONENTS} )
@@ -528,6 +527,12 @@ function(add_swift_host_library name)
528
527
NO_SONAME YES)
529
528
endif()
530
529
530
+ # Always link as CXX even if we have swift content unless we only contain
531
+ # swift content signaled via us being marked " PURE_SWIFT ".
532
+ if (NOT ASHL_PURE_SWIFT)
533
+ set_target_properties(${name} PROPERTIES LINKER_LANGUAGE CXX)
534
+ endif()
535
+
531
536
if(${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
532
537
target_link_options(${name} PRIVATE
533
538
" LINKER:-compatibility_version,1 ")
@@ -536,8 +541,24 @@ function(add_swift_host_library name)
536
541
" LINKER:-current_version,${SWIFT_COMPILER_VERSION} ")
537
542
endif()
538
543
539
- # For now turn off in swift targets, debug info if we are compiling a static
540
- # library.
544
+ # If we found a swift compiler and are going to use swift code in swift
545
+ # host side tools but link with clang, add the appropriate -L paths so we
546
+ # find all of the necessary swift libraries on Darwin.
547
+ if (NOT ASHL_PURE_SWIFT)
548
+ if (CMAKE_Swift_COMPILER)
549
+ # Add in the SDK directory for the host platform and add an rpath.
550
+ target_link_directories(${name} PRIVATE
551
+ ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _ARCH_${SWIFT_HOST_VARIANT_ARCH} _PATH}/usr/lib/swift)
552
+ # Add in the toolchain directory so we can grab compatibility libraries
553
+ get_filename_component(TOOLCHAIN_BIN_DIR ${CMAKE_Swift_COMPILER} DIRECTORY)
554
+ get_filename_component(TOOLCHAIN_LIB_DIR " ${TOOLCHAIN_BIN_DIR} /../lib/swift/macosx " ABSOLUTE)
555
+ target_link_directories(${name} PUBLIC ${TOOLCHAIN_LIB_DIR} )
556
+ endif()
557
+ endif()
558
+
559
+ # For now turn off on Darwin swift targets, debug info if we are compiling a static
560
+ # library and set up an rpath so that if someone works around this by using
561
+ # shared libraries that in the short term we can find shared libraries.
541
562
if (ASHL_STATIC)
542
563
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-gnone>)
543
564
endif()
@@ -605,9 +626,23 @@ function(add_swift_host_tool executable)
605
626
JOB_POOL_LINK swift_link_job_pool)
606
627
endif()
607
628
if(${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
629
+ # Lists of rpaths that we are going to add to our executables.
630
+ #
631
+ # Please add each rpath separately below to the list, explaining why you are
632
+ # adding it.
633
+ set(RPATH_LIST)
634
+
635
+ # We also want to be able to find libraries from the base toolchain
636
+ # directory. This is so swiftc can rely on its own host side dylibs that may
637
+ # contain swift content.
638
+ list(APPEND RPATH_LIST " @executable_path/../lib ")
639
+
640
+ # Also include the swift specific resource dir in our rpath.
641
+ list(APPEND RPATH_LIST " @executable_path/../lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR} ")
642
+
608
643
set_target_properties(${executable} PROPERTIES
609
644
BUILD_WITH_INSTALL_RPATH YES
610
- INSTALL_RPATH " @executable_path/../lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR }")
645
+ INSTALL_RPATH " ${RPATH_LIST }")
611
646
endif()
612
647
613
648
llvm_update_compile_flags(${executable} )
0 commit comments