Commit Graph

319 Commits

Author SHA1 Message Date
Ben Barham
1f53e700fa Add the distribution tag to -print-target-info
Ideally this would also update the `--version` output to be overridden
by `SWIFT_TOOLCHAIN_VERSION`, but unfortunately various tools rely on
the current format (eg. swift-build).

(cherry picked from commit 3c098782b4)
2025-05-30 10:04:40 -07:00
Steven Wu
559734c6d0 [Caching] Remove CASFS clang module implemenation
Remove the CASFS based clang module implemenation as it is not longer
used.

(cherry picked from commit 3c81c1ca9f)
2025-05-22 11:13:36 -07:00
Steven Wu
edb94fb2fb [Caching] Improve diagnostics around swift caching
Improve diagnostics message for swift caching build by trying to emit
the diagnostics early when there is more context to differentiate the
different kind of problems.

After the improvement, CAS Error should be more closer to when there is
functional problem with the CAS, rather than mixing in other kinds of
problem (like scanning dependency failures) when operating with a CAS.

rdar://145676736
(cherry picked from commit 226552bf23)
2025-05-01 16:59:43 -07:00
Egor Zhdan
bfaef5df22 [cxx-interop] Remove a workaround for CoreGraphics module interface
CoreGraphics can now be rebuilt with C++ interop enabled, which makes this workaround obsolete.

rdar://150211857
(cherry picked from commit 571bd8e9d9)
2025-04-30 14:05:36 +01:00
Steven Wu
f96b81975a [Caching][Macro] Make macro plugin options cacheable
Currently, the macro plugin options are included as cache key and the
absolute path of the plugin executable and library will affect cache
hit, even the plugin itself is identical.

Using the new option `-resolved-plugin-validation` flag, the macro
plugin paths are remapped just like the other paths during dependency
scanning. `swift-frontend` will unmap to its original path during the
compilation, make sure the content hasn't changed, and load the plugin.
It also hands few other corner cases for macro plugins:

* Make sure the plugin options in the swift module is prefix mapped.
* Make sure the remarks of the macro loading is not cached, as the
  mesasge includes the absolute path of the plugin, and is not
  cacheable.

rdar://148465899
(cherry picked from commit 3d38d0dd56)
2025-04-10 16:52:15 -07:00
Allan Shortlidge
645628f3e4 Frontend: Reinstate suppression of warnings during interface type-checking.
We're not ready to start emitting warnings when type-checking modules from
interface. It is causing performance regressions and spurious diagnostics to be
emitted.

Reverts a small part of https://github.com/swiftlang/swift/pull/80360.

Resolves rdar://148257136.
2025-03-31 20:41:24 -07:00
Becca Royal-Gordon
ce8cc1780a Ignore bad @_hasStorage in module interfaces
An objcImpl bug previously caused `@_hasStorage` to be emitted inside some extensions in module interfaces. An earlier commit in this PR created an error for this, but for backwards compatibility, it would actually be better to simply ignore the attribute in module interfaces. Modify TypeCheckStorage to emit a warning, not an error, in this situation.

Additionally, modify the module interface loader to show warnings when you verify a module interface, but not for other module interface uses (like compiling or importing one). The assumption here is that if you’re verifying a module interface, you’re either the author of the module that created it or you’re investigating a problem with it, and in either case you’d like to be told about minor defects in case they’re related.

Fixes rdar://144811653 thoroughly.
2025-03-27 18:25:11 -07:00
Alexis Laferrière
a4aaa1063a Merge pull request #80098 from xymus/upstream-swiftmodule-blocklist
Frontend: Upstream blocklist check when ignoring adjacent swiftmodule files
2025-03-26 10:28:30 -07:00
Alexis Laferrière
7d3ed787a1 Frontend: Upstream blocklist check in ignoring adjacent swiftmodule files 2025-03-19 14:15:34 -07:00
Artem Chikin
dd4e8c03a5 [Dependency Scanning] Treat resource-directory-discovered modules as stable and make them use the SDK-specific module cache path 2025-03-19 14:56:12 -06:00
Artem Chikin
88dec5199e [Dependency Scanning] Add support for placing explicitly-built SDK modules into a separate module cache
With '-sdk-module-cache-path', Swift textual interfaces found in the SDK will be built into a separate SDK-specific module cache.
Clang modules are not yet affected by this change, pending addition of the required API.
2025-03-19 09:17:04 -06:00
Hiroshi Yamauchi
275a6792d1 Merge pull request #80007 from hjyamauchi/androidoverlay
Propagate sysroot to module loader subinvocation
2025-03-14 22:12:02 -07:00
Hiroshi Yamauchi
1a3a6e1c66 Propagate sysroot to module loader subinvocation
To fix the Android build issue https://github.com/swiftlang/swift/issues/79839
2025-03-14 12:38:40 -07:00
Artem Chikin
27bac69527 Merge pull request #79930 from artemcm/ClangTargetVariant
[Explicit Module Builds] Add '-clang-target-variant' flag
2025-03-13 07:21:09 -07:00
Egor Zhdan
735b6aab49 Merge pull request #79952 from swiftlang/egorzhdan/darwin-cxx
[cxx-interop] Allow Darwin overlay to be rebuilt with C++ interop enabled
2025-03-13 10:56:34 +00:00
Egor Zhdan
4ce5a23034 [cxx-interop] Allow Darwin overlay to be rebuilt with C++ interop enabled
This removes a workaround from the module interface loader, which was forcing Darwin to be rebuilt from their textual interfaces with C++ interop disabled, even if the current compilation explicitly enables it.

See also 3791ccb6.

rdar://142961112
2025-03-12 16:45:13 +00:00
Artem Chikin
e96a690cc7 [Explicit Module Builds] Add '-clang-target-variant' flag
https://github.com/swiftlang/swift/pull/37774 added '-clang-target' which allows us to specify a target triple that only differs from '-target' by the OS version, when we want to provide a different OS version for API availability and type-checking, in order to set a common/unified target triple for the entire Clang module dependency graph, for presenting a unified API surface to the Swift client, serving as a maximum type-checking epoch.

This change adds an equivalent flag for the '-target-variant' configuration, as a mechanism to ensure that the entire module dependency graph presents a consistent os version.
2025-03-11 15:48:06 -07:00
Tony Allevato
8752920875 Allow module aliases to be expressed in the explicit Swift module map JSON file.
For build systems that already generate these files, it makes sense to include the aliases so that the map file serves as a comprehensive index of how the module inputs are referenced.
2025-03-11 17:18:43 -04:00
Egor Zhdan
3791ccb6e6 [cxx-interop] Allow AppKit & UIKit to be rebuilt with C++ interop enabled
This removes a workaround from the module interface loader, which was forcing AppKit and UIKit to be rebuilt from their textual interfaces with C++ interop disabled, even if the current compilation explicitly enables it.

The workaround was previously put in place because of a compiler error:
```
error: type 'AttributeScopes.AppKitAttributes.StrikethroughStyleAttribute' does not conform to protocol 'AttributedStringKey'
note: possibly intended match 'AttributeScopes.AppKitAttributes.StrikethroughStyleAttribute.Value' (aka 'NSUnderlineStyle') does not conform to 'Hashable'
```

`NSUnderlineStyle` is a C/C++ type from AppKit that is declared using `NS_OPTIONS` macro. `NS_OPTIONS`/`CF_OPTIONS` macros have different expansions in C vs C++ language modes. The C++ expansions weren't handled correctly by ClangImporter, resulting in two distinct Swift types being created: a `typealias NSUnderlineStyle` which was marked as unavailable in Swift, and `enum NSUnderlineStyle`. This mostly worked fine, since the lookup logic was picking the enum during regular name lookup. However, this silently broke down when rebuilding the explicit conformance from `AppKit.swiftinterface`:
```
extension AppKit.NSUnderlineStyle : Swift.Hashable {}
```
Swift was picking the (unavailable) typealias when rebuilding this extension, which means the (available) enum wasn't getting the conformance.

This is verified by an existing test (`test/Interop/Cxx/objc-correctness/appkit-uikit.swift`).

rdar://142961112
2025-03-07 13:27:11 +00:00
Alexis Laferrière
c539f7e11a Merge pull request #79588 from xymus/ignore-more-swiftmodules
Frontend: Ignore resilient binary swiftmodules under usr/lib/swift
2025-02-25 09:08:36 -08:00
Alexis Laferrière
40244a2935 Frontend: Ignore resilient binary swiftmodules under usr/lib/swift
Most SDKs use only swiftinterfaces under usr/lib/swift. Let's make sure
we standardize this behavior and use only swiftinterface when they are
present, even if there are also binary swiftmodule files available.

Apply the same logic to SubFrameworks as well while we're at it.

rdar://145316821
2025-02-24 16:22:20 -08:00
Qiongsi Wu
23e863dc7a Address code review: adding a test for -experimental-clang-importer-direct-cc1-scan and renaming a function. 2025-02-13 14:02:53 -08:00
Qiongsi Wu
b7b27955bd Addressing code review. Removed the helper class, hence we do not need to manage any states. 2025-02-12 20:19:39 -08:00
Qiongsi Wu
1ce69497ff Address code review comments. 2025-02-12 20:19:39 -08:00
Qiongsi Wu
cd6066dcbf Refactoring swift interface module's output path calculation to use new code. 2025-02-12 20:19:38 -08:00
Qiongsi Wu
8055c1d17c Initial commit of InterfaceModuleNameExpander implmentation. All tests pass, and the unused vfs overlay is optimized. 2025-02-12 20:19:36 -08:00
Allan Shortlidge
2175e29cfa Frontend: Fix warnings about unused variables. 2025-02-01 10:28:27 -08:00
Artem Chikin
477ba0dd97 [Dependency Scanning] Remove references to per-triple PCM variant compilation 2025-01-29 11:32:07 -08:00
Artem Chikin
ea2c501131 Merge pull request #78672 from artemcm/DepScanInvalidRejectedBinaryModulesWarn
[Dependency Scanning] Emit a warning when failing to load a binary module of a non-resilient dependency
2025-01-22 15:03:43 -08:00
Egor Zhdan
752cb36239 Merge pull request #78014 from swiftlang/egorzhdan/libcxx-overlay-linux
[cxx-interop] Support CxxStdlib overlay for libc++ on Linux
2025-01-20 15:09:26 +00:00
Artem Chikin
550538f3b5 [Dependency Scanning] Emit a warning when failing to load a binary module of a non-resilient dependency
This failure will most-likely result in the dependency query failure which will fail the scan. It will be helpful if the scanner emitted diagnostic for each such module it rejected to explain the reason why.

Resolves rdar://142906530
2025-01-17 10:52:10 -08:00
Cassie Jones
7323a752b6 [cxx-interop] Workaround compiler error when importing AppKit/UIKit with C++ interop
The AppKit/UIKit overlay refers to symbols declared via NS_OPTIONS
macro, which is causing issues in C++ language mode due to the macro
definition being different. This teaches the module interface loader to
drop the C++ interop flag when rebuilding the AppKit and UIKit overlay
from its interface.

This is the same fix as #78636, but for different modules.

rdar://143033209
2025-01-16 15:19:23 -08:00
Allan Shortlidge
4ea157efdb Frontend: Parse diagnostic options earlier.
Diagnostics may be emitted while parsing command line arguments. This implies
that the options which affect how diagnostics are emitted and presented need to
be parsed first.
2025-01-15 16:34:32 -08:00
Allan Shortlidge
250479177e Merge pull request #78653 from tshortli/suppress-option-parsing-warnings-in-swiftinterfaces
Frontend: Honor warning suppression when parsing arguments from swiftinterfaces
2025-01-15 09:45:40 -08:00
Allan Shortlidge
3c5ae232dc Frontend: Honor warning suppression when parsing arguments from swiftinterfaces.
Diagnostics are suppressed when parsing swiftinterface files, since the
warnings emitted from compiling the swiftinterface of a dependency would just
be a nuisance. It follows that warnings generated when parsing the arguments in
a swiftinterface file should also be suppressed, but that wasn't happening
because the diagnostic engine of the main compile was used for parsing. Pass
the diagnostic engine of the compiler subinstance instead, and proactively
suppress warnings before parsing begins.

Resolves rdar://142814164.
2025-01-14 23:07:24 -08:00
Egor Zhdan
d72006e265 [cxx-interop] Workaround compiler error when importing CoreGraphics with C++ interop
The CoreGraphics overlay refers to symbols declared via `CF_OPTIONS` macro, which is causing issues in C++ language mode due to the macro definition being different.

This teaches the module interface loader to drop the C++ interop flag when rebuilding the CoreGraphics overlay from its interface.

rdar://142762174
2025-01-14 19:25:40 +00:00
Meghana Gupta
453369517a Allow recompilation of modules in the resource directory when importing non-ossa module to ossa module
This effects local swift development only and is needed now to use -enable-ossa-modules in local tests that
import Synchronization and Distributed which are non-ossa.
2025-01-08 20:45:37 -08:00
Allan Shortlidge
3f0eb8ce2c Frontend: Fix -target-variant subarch normalization.
In https://github.com/swiftlang/swift/pull/77156, normalization was introduced
for -target-variant triples. That PR also caused -target-variant arguments to
be inherited from the main compilation options whenever building dependency
modules from their interfaces, which is incorrect. The -target-variant option
must only be specified when compiling a "zippered" module, but the dependencies
of zippered modules are not necessarily zippered themselves and
indiscriminantly propagating the option can cause miscompilation.

The new, more targeted approach to normalizing arm64e triples simply uses the
arch and subarch of the -target argument of the main compile to decide whether
the subarch of both the -target and -target-variant arguments of a dependency
need adjustment.

Resolves rdar://135322077 and rdar://141640919.
2025-01-02 13:51:26 -08:00
Egor Zhdan
282f3b127b [cxx-interop] Support CxxStdlib overlay for libc++ on Linux
This teaches Swift to rebuild the CxxStdlib overlay module from its interface when using a C++ standard library that is not the platform default, specifically libc++ on Linux.

rdar://138838506
2024-12-10 14:19:59 +00:00
Egor Zhdan
7ae2bebfe8 [cxx-interop] Do not emit C++ interop flag in textual interfaces
This makes sure that the compiler does not emit `-enable-experimental-cxx-interop`/`-cxx-interoperability-mode` flags in `.swiftinterface` files. Those flags were breaking explicit module builds. The module can still be rebuilt from its textual interface if C++ interop was enabled in the current compilation.

rdar://140203932
2024-12-05 19:25:09 +00:00
Steven Wu
0a18baa510 Merge pull request #76732 from cachemeifyoucan/eng/PR-136682810
[Macro] Precise macro plugin dependency during scanning
2024-11-04 09:21:33 -08:00
Steven Wu
2d204f839a [ScanDependency] Teach dependency scanner to use resolved macros option
Teach dependency scanner to construct build commands using resolved
plugin search path option. This ensures the modules that do not have
access to the macro plugins will not have a different variant due to
different plugin search path.

rdar://136682810
2024-10-31 10:56:21 -07:00
Steven Wu
47b3efdb6e [Macro] Add a new macro loading option that do not involve searching
Add flag `-load-resolved-plugin` to load macro plugin, which provides a
pre-resolved entry into PluginLoader so the plugins can be loaded based
on module name without searching the file system. The option is mainly
intended to be used by explicitly module build and the flag is supplied
by dependency scanner.
2024-10-31 10:56:21 -07:00
Meghana Gupta
10aebac25b Pass -enable-ossa-modules to the generic args while inheriting options for building the interface 2024-10-31 10:55:40 -07:00
Daniel Rodríguez Troitiño
4e2fbe17c3 [swiftinterface] Handle target variants the same as targets (#77156)
Based on preliminary work from @rmaz.

The compilation arguments for a swiftinterface file are preprocessed to
modify the `-target` argument to match the preferred target (which comes
from the command line) in cases in which the sub-architecture differs,
but it is compatible (for example using `arm64e` when `arm64` is being
compiled), but this was not done for the target variant, which ended up
with mismatches on the sub-architecture used by the target and target
variant, which fails an assert in assert toolchains.
2024-10-22 16:34:19 -07:00
Artem Chikin
09b5431878 Merge pull request #76465 from artemcm/InheritTargetSDKInfoOnExplicitSwiftDep
[Dependency Scanning] Inherit target SDK name and version for textual interface build recipes
2024-09-14 07:47:53 -07:00
artemcm
8dbbc807c8 [Dependency Scanning] Inherit target SDK name and version for textual interface build recipes
Otherwise they get built with an empty SDK name string and we do not get the benefit of the SDK name compatibility check in case they are loading modules from an incompatible SDK

Resolves rdar://135972810
2024-09-13 16:10:06 -07:00
Steven Wu
a6c560b949 [Modules] Make SubInstance spawn correctly under DirectCC1Mode
Make sure ClangExtraArgs are inherited in the subinstance for module
lookup/building when direct cc1 mode is used. This is useful for lldb,
which does a slight different variant of the explicit module build
that do not have swift-driver cooridination and replies on the
subInstance to load swiftmodule. When such configuration is used, if
DirectCC1 compile option is inherited without any extra cc1 arguments,
the clang importer inside the sub-instance is actually malformed,
causing the swift instance failed to be created.

rdar://135611011
2024-09-10 16:47:48 -07:00
Steven Wu
8efc7414f0 [Module] Use stricter module hash
Use a stricter module hash for modules as moving towards more explicit
modules. Previously, a normalized target triple without deployment
target is used as part of the module hash, with the assumption that
deployment target should not change binary module generated.

In reality, the binary module compilation also needs to provide the
typecheck for all interface to ensure the underlying C/ObjC module that
built with the correct deployment target does provide the interfaces to
pass typecheck. Using a stricter module hash can avoid the potentially
confusing error when importing the module.

This commit adds following to module hash to distinguish swiftmodules.
* Deployment target
* -application-extension

rdar://134301179
2024-08-30 14:39:43 -07:00
Steven Wu
7ed9a52633 [PrefixMap] Remap clang cc1 args when building swift interfaces
Fix a bug that swift clang importer is not setup correctly when prefix
map is used. There are two separate issues:
* CC1 args used to setup clang import when building swift (interface and
  sources) are not correctly remapped.
* When loading SDKInfo from SDK path, the SDKSettings.json is not
  loading from VFS, thus the file cannot be loaded from remapped path.

rdar://134458611
2024-08-23 10:32:20 -07:00