diff --git a/stdlib/public/Platform/SwiftAndroidNDK.h b/stdlib/public/Platform/SwiftAndroidNDK.h index 791ac40ec4336..4d294ef96ad51 100644 --- a/stdlib/public/Platform/SwiftAndroidNDK.h +++ b/stdlib/public/Platform/SwiftAndroidNDK.h @@ -24,7 +24,14 @@ #include #include #include +#ifdef __cplusplus +// The Android r26 NDK contains an old libc++ modulemap that requires C++23 +// for 'stdatomic', which can't be imported unless we're using C++23. Thus, +// import stdatomic from the NDK directly, bypassing the stdatomic from the libc++. +#pragma clang module import _stdatomic +#else #include +#endif #include #include #include diff --git a/stdlib/public/Platform/SwiftBionic.h b/stdlib/public/Platform/SwiftBionic.h index b3e173030f18b..af4652d5ca7e6 100644 --- a/stdlib/public/Platform/SwiftBionic.h +++ b/stdlib/public/Platform/SwiftBionic.h @@ -24,7 +24,14 @@ #include #include #include +#ifdef __cplusplus +// The Android r26 NDK contains an old libc++ modulemap that requires C++23 +// for 'stdatomic', which can't be imported unless we're using C++23. Thus, +// import stdatomic from the NDK directly, bypassing the stdatomic from the libc++. +#pragma clang module import _stdatomic +#else #include +#endif #include #include #include diff --git a/test/Interop/Cxx/stdlib/android-and-std-module.swift b/test/Interop/Cxx/stdlib/android-and-std-module.swift new file mode 100644 index 0000000000000..cff4db5e70ae8 --- /dev/null +++ b/test/Interop/Cxx/stdlib/android-and-std-module.swift @@ -0,0 +1,29 @@ +// RUN: %empty-directory(%t) +// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++14 -Xcc -fmodules-cache-path=%t +// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t +// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t + +// RUN: find %t | %FileCheck %s + +// RUN: %empty-directory(%t) + +// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++17 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB +// RUN: %target-swift-frontend %s -c -cxx-interoperability-mode=default -Xcc -std=c++20 -Xcc -fmodules-cache-path=%t -DADD_CXXSTDLIB + +// REQUIRES: OS=linux-android + +import Android +import Bionic + +#if ADD_CXXSTDLIB +import CxxStdlib +#endif + +func test() { +#if ADD_CXXSTDLIB + let _ = std.string() +#endif +} + +// CHECK-DAG: Android{{.*}}.pcm +// CHECK-DAG: std{{.*}}.pcm