Skip to content

Commit 8839741

Browse files
authored
Merge pull request swiftlang#25471 from compnerd/standard-no-standard
build: use `LINKER_LANGUAGE` to control linking on Android
2 parents 9feac71 + c1c5ee9 commit 8839741

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,8 @@ function(_add_variant_link_flags)
463463
list(APPEND result "-Wl,-Bsymbolic")
464464
elseif("${LFLAGS_SDK}" STREQUAL "ANDROID")
465465
list(APPEND link_libraries "dl" "log" "atomic" "icudataswift" "icui18nswift" "icuucswift")
466-
# We provide our own C++ below, so we ask the linker not to do it. However,
467-
# we need to add the math library, which is linked implicitly by libc++.
468-
list(APPEND result "-nostdlib++" "-lm")
466+
# We need to add the math library, which is linked implicitly by libc++
467+
list(APPEND result "-lm")
469468
if("${LFLAGS_ARCH}" MATCHES armv7)
470469
set(android_libcxx_path "${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a")
471470
elseif("${LFLAGS_ARCH}" MATCHES aarch64)
@@ -1371,8 +1370,16 @@ function(_add_swift_library_single target name)
13711370
${SWIFTLIB_SINGLE_PRIVATE_LINK_LIBRARIES})
13721371
endif()
13731372

1374-
set_property(TARGET "${target}" PROPERTY
1373+
# NOTE(compnerd) use the C linker language to invoke `clang` rather than
1374+
# `clang++` as we explicitly link against the C++ runtime. We were previously
1375+
# actually passing `-nostdlib++` to avoid the C++ runtime linkage.
1376+
if(SWIFTLIB_SINGLE_SDK STREQUAL ANDROID)
1377+
set_property(TARGET "${target}" PROPERTY
1378+
LINKER_LANGUAGE "C")
1379+
else()
1380+
set_property(TARGET "${target}" PROPERTY
13751381
LINKER_LANGUAGE "CXX")
1382+
endif()
13761383

13771384
if(target_static)
13781385
set_property(TARGET "${target_static}" APPEND_STRING PROPERTY

0 commit comments

Comments
 (0)