Skip to content

libswift: fixes for the linux bootstrapping build #39973

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

Merged
Merged
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
12 changes: 9 additions & 3 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -741,9 +741,12 @@ function(add_libswift name)

get_bootstrapping_path(build_dir ${CMAKE_CURRENT_BINARY_DIR} "${ALS_BOOTSTRAPPING}")

set(sdk_option "")

if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
set(deployment_version "10.15") # TODO: once #38675 lands, replace this with
# set(deployment_version "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}")
set(sdk_option "-sdk" "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}")
endif()
get_versioned_target_triple(target ${SWIFT_HOST_VARIANT_SDK}
${SWIFT_HOST_VARIANT_ARCH} "${deployment_version}")
Expand Down Expand Up @@ -777,7 +780,7 @@ function(add_libswift name)
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${sources} ${deps} ${ALS_DEPENDS}
COMMAND ${ALS_SWIFT_EXEC} "-c" "-o" ${module_obj_file}
"-sdk" "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}"
${sdk_option}
"-target" ${target}
"-module-name" ${module} "-emit-module"
"-emit-module-path" "${build_dir}/${module}.swiftmodule"
Expand Down Expand Up @@ -980,8 +983,11 @@ function(add_swift_host_tool executable)
elseif(LIBSWIFT_BUILD_MODE STREQUAL "BOOTSTRAPPING")
# At build time link against the built swift libraries from the
# previous bootstrapping stage.
get_bootstrapping_swift_lib_dir(bs_lib_dir "${ASHT_BOOTSTRAPPING}")
target_link_directories(${executable} PRIVATE ${bs_lib_dir})
if (NOT "${ASHT_BOOTSTRAPPING}" STREQUAL "0")
get_bootstrapping_swift_lib_dir(bs_lib_dir "${ASHT_BOOTSTRAPPING}")
target_link_directories(${executable} PRIVATE ${bs_lib_dir})
target_link_libraries(${executable} PRIVATE "swiftCore")
endif()

# At runtime link against the built swift libraries from the current
# bootstrapping stage.
Expand Down
15 changes: 15 additions & 0 deletions libswift/Sources/SIL/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ extension BridgedStringRef {
}
}

#if os(Linux)

extension std.__cxx11.string {
public var string: String {
// TODO: remove this once a new version of Swift is released (and call
// c_str() directly).
let mutableSelf = self
return String(cString: mutableSelf.c_str())
}
}

#else

extension std.__1.string {
public var string: String {
// TODO: remove this once a new version of Swift is released (and call
Expand All @@ -90,6 +103,8 @@ extension std.__1.string {
}
}

#endif

extension String {
public func withBridgedStringRef<T>(_ c: (BridgedStringRef) -> T) -> T {
var str = self
Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ set(swiftDarwin_common_options
DEPENDS ${darwin_depends})


if(${LIBSWIFT_BUILD_MODE} STREQUAL "BOOTSTRAPPING")
if(${LIBSWIFT_BUILD_MODE} STREQUAL "BOOTSTRAPPING" AND
${SWIFT_HOST_VARIANT_SDK} IN_LIST SWIFT_DARWIN_PLATFORMS)

set(swiftDarwin_common_bootstrapping_options
${swiftDarwin_common_options}
Expand Down