You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Verify product dependencies w/ target platform, vs. hardcoded macOS (#6963)
Product dependencies are now verified using the `buildEnvironment`'s
platform, instead of the hardcoded `macOS` platform.
This builds on the work of #6732, now allowing cross-compilation of
product dependencies 🎉
### Motivation:
Let's say we're cross-compiling macOS -> iOS simulator, with a host
system of `macOS v13`.
```swift
let package = Package(
name: "SwiftFlashlight",
products: [.library(...)],
platforms: [.iOS(.v16)],
dependencies: [
// internally, for iOS(.v16), macOS(.v14)
.package(url: "probably/alamofire", exact: "1.2.3")
],
// ...
)
```
As long as we set our triple & SDK, we _should_ be good... (and, with
#6828, only the triple needed)
```fish
> swift build --triple arm64-apple-ios-simulator \
--sdk "$(xcrun --sdk iphonesimulator --show-sdk-path)"
...
error: the library 'SwiftFlashlight' requires macos 10.13,
but depends on the product 'probably/alamofire' which requires macos 10.14; [...]
```
Even though `SwiftFlashlight` only supports `iOS(.v16)`,
[SupportedPlatform](https://github.com/apple/swift-package-manager/blob/main/Documentation/PackageDescription.md#supportedplatform)
"[by] default, [...] assigns a predefined minimum deployment version for
each supported platforms unless you configure supported platforms
[...]". As a side-effect, `macOS` is inferred as a valid platform. (This
is why no "target/platform mismatch" error was thrown.)
Previously, product dependencies were verified against `macOS`, rather
than the target platform. Since `macOS` is always inferred, this
surfaced as a "woah! your dependencies are out of sync".
```swift
let swiftFlashlight = Package(
platforms: [
.iOS(.v16),
.macOS(.v13) // <-- inferred-|
], |
) |-- // since --triple is .iOS,
| // shouldn't be comparing
let probably/alamofire = Package ( | // macOS.
platforms: [ |
iOS(.v16), |
macOS(.v14)] // <-- inferred-|
]
)
```
Now, the intention of `--triple` is respected 🐱
### Modifications:
- `validateDeploymentVersionOfProductDependency` accepts a
`buildEnvironment` containing the target platform
### Result:
Product dependencies can now be compiled for `darwin` other than macOS
-- i.e, iOS :)
### Future work
- Target-level or product-level platform support is still up in the air
- This only applies to `triple.isDarwin()` -- perhaps a next step of
verifying dependencies against non-darwin?
---------
Co-authored-by: Max Desiatov <[email protected]>
/// Converts a set of C compiler flags into an equivalent set to be
41
41
/// indirected through the Swift compiler instead.
42
42
func asSwiftcCCompilerFlags()->Self{
@@ -142,7 +142,8 @@ extension BuildParameters {
142
142
return args
143
143
}
144
144
145
-
/// Computes the linker flags to use in order to rename a module-named main function to 'main' for the target platform, or nil if the linker doesn't support it for the platform.
145
+
/// Computes the linker flags to use in order to rename a module-named main function to 'main' for the target
146
+
/// platform, or nil if the linker doesn't support it for the platform.
.warning("Swift compiler no longer supports statically linking the Swift libraries. They're included in the OS by default starting with macOS Mojave 10.14.4 beta 3. For macOS Mojave 10.14.3 and earlier, there's an optional Swift library package that can be downloaded from \"More Downloads\" for Apple Developers at https://developer.apple.com/download/more/")
644
+
.warning(
645
+
"Swift compiler no longer supports statically linking the Swift libraries. They're included in the OS by default starting with macOS Mojave 10.14.4 beta 3. For macOS Mojave 10.14.3 and earlier, there's an optional Swift library package that can be downloaded from \"More Downloads\" for Apple Developers at https://developer.apple.com/download/more/"
consider changing the \(target.type.rawValue) '\(target.name)' to require \
661
+
\(productPlatform.platform.name)\(productPlatform.version.versionString) or later, \
662
+
or the product '\(product)' to require \
663
+
\(targetPlatform.platform.name)\(targetPlatform.version.versionString) or earlier.
664
+
""")
649
665
}
650
666
651
667
staticfunc binaryTargetsNotSupported()->Self{
@@ -656,7 +672,7 @@ extension Basics.Diagnostic {
656
672
extensionBuildParameters{
657
673
/// Returns a named bundle's path inside the build directory.
658
674
func bundlePath(named name:String)->AbsolutePath{
659
-
returnbuildPath.appending(component: name +self.triple.nsbundleExtension)
675
+
buildPath.appending(component: name +self.triple.nsbundleExtension)
660
676
}
661
677
}
662
678
@@ -705,20 +721,20 @@ extension ResolvedPackage {
705
721
706
722
extensionResolvedProduct{
707
723
privatevarisAutomaticLibrary:Bool{
708
-
returnself.type ==.library(.automatic)
724
+
self.type ==.library(.automatic)
709
725
}
710
726
711
727
privatevarisBinaryOnly:Bool{
712
728
returnself.targets.filter({ !($0.underlying is BinaryTarget)}).isEmpty
713
729
}
714
730
715
731
privatevarisPlugin:Bool{
716
-
returnself.type ==.plugin
732
+
self.type ==.plugin
717
733
}
718
734
719
-
// We shouldn't create product descriptions for automatic libraries, plugins or products which consist solely of binary targets, because they don't produce any output.
735
+
// We shouldn't create product descriptions for automatic libraries, plugins or products which consist solely of
736
+
// binary targets, because they don't produce any output.
0 commit comments