Static Methodswift-package-manager 6.0.1PackageDescription
plugin(name:capability:dependencies:path:exclude:sources:packageAccess:)
Defines a new package plug-in target.
Target.swift:1218- SwiftPM
- 5.9+
static func plugin(name: String, capability: PluginCapability, dependencies: [Dependency] = [], path: String? = nil, exclude: [String] = [], sources: [String]? = nil, packageAccess: Bool = true) -> Target
Parameters
- name
The name of the plug-in target.
- capability
The type of capability the plug-in target provides.
- dependencies
The plug-in target’s dependencies.
- path
The path of the plug-in target relative to the package root.
- exclude
The paths to source and resource files that you want to exclude from the plug-in target.
- sources
The source files in the plug-in target.
- packageAccess
Allows access to package symbols from other targets in the package.
Returns
A Target
instance.
A plug-in target provides custom build commands to SwiftPM (and to any IDEs based on libSwiftPM).
The capability determines what kind of build commands it can add. Besides determining at what point in the build those commands run, the capability determines the context that is available to the plug-in and the kinds of commands it can create.
In the initial version of this proposal, three capabilities are provided: prebuild, build tool, and postbuild. For more information, see the declaration of each capability under PluginCapability
.
The package plug-in itself is implemented using a Swift script that is invoked for each target that uses it. The script is invoked after the package graph has been resolved, but before the build system creates its dependency graph. It’s also invoked after changes to the target or the build parameters.
Note that the role of the package plug-in is only to define the commands that run before, during, or after the build. It doesn’t run those commands itself. The commands are defined in an IDE-neutral way, and are run as appropriate by the build system that builds the package. The extension itself is only a procedural way of generating commands and their input and output dependencies.
The package plug-in may specify the executable or binary targets that provide the build tools used by the generated commands during the build. In the initial implementation, prebuild actions can only depend on binary targets. Build tool and postbuild plug-ins can depend on executables as well as binary targets. This is due to how Swift Package Manager constructs its build plan.
Other members in extension
Types
enum Dependency
The different types of a target’s dependency on another entity.
enum PluginCapability
The different types of capability that a plug-in can provide.
enum PluginUsage
A plug-in used in a target.
enum TargetType
The different types of a target.
Type members
static func binaryTarget(name: String, path: String
) -> Target Creates a binary target that references an artifact on disk.
static func binaryTarget(name: String, url: String, checksum: String
) -> Target Creates a binary target that references a remote artifact.
static func executableTarget(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?, resources: [Resource]?, publicHeadersPath: String?, packageAccess: Bool, cSettings: [CSetting]?, cxxSettings: [CXXSetting]?, swiftSettings: [SwiftSetting]?, linkerSettings: [LinkerSetting]?, plugins: [PluginUsage]?
) -> Target Creates an executable target.
static func systemLibrary(name: String, path: String?, pkgConfig: String?, providers: [SystemPackageProvider]?
) -> Target Creates a system library target.
static func target(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?, resources: [Resource]?, publicHeadersPath: String?, packageAccess: Bool, cSettings: [CSetting]?, cxxSettings: [CXXSetting]?, swiftSettings: [SwiftSetting]?, linkerSettings: [LinkerSetting]?, plugins: [PluginUsage]?
) -> Target Creates a regular target.
static func testTarget(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?, resources: [Resource]?, packageAccess: Bool, cSettings: [CSetting]?, cxxSettings: [CXXSetting]?, swiftSettings: [SwiftSetting]?, linkerSettings: [LinkerSetting]?, plugins: [PluginUsage]?
) -> Target Creates a test target.
Show obsolete interfaces (11)
Hide obsolete interfaces
static func executableTarget(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?, resources: [Resource]?, publicHeadersPath: String?, cSettings: [CSetting]?, cxxSettings: [CXXSetting]?, swiftSettings: [SwiftSetting]?, linkerSettings: [LinkerSetting]?
) -> Target Creates an executable target.
static func executableTarget(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?, resources: [Resource]?, publicHeadersPath: String?, cSettings: [CSetting]?, cxxSettings: [CXXSetting]?, swiftSettings: [SwiftSetting]?, linkerSettings: [LinkerSetting]?, plugins: [PluginUsage]?
) -> Target Creates an executable target.
static func plugin(name: String, capability: PluginCapability, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?
) -> Target Defines a new package plugin target.
static func target(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?, publicHeadersPath: String?
) -> Target Creates a library or executable target.
static func target(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?, publicHeadersPath: String?, cSettings: [CSetting]?, cxxSettings: [CXXSetting]?, swiftSettings: [SwiftSetting]?, linkerSettings: [LinkerSetting]?
) -> Target Creates a library or executable target.
static func target(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?, resources: [Resource]?, publicHeadersPath: String?, cSettings: [CSetting]?, cxxSettings: [CXXSetting]?, swiftSettings: [SwiftSetting]?, linkerSettings: [LinkerSetting]?
) -> Target Creates a regular target.
static func target(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?, resources: [Resource]?, publicHeadersPath: String?, cSettings: [CSetting]?, cxxSettings: [CXXSetting]?, swiftSettings: [SwiftSetting]?, linkerSettings: [LinkerSetting]?, plugins: [PluginUsage]?
) -> Target Creates a regular target.
static func testTarget(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?
) -> Target Creates a test target.
static func testTarget(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?, cSettings: [CSetting]?, cxxSettings: [CXXSetting]?, swiftSettings: [SwiftSetting]?, linkerSettings: [LinkerSetting]?
) -> Target Creates a test target.
static func testTarget(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?, resources: [Resource]?, cSettings: [CSetting]?, cxxSettings: [CXXSetting]?, swiftSettings: [SwiftSetting]?, linkerSettings: [LinkerSetting]?
) -> Target Creates a test target.
static func testTarget(name: String, dependencies: [Dependency], path: String?, exclude: [String], sources: [String]?, resources: [Resource]?, cSettings: [CSetting]?, cxxSettings: [CXXSetting]?, swiftSettings: [SwiftSetting]?, linkerSettings: [LinkerSetting]?, plugins: [PluginUsage]?
) -> Target Creates a test target.
Show system interfaces (1)
Hide system interfaces
init(name: String, dependencies: [Dependency], path: String?, url: String?, exclude: [String], sources: [String]?, resources: [Resource]?, publicHeadersPath: String?, type: TargetType, packageAccess: Bool, pkgConfig: String?, providers: [SystemPackageProvider]?, pluginCapability: PluginCapability?, cSettings: [CSetting]?, cxxSettings: [CXXSetting]?, swiftSettings: [SwiftSetting]?, linkerSettings: [LinkerSetting]?, checksum: String?, plugins: [PluginUsage]?
) Construct a target.
Instance members
var cSettings: [CSetting]?
The target’s C build settings.
var checksum: String?
The checksum for the archive file that contains the referenced binary artifact.
var cxxSettings: [CXXSetting]?
The target’s C++ build settings.
var dependencies: [Dependency]
The target’s dependencies on other entities inside or outside the package.
var exclude: [String]
The paths to source and resource files that you don’t want to include in the target.
var isTest: Bool
A Boolean value that indicates whether this is a test target.
var linkerSettings: [LinkerSetting]?
The target’s linker settings.
var name: String
The name of the target.
let packageAccess: Bool
If true, access to package declarations from other targets in the package is allowed.
var path: String?
The path of the target, relative to the package root.
let pkgConfig: String?
The name of the package configuration file, without extension, for the system library target.
var pluginCapability: PluginCapability?
The capability provided by a package plug-in target.
var plugins: [PluginUsage]?
The uses of package plug-ins by the target.
let providers: [SystemPackageProvider]?
The providers array for a system library target.
var publicHeadersPath: String?
The path to the directory that contains public headers of a C-family target.
var resources: [Resource]?
The explicit list of resource files in the target.
var sources: [String]?
The source files in this target.
var swiftSettings: [SwiftSetting]?
The target’s Swift build settings.
let type: TargetType
The type of the target.
var url: String?
The URL of a binary target.