Currently, swift packages can expose 3 types of products to the consumer of packages:
- Library
- Executable
- Plugin
There is no alternative to add custom product definitions and expose custom product types. Some example for this:
- Developing for android platform requires producing
.apk
product which can be deployed on android devices. - Developing for ios platform requires producing
.app
product. - Other platforms also provide alternative packaging/deployment options, i.e
.appx
or.msix
in Windows, snaps and flatpaks in Linux.
Currently cross-compilation destination bundles pitch outlines support for building existing products for other platforms. Allowing destination bundles to expose additional product types will make multi-platform development in Swift much easier.
This will help removing reliance on Xcode projects and other third-party setup required for doing multi-platform development, providing a standard way for multi-platform development with Swift.
Extending destination bundles destination.json
schema to allow destinations to provide additional product definitions will help decouple platform-specific definitions from Swift tools version and can be updated by updating destination bundles and adding support for newer destinations.
Adding additional property swiftPackageDefinitionsPath
for each runTimeTriples
in destination.json
will allow importing such definitions in Package.swift
.
{
"schemaVersion": "3.1",
"runTimeTriples": [
"<triple1>": {
// optional:
"swiftPackageDefinitionsPath": ["<array of paths relative to `destination.json` containing Swift modules that can be imported in `Package.swift`>"]
},
"<triple2>": {
// optional:
"swiftPackageDefinitionsPath": ["<array of paths relative to `destination.json` containing Swift modules that can be imported in `Package.swift`>"]
}
]
}
To use these custom definitions in Package.swift
, users can conditionally add the products based on presence of module, i.e android product can only be exposed in presence of AndroidProductTypes
, iOS product can only be exposed in presence of AppleProductTypes
etc:
#if canImport(AndroidProductTypes)
package.products.append(
.androidApp(...)
)
#endif
#if canImport(AppleProductTypes)
package.products.append(
.iOSApp(...)
)
#endif
#if canImport(WindowsProductTypes)
package.products.append(
.windowsApp(...)
)
#endif
#if canImport(UbuntuProductTypes)
package.products.append(
.snapApp(...)
)
#endif