Commit Graph

36 Commits

Author SHA1 Message Date
Kuba Mracek
a02586f1f2 [embedded] Include and use cxxshims in the embedded/ resource dir 2024-12-12 12:12:11 -08:00
Egor Zhdan
9472c4ca08 [cxx-interop] Avoid "libstdc++ not found" warning when -nostdinc++ is passed
When explicitly asked not to load the C++ standard library, Swift should not emit warnings for missing libstdc++.

This fixes a compiler warning when building the Cxx module on Linux.
2024-12-05 17:51:30 +00:00
Egor Zhdan
16e7cbeafa [cxx-interop] Modularize __msvc_bit_utils on Windows
`__msvc_bit_utils.hpp` was added in a recent version of MSVC, and it is causing build errors for SwiftCompilerSources:
```
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\numeric:598:12: error: function '_Select_countr_zero_impl<unsigned long long, (lambda at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\numeric:598:55)>' with deduced return type cannot be used before it is defined
    return _Select_countr_zero_impl<_Common_unsigned>([=](auto _Countr_zero_impl) {
```

This change references the `__msvc_bit_utils.hpp` header from the modulemap. Since we still need to support older versions of Visual Studio that do not provide `__msvc_bit_utils.hpp`, this also teaches ClangImporter to inject an empty header file named `__msvc_bit_utils.hpp` into the system include directory, unless it already exists.

rdar://137066642
2024-10-04 13:15:20 +01:00
Alastair Houghton
ac750a6aec Merge pull request #76545 from al45tair/eng/PR-115918181
[ClangImporter][ModuleWrap] Turn off libc warnings.
2024-10-01 18:46:06 +01:00
Alastair Houghton
bace89ffbd [ClangImporter] Just turn off the warning, not the actual overlays.
We should still try adding the overlays, even if we're asked not to
generate a diagnostic while doing so.  That's slightly safer because
it means that we're less likely to find ourselves in a situation
where `swift-modulewrap` wants to use types from the C/C++ library
and can't.

rdar://115918181
2024-09-30 17:02:41 +01:00
Daniel Rodríguez Troitiño
fe796b419a [cxx-interop] Use macosx paths when searching modulemaps for macCatalyst (#76735)
The existing code will use paths for "iphoneos" because the triples for
macCatalyst are in the form "<arch>-apple-iosXX.yy-macabi", which the
code interprets as an iPhone triple. This seems to work in Xcode because
the "iphoneos" folder is always there. When building in open source,
this seems to work because it is also normal to have the iPhone SDK
configured. This is not the case if you want to build the macOS SDK in
isolation.

The code changes detect the macCatalyst environment from the triple and
use the "macosx" paths instead, otherwise it follows the same code path
as before. This matches many places in the CMakeLists.txt files in which
macCatalyst support pieces are only enabled when the SDK is macOS.

The modified function is also used for the libc modulemap of non-Darwin
platforms, but for those triples, the macCatalyst environment should not
be detected, so the libc modulemap should not be affected by this
change.

This is a followup to #76260 and #74994.
2024-09-27 10:08:16 -07:00
Finagolfin
b7ec9c8407 [ClangImporter] Make sure the -resource-dir is checked before the -sdk, as done everywhere else in the compiler
Otherwise, these module maps can be pulled from a system SDK instead when
building a fresh Swift stdlib, fixes #74696.
2024-08-22 20:14:01 +05:30
Egor Zhdan
bfe72b4be9 Merge pull request #75589 from swiftlang/egorzhdan/linux-libcxx-interop
[cxx-interop] Allow compiling with libc++ on Linux
2024-08-09 13:42:29 +01:00
Egor Zhdan
059f0f97d1 [cxx-interop] Allow compiling with libc++ on Linux
This makes sure that Swift respects `-Xcc -stdlib=libc++` flags.

Clang already has existing logic to discover the system-wide libc++ installation on Linux. We rely on that logic here.

Importing a Swift module that was built with a different C++ stdlib is not supported and emits an error.

The Cxx module can be imported when compiling with any C++ stdlib. The synthesized conformances, e.g. to CxxRandomAccessCollection also work. However, CxxStdlib currently cannot be imported when compiling with libc++, since on Linux it refers to symbols from libstdc++ which have different mangled names in libc++.

rdar://118357548 / https://github.com/swiftlang/swift/issues/69825
2024-08-08 16:24:58 +01:00
Alex Lorenz
c03627014e [android] fix path and cmake local build target tracking for posix_filesystem.apinotes
This apinote file needs to be accessible in the locally built Android SDK as it's being built with build.ps1, so that swift-foundation can be built with that file present. This change ensures that the file is copied over into the local build directory for that Android SDK, in addition to being included in the installed component

This change also places the component into lib/swift/apinotes, as that's where the clang importer already looks for API notes
2024-07-25 21:25:25 -07:00
Saleem Abdulrasool
c8bec5b12f Driver: introduce -sysroot option for non-Darwin targets
This introduces a secondary flag `-sysroot` for the non-Darwin targets,
primarily Unicies. The intention here is to support a split `-sdk`,
`-sysroot` model where the `-sdk` parameter provides the Swift "SDK"
which augments the native platform's C sysroot which is indicated as
`-sysroot`. For the case of Android, this would allow us to provide a
path to the NDK sysroot and the Swift SDK allowing us to cross-compile
Android binaries from Windows.
2024-07-10 11:03:18 -07:00
Saleem Abdulrasool
47f9d78990 ClangImporter: add support for Android API Notes
Introduce the first APINotes injection for the Android platform. This
follows the VCRuntime pattern of permitting the SDK to provide API Notes
that augment the system SDK. This adds a workaround for incorrect
nullability on the `fts_open` function in bionic. The system library
itself is fixed at:
https://android-review.googlesource.com/c/platform/bionic/+/3151616
2024-06-28 13:24:04 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Alex Lorenz
57b89d5303 [android] add an android NDK Swift overlay module, and use it instead of Glibc 2024-05-28 12:57:38 -07:00
Alastair Houghton
a1f406fd40 [ClangImporter] -Xclang -fbuiltin-headers-in-system-modules is being passed when it shouldn't
We were accidentally setting `requiresBuiltinHeadersInSystemModules` because
the `else` here gets executed for things that are not WASI or Musl.  Fix
by making it conditional.

rdar://128219177
2024-05-22 09:20:02 +01:00
Alastair Houghton
978169f029 [ClangImporter] Don't put built-in headers in system modules for musl.
We only need this for WASI and Glibc.

rdar://123506306
2024-05-07 16:48:56 +01:00
Alastair Houghton
a25cd37750 Add support to the compiler for musl and the LINUX_STATIC SDK.
This is really just about setting appropriate defaults (such as
making sure that the static Linux triple causes us to use lld).

rdar://123506306
2024-05-07 16:48:52 +01:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Ian Anderson
94e860e795 [ClangImporter] Swift needs to pass -Xclang -fbuiltin-headers-in-system-modules for its module maps that group cstd headers
Swift has some module maps it overlays on Linux and Windows that groups all of the C standard library headers into a single module. This doesn’t allow clang and C++ headers to layer properly with the OS/SDK modules. clang will set -fbuiltin-headers-in-system-modules as necessary for Apple SDKs, but Swift will need to pass that flag itself when required by its module maps.
2023-12-08 22:33:12 -08:00
Yuta Saito
643c7c8b49 [wasm][ClangImporter] Support wasi-libc.modulemap import with VFS 2023-09-23 11:52:31 +00:00
Saleem Abdulrasool
eee9331d97 ClangImporter: correct a duplicated path component
When computing the path for a non-architecture specific resource, we
would append the architecture unconditionally if `-sdk` is used.  This
would result in the path being miscomputed with the architecture or the
architecture duplicated if it was architecture specific.

Found by inspection.
2023-08-03 10:58:39 -07:00
Alex Lorenz
c215abdd8c [cxx-interop][linux] modularize the bits part of libstdc++
Fixes https://github.com/apple/swift/issues/64457
2023-07-27 10:20:28 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Egor Zhdan
3e28a7c525 [cxx-interop] Make libstdc++ header and modulemap arch-independent
This moves `libstdcxx.modulemap` and `libstdcxx.h` from `*.xctoolchain/usr/lib/swift/macosx/arm64e` to `*.xctoolchain/usr/lib/swift/macosx` to simplify distribution.

rdar://110788977
2023-06-22 22:03:57 +01:00
Egor Zhdan
4ce4527ef1 [cxx-interop] Make CxxShim header and modulemap arch-independent
This moves `libcxxshim.modulemap`, `libcxxshim.h` and `libcxxstdlibshim.h` from `*.xctoolchain/usr/lib/swift/macosx/arm64e` to `*.xctoolchain/usr/lib/swift/macosx` to simplify distribution.

rdar://110788977
2023-06-20 15:57:38 +01:00
Alex Lorenz
11e5fc80b8 Merge pull request #64177 from hyp/eng/libstdcxx-dynamic
[interop] Configure libstdc++ module map at runtime
2023-03-08 15:34:51 -08:00
Alex Lorenz
eba8a00673 [interop] Inject header files into libstdcxx.modulemap dynamically
This allows the module map we use for libstdc++ to correctly include optional headers like "any" and other C++17/20 files.
2023-03-08 07:59:52 -08:00
Saleem Abdulrasool
73cafebaf5 Driver: introduce additional Windows controls
This adds the following four new options:
  - `-windows-sdk-root`
  - `-windows-sdk-version`
  - `-visualc-tools-root`
  - `-visualc-tools-version`

Together these options make one the master of Windows SDK selection for
the Swift compilation.  This is important as now that the injection is
no longer done by the user, we need to ensure that we have enough
control over the paths so that the synthesized overlay is going to map
the files to the proper location.
2023-03-06 13:29:31 -08:00
Saleem Abdulrasool
67d5deb110 ClangImporter: inject modulemaps via the VFS
This is the second step towards removal of the content injection into
the Visual Studio installation.  With this the new path is enabled to
create the mappings to the SDK shared content.  Subsequent improvements
involve the introduction of new options to the Swift driver and
Swift frontend:
  1. `-windows-sdk-root`
  2. `-windows-sdk-version`
  3. `-visualc-tools-root`
  4. `-visualc-tools-version`
The introduction of these options will then feed into the path selection
here enabling granular control over the VCRuntime and Windows SDK by the
user.

Thanks to @artemcm for the very helpful discussion and help on
identifying a good set of options for the driver.  Thanks to @stevapple
for the inspiration for this patch.
2023-03-02 15:56:14 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Butta
f82a4e7899 [ClangImporter] Add the sysroot directly to the clang Driver used to find the libc header path
`getToolChain()` and `AddClangSystemIncludeArgs()` don't parse the arguments to set the
sysroot, so set it directly instead. Also, remove a redundant check for a valid directory.

Fixes #60224
2022-08-27 01:24:33 +05:30
3405691582
6a55161187 Correct VFS libc modulemap injection condition.
We should only be skipping VFS libc modulemap injection on Darwin and
Windows. Unfortunately, we cannot just use the isOSGlibc Triple method
because LLVM's sense of Glibc (does the platform _actually use_ glibc)
differs from Swift's sense of Glibc (does the platform use libc).

There may be other non-libc platforms that we should skip VFS injection
on but let's correct the conditional for now and other prs should add
those platforms as necessary.
2022-08-17 16:25:00 -04:00
Egor Zhdan
59cc7c49e3 [cxx-interop] NFC: fix bad merge
`getModuleMapFilePath` and related logic was moved to `ClangIncludePaths.cpp` recently, but got resurrected in `ClangImporter.cpp` by accident.
2022-07-08 12:41:46 +01:00
Egor Zhdan
cf3354222d [Glibc] Use VFS to inject modulemap into Glibc include path
This will fix modularization issues caused by the presence of Glibc and libstdc++ in a single context.

Some Glibc headers were getting hijacked by the libstdc++ module, and the decls in them were incorrectly determined to be a part of libstdc++. This caused compiler errors when trying to use those decls.

After this change, we will be able to reference Glibc headers directly from the module map, without using an additional header (`SwiftGlibc.h`).
2022-07-01 23:49:12 +01:00
Egor Zhdan
a2fb2d0b78 [ClangImporter] NFC: extract Clang include path mapping logic into a separate file
This logic is going to be extended to inject the modulemap and the header of Glibc in addition to libstdc++. It doesn't depend on the rest of ClangImporter, so let's extract it to a separate file to make incremental builds and IDE features faster.
2022-06-30 15:50:33 +01:00