Skip to content

[6.0 🍒][CMake] Establish a dependency from standard library variants onto 'libSwiftScan' #77704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,8 @@ option(SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS
debugging Swift)"
FALSE)

option(BOOTSTRAPPING_MODE [=[
set(BOOTSTRAPPING_MODE HOSTTOOLS CACHE STRING [=[
How to build the swift compiler modules. Possible values are
OFF: build without swift modules
HOSTTOOLS: build with a pre-installed toolchain
BOOTSTRAPPING: build with a 2-stage bootstrapping process
BOOTSTRAPPING-WITH-HOSTLIBS: build with a 2-stage bootstrapping process,
Expand All @@ -362,7 +361,7 @@ How to build the swift compiler modules. Possible values are
`SWIFT_NATIVE_SWIFT_TOOLS_PATH` (non-Darwin only)
CROSSCOMPILE-WITH-HOSTLIBS: build with a bootstrapping-with-hostlibs compiled
compiler, provided in `SWIFT_NATIVE_SWIFT_TOOLS_PATH`
]=] OFF)
]=])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we should be removing OFF here. I'm actually trying to get it working again in #77815 :)


option(BRIDGING_MODE [=[
How swift-C++ bridging code is compiled:
Expand Down Expand Up @@ -1430,6 +1429,10 @@ if(SWIFT_ENABLE_DISPATCH)
endif()

# Add all of the subdirectories, where we actually do work.
add_subdirectory(include)
if(SWIFT_INCLUDE_TOOLS)
add_subdirectory(lib)
endif()

###############
# PLEASE READ #
Expand Down Expand Up @@ -1482,11 +1485,7 @@ if(SWIFT_INCLUDE_APINOTES)
add_subdirectory(apinotes)
endif()

add_subdirectory(include)

if(SWIFT_INCLUDE_TOOLS)
add_subdirectory(lib)

add_subdirectory(SwiftCompilerSources)

# Always include this after including stdlib/!
Expand Down
24 changes: 14 additions & 10 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,20 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)

set(sdk_dir "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}/usr/lib/swift")

# HostCompatibilityLibs is defined as an interface library that
# does not generate any concrete build target
# (https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries)
# In order to specify a dependency to it using `add_dependencies`
# we need to manually "expand" its underlying targets
get_property(compatibility_libs
TARGET HostCompatibilityLibs
PROPERTY INTERFACE_LINK_LIBRARIES)
set(compatibility_libs_path
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH}")
# Note we only check this for bootstrapping, since you ought to
# be able to build using hosttools with the stdlib disabled.
if(ASRLF_BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
# HostCompatibilityLibs is defined as an interface library that
# does not generate any concrete build target
# (https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries)
# In order to specify a dependency to it using `add_dependencies`
# we need to manually "expand" its underlying targets
get_property(compatibility_libs
TARGET HostCompatibilityLibs
PROPERTY INTERFACE_LINK_LIBRARIES)
set(compatibility_libs_path
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH}")
endif()

# If we found a swift compiler and are going to use swift code in swift
# host side tools but link with clang, add the appropriate -L paths so we
Expand Down
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ add_subdirectory(StaticMirror)
add_subdirectory(SymbolGraphGen)
add_subdirectory(SwiftSyntax)
add_subdirectory(Threading)
add_subdirectory(Tooling)

if(SWIFT_BUILD_EXTERNAL_GENERIC_METADATA_BUILDER)
add_subdirectory(ExternalGenericMetadataBuilder)
Expand Down
1 change: 1 addition & 0 deletions lib/Tooling/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_swift_tool_subdirectory(libSwiftScan)
14 changes: 8 additions & 6 deletions stdlib/public/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,6 @@ elseif(SWIFT_PRIMARY_VARIANT_SDK STREQUAL "WINDOWS")
list(APPEND swift_core_private_link_libraries shell32;DbgHelp;Synchronization)
endif()

# There is a race condition with building the 'tools' CMake build of the compiler,
# which produces libSwiftScan that the compiler building the standard library may attempt to use.
# Since the current build system makes establishing this dependency relationship exceedingly difficult,
# we attempt to work around it by disabling use of 'libSwiftScan' here.
list(APPEND swift_stdlib_compile_flags "-nonlib-dependency-scanner")
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
list(APPEND swift_stdlib_compile_flags "-Xllvm" "-sil-inline-generics")
list(APPEND swift_stdlib_compile_flags "-Xllvm" "-sil-partial-specialization")
Expand Down Expand Up @@ -403,12 +398,18 @@ if(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
BOOTSTRAPPING 1)
endif()

set(tooling_stdlib_deps)
if(TARGET libSwiftScan)
list(APPEND tooling_stdlib_deps libSwiftScan)
endif()

add_swift_target_library(swiftCore
${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
${swiftCore_common_options}
${compile_flags_for_final_build}
FILE_DEPENDS
${swiftCore_common_dependencies}
DEPENDS ${tooling_stdlib_deps}
INSTALL_IN_COMPONENT
stdlib
MACCATALYST_BUILD_FLAVOR
Expand Down Expand Up @@ -444,11 +445,12 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
GYB_SOURCES ${SWIFTLIB_EMBEDDED_GYB_SOURCES}
SWIFT_COMPILE_FLAGS
${swift_stdlib_compile_flags} -Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding -enable-experimental-feature Embedded
-Xfrontend -enable-ossa-modules -nonlib-dependency-scanner
-Xfrontend -enable-ossa-modules
MODULE_DIR "${CMAKE_BINARY_DIR}/lib/swift/embedded"
SDK "embedded"
ARCHITECTURE "${arch}"
FILE_DEPENDS ${swiftCore_common_dependencies}
DEPENDS ${tooling_stdlib_deps}
INSTALL_IN_COMPONENT stdlib
)
add_dependencies(embedded-stdlib embedded-stdlib-${mod})
Expand Down
1 change: 0 additions & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ add_swift_tool_subdirectory(swift-def-to-strings-converter)
add_swift_tool_subdirectory(swift-serialize-diagnostics)
add_swift_tool_subdirectory(swift-ast-script)
add_swift_tool_subdirectory(swift-refactor)
add_swift_tool_subdirectory(libSwiftScan)
add_swift_tool_subdirectory(libStaticMirror)
add_swift_tool_subdirectory(libMockPlugin)
add_swift_tool_subdirectory(swift-plugin-server)
Expand Down