Skip to content

[Cxx] Make C++ flags configurable for Linux SDK #59764

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 1 commit into from
Jun 29, 2022
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
15 changes: 15 additions & 0 deletions cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,21 @@ macro(configure_sdk_unix name architectures)
endif()
set(SWIFT_SDK_${prefix}_USE_ISYSROOT FALSE)

# GCC on Linux is usually located under `/usr`.
# However, Ubuntu 20.04 ships with another GCC installation under `/`, which
# does not include libstdc++. Swift build scripts pass `--sysroot=/` to
# Clang. By default, Clang tries to find GCC installation under sysroot, and
# if it doesn't exist, under `{sysroot}/usr`. On Ubuntu 20.04 and newer, it
# attempts to use the GCC without the C++ stdlib, which causes a build
# failure. To fix that, we tell Clang explicitly to use GCC from `/usr`.
# FIXME: This is a compromise. The value might depend on the architecture
# but add_swift_target_library does not allow passing different values
# depending on the architecture, so having a single value is the only
# possibility right now.
set(SWIFT_SDK_${prefix}_CXX_OVERLAY_SWIFT_COMPILE_FLAGS
-Xcc --gcc-toolchain=/usr
CACHE STRING "Extra flags for compiling the C++ overlay")

foreach(arch ${architectures})
if("${prefix}" STREQUAL "ANDROID")
swift_android_sysroot(android_sysroot)
Expand Down
7 changes: 1 addition & 6 deletions stdlib/public/Cxx/std/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,7 @@ add_swift_target_library(swiftstd ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVE
-Xfrontend -module-interface-preserve-types-as-written

SWIFT_COMPILE_FLAGS_LINUX
# GCC on Linux is usually located under `/usr`.
# However, Ubuntu 20.04 ships with another GCC installation under `/`, which does not include libstdc++.
# Swift build scripts pass `--sysroot=/` to Clang. By default, Clang tries to find GCC installation under sysroot,
# and if it doesn't exist, under `{sysroot}/usr`. On Ubuntu 20.04 and newer, it attempts to use the GCC without the
# C++ stdlib, which causes a build failure. To fix that, we tell Clang explicitly to use GCC from `/usr`.
-Xcc --gcc-toolchain=/usr
${SWIFT_SDK_LINUX_CXX_OVERLAY_SWIFT_COMPILE_FLAGS}

LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS ALL_APPLE_PLATFORMS LINUX
Expand Down