Commit Graph

74 Commits

Author SHA1 Message Date
Ian Anderson
15345ef2d5 [CMake][Darwin] Remove support for building the SDK overlays on Apple platforms
The SDK overlays have been provided in the Apple SDKs for many years, and the interface and implementation has diverged in more recent years such that trying to build the Swift version no longer works. Remove all of the dead code.

rdar://151889154
2025-05-23 23:38:08 -07:00
Alastair Houghton
b2f0d92eaa [Cxx] Build the C++ interop support library for the Static SDK for Linux.
We need the C++ interop support library to make the build work, as
the Runtime module uses C++ interop.

(Also, we should build it, because some user programs might want to
use C++ interop.)

rdar://147201087
2025-05-15 14:30:12 +01:00
Egor Zhdan
16b280862a [cxx-interop] Do not install binary .swiftmodule files for the overlays
This fixes a deserialization failure in the compiler that occurred while loading the CxxStdlib overlay module:
```
Cross-reference to module 'Swift'
... Optional
... some
... with type <τ_0_0 where τ_0_0 : ~Copyable, τ_0_0 : ~Escapable> (Optional<τ_0_0>.Type) -> (τ_0_0) -> Optional<τ_0_0>
```

This was happening because the overlays were built against a different version of the Swift stdlib than is being used. The compiler is able to rebuild the Cxx and CxxStdlib modules from their textual interfaces. Let's use that feature unconditionally in production toolchains to avoid this kind of binary incompatibilities.

rdar://150416863
2025-05-10 22:55:06 +01:00
Doug Gregor
0100104ff7 [stdlib] Reinstate AllowUnsafeAttribute experimental feature on libraries
We need this so that older compilers can handle the .swiftinterface
files we generate. It's unnecessary for newer compilers and can be
removed later.

Fixes rdar://148529962.
2025-04-03 18:07:19 -07:00
Allan Shortlidge
c6cbcd8553 stdlib: Address StrictMemorySafety warnings in Cxx String related code. 2025-03-31 16:45:08 -07:00
Egor Zhdan
e32e64353f [cxx-interop] Conform std::string to ExpressibleByStringInterpolation
This adds conformances for C++ string types (`std::string`, `std::u16string`, `std::u32string`) to `Swift.ExpressibleByStringInterpolation`.

These conformances currently implicitly use `DefaultStringInterpolation`. In the future we can provide more performant interpolation mechanisms for C++ strings specifically that avoid the extra conversion between Swift String and C++ string types.

rdar://147249169
2025-03-18 15:54:56 +00:00
Doug Gregor
89d0277a35 Enable strict memory safety in the Cxx/CxxStdlib modules 2025-02-26 14:28:30 -08:00
Gábor Horváth
8398e693e7 Merge pull request #77700 from swiftlang/gaborh/span-conversion
[cxx-interop] Explicit conversions between Swift and C++ spans
2024-12-13 19:54:27 +00:00
Gabor Horvath
b6cc118f71 [cxx-interop] Explicit conversions between Swift and C++ spans
A first step towards creating safe overloads for C++ APIs using span
(rdar://139074571).

Note that we need to mark span as owned because it the libc++
implementation was mistakenly recognized as owned and might now rely on
span methods like `data` being renamed as `__dataUnsafe`. We will change
it under a new interop version. But for the time being, we want
consistent behavior across stdlib versions.
2024-12-13 16:01:02 +00:00
Alex Lorenz
9c44e01e07 [cxx-interop][stdlib] windows - use new hash inline functions like other platforms
The PR https://github.com/swiftlang/swift/pull/77857 added windows-specific workaround for https://github.com/swiftlang/swift/issues/77856, that happened after https://github.com/swiftlang/swift/pull/77843. Unfortunately this caused a new issue on windows - https://github.com/swiftlang/swift/issues/78119. It looks like windows is suffering from a similar serialization issue as libstdc++, although its even more complex as the callAsFunction is not only a derived function from a base class, the base class although has a static call operator. In any case, the libstdc++ callAsFunction deserialization fix should align with the static operator () deserialization too, so for now make windows use the same workaround as other platforms to avoid the deserialization crash (77856).

This change was tested on i686 windows too, ensuring that IR verifier crash no longer happens
2024-12-12 23:17:17 -08:00
Egor Zhdan
d5f7f6f3ff Merge pull request #77927 from swiftlang/egorzhdan/bring-back-overlay-flag
[cxx-interop] Bring back `AssumeResilientCxxTypes` flag for CxxStdlib overlay
2024-12-04 13:01:44 +00:00
Egor Zhdan
b6488d3c8c [cxx-interop] Bring back AssumeResilientCxxTypes flag for CxxStdlib overlay
This fixes a CI job that is building the Swift stdlib with a recent nightly compiler.

rdar://140850172
2024-12-03 18:52:45 +00:00
Egor Zhdan
22141b1118 [cxx-interop] Lower iOS deployment target for Cxx and CxxStdlib
The iOS/watchOS/tvOS deployment targets for Cxx and CxxStdlib binaries got unintentionally bumped in b87b263.

This reverts the deployment targets to the older versions.

rdar://140823785 / resolves https://github.com/swiftlang/swift/issues/77909
2024-12-03 16:39:59 +00:00
Egor Zhdan
f420456899 [cxx-interop] Allow using non-resilient C++ symbols in resilient overlays
If a Swift module built with library evolution enabled is an overlay of a C++ module, allow referring to the non-resilient C++ symbols from the Swift code.

Overlays are usually built and shipped along with the C/C++ modules, so library evolution is less of a concern there. A developer providing a Swift overlay for a C++ library would expect to be able to refer to the symbols from the C++ library within the overlay.
2024-12-02 19:44:32 +00:00
Egor Zhdan
7473eae623 [cxx-interop] Workaround a compiler crash for CxxStdlib on Windows
This is a workaround for https://github.com/swiftlang/swift/issues/77856.

rdar://140358388
2024-11-27 17:01:33 +00:00
Egor Zhdan
c57756168f [cxx-interop] Workaround a deserialization error for CxxStdlib on Linux
In certain versions of libstdc++, `std::hash<std::string>` defines `operator()` in a base class. It looks like Swift is not correctly deserializing an inherited `operator()` for inlinable functions. This change sidesteps the issue by moving the call to `callAsFunction`/`operator()` to the C++ shim layer.

rdar://140358388
2024-11-26 16:27:05 +00:00
Egor Zhdan
fb529ff0ce [cxx-interop] Mark all CxxStdlib APIs as @_alwaysEmitIntoClient
The change in 269fc941 turned out not to be enough to solve linker errors when using the CxxStdlib overlay with a non-default C++ stdlib.

In addition to `@inlinable`, the Swift functions in the overlay need to be `@_alwaysEmitIntoClient` to prevent Swift from trying to link a program that uses libc++ on Linux against the CxxStdlib binary shipped in the toolchain.

rdar://138838506
2024-11-21 17:09:33 +00:00
Egor Zhdan
269fc941de [cxx-interop] Mark all CxxStdlib APIs as @inlinable
This is a requirement for being able to use the CxxStdlib overlay with a C++ standard library which is not the platform default, specifically libc++ on Linux.

The module would get rebuilt from its textual interface (`CxxStdlib.swiftinterface`) by the compiler whenever a custom C++ stdlib is used. Since the mangled names of C++ stdlib symbols differ across implementations (libc++ vs libstdc++), a Swift program that uses these overlay functions would fail to link, unless the definitions of these functions are available.

rdar://138838506
2024-11-20 22:33:18 +00:00
Egor Zhdan
242fe5cfac Merge pull request #77677 from swiftlang/egorzhdan/cxxstdlib-builtin-float
[cxx-interop] Declare CxxStdlib dependency on _Builtin_float
2024-11-19 12:57:53 +00:00
Allan Shortlidge
c9c36732be stdlib: Enable upcoming MemberImportVisibility feature.
It was already supposed to be enabled, but I forgot to update the CMake when I
renamed the feature from ExtensionImportVisibility to MemberImportVisibility.

However, leave it disabled on the CxxStdlib module since the C++ standard
library's modularization varies a lot by platform, making it difficult to add
the right conditional imports.
2024-11-18 10:27:14 -08:00
Egor Zhdan
72425fa750 [cxx-interop] Declare CxxStdlib dependency on _Builtin_float
This fixes incremental builds of the overlay.

The CxxStdlib overlay re-exports the entire C++ standard library, which has headers that transitively include Clang builtin headers, bringing in the _Builtin_float module.

rdar://140036608
2024-11-18 13:01:31 +00:00
Egor Zhdan
703e479135 [cxx-interop] Make Cxx and CxxStdlib libraries resilient
This enables library evolution for the two libraries that form the Swift overlay for the C++ standard library.

rdar://129169673
2024-11-12 17:22:03 +00:00
Egor Zhdan
cb486c6599 [cxx-interop] Allow creating a String from std::string_view
This adds overlay support for initializing a Swift String from C++ `std::string_view`, `std::u16string_view`, `std::u32string_view`.

rdar://138417835
2024-10-24 13:11:09 +01:00
Shreyans Pathak
49d9067d3e feat: add comparable conformance for C++ strings 2024-09-03 13:47:27 -04:00
Alex Lorenz
c8fa166e58 [cxx][windows] fix the CxxStdlib build for recent MSVC versions after recent regression
The build regressed after cbaef38968 as newer versions of MSVC that aren't used in the OSS CI yet fail to build CxxStdlib now
2024-08-19 10:55:22 -07:00
Crazy凡
cbaef38968 [c++-interop] Improve performance of creating a C++ std::string from a contiguous UTF-8 Swift.String 2024-08-13 13:58:56 +08:00
Egor Zhdan
b0a3bb10f0 [cxx-interop] Build Cxx and CxxStdlib modules for macCatalyst
This enables building the C++ stdlib overlays (`Cxx.swiftmodule` and `CxxStdlib.swiftmodule`) for the Mac Catalyst target.

rdar://126938813
2024-07-05 19:35:29 +01:00
Alex Lorenz
273edcf2a2 build CxxStdlib for Android too 2024-06-04 15:46:39 -07:00
Egor Zhdan
4513ca2447 [cxx-interop] Faster std::string initialization from String
Instead of appending characters one-by-one, which resizes the resulting string multiple times, let's reserve the required number of bytes beforehand.

rdar://127423949
2024-05-02 14:07:07 +01:00
Artem Chikin
1f14158a1d Introduce VisionOS Platform
This change introduces a new compilation target platform to the Swift compiler - visionOS.

- Changes to the compiler build infrastrucuture to support building compiler-adjacent artifacts and test suites for the new target.
- Addition of the new platform kind definition.
- Support for the new platform in language constructs such as compile-time availability annotations or runtime OS version queries.
- Utilities to read out Darwin platform SDK info containing platform mapping data.
- Utilities to support re-mapping availability annotations from iOS to visionOS (e.g. 'updateIntroducedPlatformForFallback', 'updateDeprecatedPlatformForFallback', 'updateObsoletedPlatformForFallback').
- Additional tests exercising platform-specific availability handling and availability re-mapping fallback code-path.
- Changes to existing test suite to accomodate the new platform.
2024-04-10 09:38:02 -07:00
Egor Zhdan
53fb6531f2 [cxx-interop] Add conversions between std::chrono::duration and Swift.Duration
rdar://123696734
2024-03-01 13:15:05 +00:00
Egor Zhdan
c39c8da4db [cxx-interop] Use APINotes to apply import_owned attr to std::string and std::vector
This removes a special case in the compiler for these types, and applies the `import_owned` attribute to all instantiations of `vector` and `basic_string` via API Notes.
2023-12-04 19:54:17 +00:00
Egor Zhdan
e144f607d7 [cxx-interop] Migrate to overlay the new compiler flag
`-enable-experimental-cxx-interop` is deprecated, the new flag for enabling C++ interop is `-cxx-interoperability-mode=enabled`.

NFC intended.
2023-11-28 20:30:12 +00:00
Egor Zhdan
00cdb66d01 [cxx-interop] Lower macOS deployment target version for the Cxx module
The Cxx module does not rely on any modern OS features. It can be deployed to older macOS versions.

rdar://117699474
2023-10-30 19:22:02 +00:00
Ian Anderson
4dbc58723a [CMake] [Darwin] Don't add the Darwin overlay as a dependency if the overlays aren't being built
Allow for the overlays to not be built in Darwin by respecting SWIFT_BUILD_SDK_OVERLAY.
2023-10-17 11:03:57 -07:00
Crazy凡
02a9259dda [cxx-interop] Provide similar support for std::u32string as std::string and std::u16string. 2023-10-10 16:01:15 +08:00
Rintaro Ishizaki
064cb34015 [CMake] Use add_custom_command_target for copying std.apinotes
`COMMAND` for `add_custom_target` are "always considered out of date"
and executed everytime. Because of that, targets depends on that were
alway marked "dirty". Use `add_custom_command_target` instead.
2023-09-14 16:52:43 -07:00
Egor Zhdan
9b7dbf2599 [cxx-interop] Introduce APINotes file for C++ stdlib
This adds an `std.apinotes` file that is installed into `lib/swift/apinotes` along with existing Darwin apinotes. This new file is installed on all platforms. It replaces a few special cases in the compiler for `cmath` and `cstring` functions.

This does not require the upcoming APINotes support for namespaces, however, this does require https://github.com/apple/llvm-project/pull/7309.

rdar://107572302
2023-08-29 23:34:36 +01:00
Saleem Abdulrasool
2124c01e74 stdlib: enable CxxStdlib module on Windows
Enable this module on Windows for enabling C++ Interop.
2023-08-04 21:19:35 -07:00
Alex Lorenz
3748b0ff1c Merge pull request #65129 from hyp/eng/no-evo-cxx
[interop] Prohibit use of C++ APIs in public interfaces that opt-in i…
2023-07-19 08:10:23 -07:00
Egor Zhdan
6cd4b7c28f [cxx-interop] Make std::string::append usable from Swift
This adds a new Swift overload for `append` that takes another `std::string` as a parameter.

The original C++ overload for `append` is not exposed into Swift because it returns a mutable reference `string&`.

rdar://107018724
2023-06-19 20:51:27 +01:00
Egor Zhdan
60c91aa90a [cxx-interop] Declare CxxStdlib dependency on Darwin when building both
rdar://108188270
2023-06-07 20:17:24 +01:00
Egor Zhdan
b5866040ae [cxx-interop] Fix Linux build with SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP=NO
This fixes the Swift LSAN CI job Linux (https://ci.swift.org/job/oss-swift-RA-lsan-linux-ubuntu-18_04/) that started failing after https://github.com/apple/swift/pull/65398.

rdar://108674065
2023-05-02 17:35:29 +01:00
Egor Zhdan
030313213c [cxx-interop] Add missing dependency to CxxStdlib
The CxxStdlib module now relies on the libcxxshim modulemap, so we
need to make sure that the modulemap is copied into the correct location before CxxStdlib is built.

rdar://108007693
2023-04-13 20:28:24 +01:00
Alex Lorenz
045fcf3ff5 [interop] Prohibit use of C++ APIs in public interfaces that opt-in into library evolution
The CxxStdlib overlay now has to be built without library evolution enabled.
2023-04-13 10:48:09 -07:00
Egor Zhdan
7774650db1 [cxx-interop] Fix CxxStdlib build error on CentOS
This fixes a build failure that started occurring on CentOS after https://github.com/apple/swift/pull/65057:
```
error: cannot find 'strlen' in scope
```

rdar://107987115
2023-04-13 13:42:46 +01:00
Puyan Lotfi
6180387a05 [cxx-interop] Adding std.string initializer for UnsafePointer<CChar>?
Currently without an initializer for the unsafe char pointer type swiftc
hits an assert around not being able to handle conversions of unsafe
pointers with Any type. This patch adds the ability to convert to a
std::string.

This is to address issue https://github.com/apple/swift/issues/61218
2023-04-12 22:03:57 -04:00
Egor Zhdan
14f32312bf [cxx-interop] Do not add a dependency on clang to CxxStdlib
Cxx & CxxStdlib modules are Swift-only, they do not require invoking clang directly.

When building with `SWIFT_INCLUDE_TOOLS=NO`, Clang is not available as a CMake target (see `swift_common_standalone_build_config`).

rdar://107780733
2023-04-11 16:45:39 +01:00
Egor Zhdan
242a432919 [cxx-interop] Conform std::string to Hashable
rdar://107709149
2023-04-06 16:15:40 +01:00
Egor Zhdan
416e2e17df [cxx-interop] Remove CxxStdlib dependency on Darwin
This was causing build errors when building the compiler and the stdlib separately.

rdar://107290998
2023-03-28 16:16:04 +01:00