Commit Graph

120 Commits

Author SHA1 Message Date
zoecarver
8cf4d3b983 [cxx-interop] Disable cxxshim on windows until we can figure out cmakeconfig. 2022-07-05 20:03:45 -07:00
zoecarver
3805828ad0 [cxx-interop] Add CxxShim library; move __swift_interopStaticCast into it. 2022-07-05 15:52:51 -07:00
Daniel Rodríguez Troitiño
036e16810a [Cxx] Make C++ flags configurable for Linux SDK (#59764)
Allow Linux distributions to provide their own C++ flags to compile the
C++ overlay correctly. The default is kept the same for Ubuntu and
CentOS, but other distributions can provide other flags to use their own
distro GCC stdlibc++ or even libc++ if they choose.

This should not change the current compilation, but opens the door for
other maintainers to provide a different value that work on their
systems.
2022-06-29 08:54:56 -07:00
Egor Zhdan
82a90b90aa [cxx-interop] Split C++ stdlib overlay into two modules
This allows projects that don't want to pull in the entire C++ standard library to use stdlib-independent C++ interop utilities like `CxxSequence`.
This also makes the utilities available on platforms where we don't currently have the `std` overlay available, e.g. Windows.
2022-06-28 15:37:20 +01:00
Egor Zhdan
6754c3cf82 [cxx-interop] Add CxxSequence protocol to the stdlib overlay
This change adds basic helper protocols and structs that are going to be used for making C++ sequences and collection safe and Swifty by adding conformances to `Swift.Sequence`, `Swift.Collection`, etc.

This is not meant to be a final design.
2022-06-27 20:40:12 +01:00
Egor Zhdan
0ced5ec070 [cxx-interop] Re-enable C++ stdlib overlay on Linux 2022-06-14 23:28:37 +01:00
Egor Zhdan
a605ec7138 [cxx-interop] Fix libstdc++ build failure on CentOS 7
CentOS 7 is shipped with an outdated version of libstdc++, which does not include `codecvt` stdlib header.
Let's wrap the `#include` with `#if __has_include`.
2022-06-09 12:48:35 +01:00
Alex Hoppen
95481a54bc Revert "Merge pull request #58983 from apple/egorzhdan/cxx-overlay-linux"
This reverts commit 9e69e4dd76, reversing
changes made to 59bb4cb11a.
2022-06-08 08:35:04 +02:00
Egor Zhdan
9e69e4dd76 Merge pull request #58983 from apple/egorzhdan/cxx-overlay-linux
[cxx-interop] Enable C++ stdlib overlay on Linux
2022-06-07 20:53:28 +01:00
Egor Zhdan
737507ea93 [cxx-interop] Fix a potential dangling pointer in String(cxxString:)
`cxxString` might get deallocated immediately after `c_str()` call, which would mean that the pointer passed to `String(cString:)` points to invalid memory.

We haven't actually seen this, but let's preemptively add an explicit `withExtendedLifetime` call to avoid running into this in the future.
2022-06-07 16:58:52 +01:00
Egor Zhdan
bcc07cc4eb [cxx-interop] Enable C++ stdlib overlay on Linux 2022-06-07 16:38:28 +01:00
Egor Zhdan
ff8464fd2a [cxx-interop] Add basic C++ stdlib overlay
This will allow us to add Swift conformances to C++ standard library types, and improve usability of the C++ standard library from Swift.
2022-05-16 13:30:35 +01:00
Egor Zhdan
1ef02efed1 Merge pull request #58843 from apple/egorzhdan/libstdcxx-vfs
[cxx-interop] Use VFS to inject modulemap into libstdc++ installation
2022-05-14 00:40:16 +01:00
Egor Zhdan
20650eab33 [cxx-interop] Add cassert header to libstdc++ modulemap
Previously this header was sometimes getting hijacked by the first header to include it. This caused Swift compiler failures on Linux when using any LLVM header that uses `assert`.

Now `cassert` is referenced directly from a modulemap, which fixes the issue.
2022-05-13 22:21:40 +01:00
Egor Zhdan
f3790def63 [cxx-interop] Use VFS to inject modulemap into libstdc++ installation
Previously the modulemap for the C++ stdlib on Linux was provided via `-fmodule-map-file=` Clang argument pointing to the modulemap file within the Swift toolchain. The modulemap file could not reference the stdlib headers directly, since the exact stdlib include directory varies across Linux versions (it generally looks like `/usr/include/c++/{gcc_version}`). So the modulemap file instead referenced a local header, which `#include <>`-ed the stdlib headers, relying on Clang include resolution.

Unfortunately this did not work properly in the presence of another C++ module which included the stdlib headers: sometimes decls from the stdlib were hijacked by the other module, and were not treated as a part of the stdlib by Clang. This caused compile errors in Swift.

This change uses LLVM VFS to inject the modulemap file into the libstdc++ directory. The modulemap file is now able to reference the stdlib headers directly, which fixes the issue.

Credits to Rintaro Ishizaki for proposing a similar idea for SwiftGlibc back in 2016.
2022-05-13 22:21:40 +01:00
Egor Zhdan
0def240c14 [cxx-interop] Copy libstdc++ resources again if the sources changed
Previously if you changed `libstdcxx.h` or `libstdcxx.modulemap` locally and ran an incremental build, the artifacts weren't updated.
2022-05-13 13:38:03 +01:00
Egor Zhdan
67a28c78d5 [cxx-interop][SwiftCompilerSources] Enable libstdc++ on platforms that use it
Since libstdc++ doesn't come with a Clang modulemap, Swift provides its own modulemap for libstdc++. This change makes the modulemap available while building SwiftCompilerSources.
2022-05-03 19:48:14 +01:00
Butta
a839a69484 [android] Don't generate a libstdcxx.modulemap
Android uses libc++, which already has its own module map.
2022-04-28 23:51:20 +05:30
Egor Zhdan
6efd4c1ecf [cxx-interop] Fix test failures with older libstdc++ 2022-04-08 19:54:05 +01:00
Egor Zhdan
a3e914364a [cxx-interop] Import libstdc++ as a Clang module
This change adds a module map for libstdc++, which allows it to be properly imported into Swift as a module. The module map is installed into `usr/lib/swift/linux/{arch}` similarly to `glibc.modulemap`, and is passed to Clang as `-fmodule-map-file`.

That means it is now possible to import std directly from Swift on Linux, when C++ interop is enabled.

The module map currently declares a single `std` module without splitting the headers into submodules. This is going to change in the near future.

rdar://87654514
2022-04-08 14:10:04 +01:00