1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
|
# Package
`class Package`
The configuration of a Swift package.
Pass configuration options as parameters to your package's initializer
statement to provide the name of the package, its targets, products,
dependencies, and other configuration options.
By convention, the properties of a `Package` are defined in a single nested
initializer statement, and not modified after initialization. The following package
manifest shows the initialization of a simple package object for the MyLibrary
Swift package:
```swift
// swift-tools-version:5.1
import PackageDescription
let package = Package(
name: "MyLibrary",
platforms: [
.macOS(.v10_15),
],
products: [
.library(name: "MyLibrary", targets: ["MyLibrary"]),
],
dependencies: [
.package(url: "https://url/of/another/package/named/Utility", from: "1.0.0"),
],
targets: [
.target(name: "MyLibrary", dependencies: ["Utility"]),
.testTarget(name: "MyLibraryTests", dependencies: ["MyLibrary"]),
]
)
```
## Methods
<pre>
Package(
name: String,
defaultLocalization: [<a href="#languageTag">LanguageTag</a>]? = nil.
platforms: [<a href="#supportedplatform">SupportedPlatform</a>]? = nil,
products: [<a href="#product">Product</a>] = [],
dependencies: [<a href="#package-dependency">Package.Dependency</a>] = [],
targets: [<a href="#target">Target</a>] = [],
swiftLanguageVersions: [<a href="#SwiftVersion">SwiftVersion</a>]? = nil,
cLanguageStandard: <a href="#CLanguageStandard">CLanguageStandard</a>? = nil,
cxxLanguageStandard: <a href="#CXXLanguageStandard">CXXLanguageStandard</a>? = nil
)
</pre>
### About the Swift Tools Version
A `Package.swift` manifest file must begin with the string
`// swift-tools-version:` followed by a version number specifier.
The following code listing shows a few examples of valid declarations
of the Swift tools version:
// swift-tools-version:3.0.2
// swift-tools-version:3.1
// swift-tools-version:4.0
// swift-tools-version:5.0
// swift-tools-version:5.1
// swift-tools-version:5.2
// swift-tools-version:5.3
The Swift tools version declares the version of the `PackageDescription`
library, the minimum version of the Swift tools and Swift language
compatibility version to process the manifest, and the minimum version of the
Swift tools that are needed to use the Swift package. Each version of Swift
can introduce updates to the `PackageDescription` framework, but the previous
API version will continue to be available to packages which declare a prior
tools version. This behavior lets you take advantage of new releases of
Swift, the Swift tools, and the `PackageDescription` library, without having
to update your package's manifest or losing access to existing packages.
# SupportedPlatform
`struct SupportedPlatform`
A platform that the Swift package supports.
By default, the Swift Package Manager assigns a predefined minimum deployment
version for each supported platforms unless you configure supported platforms using the `platforms`
API. This predefined deployment version is the oldest deployment target
version that the installed SDK supports for a given platform. One exception
to this rule is macOS, for which the minimum deployment target version
starts from 10.10. Packages can choose to configure the minimum deployment
target version for a platform by using the APIs defined in this struct. The
Swift Package Manager emits appropriate errors when an invalid value is
provided for supported platforms, such as an empty array, multiple declarations
for the same platform, or an invalid version specification.
The Swift Package Manager will emit an error if a dependency is not
compatible with the top-level package's deployment version. The deployment
target of a package's dependencies must be lower than or equal to the top-level package's
deployment target version for a particular platform.
## Methods
```swift
/// Configure the minimum deployment target version for the macOS platform.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter version: The minimum deployment target that the package supports.
static func macOS(_ version: SupportedPlatform.MacOSVersion) -> SupportedPlatform
/// Configure the minimum deployment target version for the macOS platform
/// using a version string.
///
/// The version string must be a series of two or three dot-separated integers, such as `10.10` or `10.10.1`.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter versionString: The minimum deployment target as a string representation of two or three dot-separated integers, such as `10.10.1`.
static func macOS(_ versionString: String) -> SupportedPlatform
/// Configure the minimum deployment target version for the iOS platform.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter version: The minimum deployment target that the package supports.
static func iOS(_ version: SupportedPlatform.IOSVersion) -> SupportedPlatform
/// Configure the minimum deployment target version for the iOS platform
/// using a custom version string.
///
/// The version string must be a series of two or three dot-separated integers, such as `8.0` or `8.0.1`.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter versionString: The minimum deployment target as a string representation of two or three dot-separated integers, such as `8.0.1`.
static func iOS(_ versionString: String) -> SupportedPlatform
/// Configure the minimum deployment target version for the tvOS platform.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter version: The minimum deployment target that the package supports.
static func tvOS(_ version: SupportedPlatform.TVOSVersion) -> SupportedPlatform
/// Configure the minimum deployment target version for the tvOS platform
/// using a custom version string.
///
/// The version string must be a series of two or three dot-separated integers,such as `9.0` or `9.0.1`.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter versionString: The minimum deployment target as a string representation of two or three dot-separated integers, such as `9.0.1`.
static func tvOS(_ versionString: String) -> SupportedPlatform
/// Configure the minimum deployment target version for the watchOS platform.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter version: The minimum deployment target that the package supports.
static func watchOS(_ version: SupportedPlatform.WatchOSVersion) -> SupportedPlatform
/// Configure the minimum deployment target version for the watchOS platform
/// using a custom version string.
///
/// The version string must be a series of two or three dot-separated integers, such as `2.0` or `2.0.1`.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameter versionString: The minimum deployment target as a string representation of two or three dot-separated integers, such as `2.0.1`.
static func watchOS(_ versionString: String) -> SupportedPlatform
```
# Product
`class Product`
The object that defines a package product.
A package product defines an externally visible build artifact that's
available to clients of a package. The product is assembled from the build
artifacts of one or more of the package's targets.
A package product can be one of two types:
1. **Library**. Use a library product to vend library targets. This makes a target's public APIs
available to clients that integrate the Swift package.
2. **Executable**. Use an executable product to vend an executable target.
Use this only if you want to make the executable available to clients.
The following example shows a package manifest for a library called "Paper"
that defines multiple products:
```swift
let package = Package(
name: "Paper",
products: [
.executable(name: "tool", targets: ["tool"]),
.library(name: "Paper", targets: ["Paper"]),
.library(name: "PaperStatic", type: .static, targets: ["Paper"]),
.library(name: "PaperDynamic", type: .dynamic, targets: ["Paper"]),
],
dependencies: [
.package(url: "http://example.com/ExamplePackage/ExamplePackage", from: "1.2.3"),
.package(url: "http://some/other/lib", .exact("1.2.3")),
],
targets: [
.target(
name: "tool",
dependencies: [
"Paper",
"ExamplePackage"
]),
.target(
name: "Paper",
dependencies: [
"Basic",
.target(name: "Utility"),
.product(name: "AnotherExamplePackage"),
])
]
)
```
## Methods
```swift
/// Create a library product to allow clients that declare a dependency on this package
/// to use the package's functionality.
///
/// A library's product can either be statically or dynamically linked.
/// If possible, don't declare the type of library explicitly to let
/// the Swift Package Manager choose between static or dynamic linking based
/// on the preference of the package's consumer.
///
/// - Parameters:
/// - name: The name of the library product.
/// - type: The optional type of the library that is used to determine how to link to the library.
/// Leave this parameter unspecified to let the Swift Package Manager choose between static or dynamic linking (recommended).
/// If you do not support both linkage types, use `.static` or `.dynamic` for this parameter.
/// - targets: The targets that are bundled into a library product.
static func library(name: String, type: Product.Library.LibraryType? = nil, targets: [String]) -> Product
/// Create an executable package product that clients can run.
///
/// - Parameters:
/// - name: The name of the executable product.
/// - targets: The targets to bundle into an executable product.
static func executable(name: String, targets: [String]) -> Product
```
# Package Dependency
`class Package.Dependency`
A package dependency of a Swift package.
A package dependency consists of a Git URL to the source of the package,
and a requirement for the version of the package.
The Swift Package Manager performs a process called *dependency resolution* to
figure out the exact version of the package dependencies that an app or other
Swift package can use. The `Package.resolved` file records the results of the
dependency resolution and lives in the top-level directory of a Swift package.
If you add the Swift package as a package dependency to an app for an Apple platform,
you can find the `Package.resolved` file inside your `.xcodeproj` or `.xcworkspace`.
## Methods
```swift
/// Create a package dependency that uses the version requirement, starting with the given minimum version,
/// going up to the next major version.
///
/// This is the recommended way to specify a remote package dependency.
/// It allows you to specify the minimum version you require, allows updates that include bug fixes
/// and backward-compatible feature updates, but requires you to explicitly update to a new major version of the dependency.
/// This approach provides the maximum flexibility on which version to use,
/// while making sure you don't update to a version with breaking changes,
/// and helps to prevent conflicts in your dependency graph.
///
/// The following example allows the Swift Package Manager to select a version
/// like a `1.2.3`, `1.2.4`, or `1.3.0`, but not `2.0.0`.
///
/// .package(url: "https://example.com/example-package.git", from: "1.2.3"),
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - version: The minimum version requirement.
static func package(url: String, from version: Version) -> Package.Dependency
/// Add a remote package dependency given a version requirement.
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - requirement: A dependency requirement. See static methods on `Package.Dependency.Requirement` for available options.
static func package(url: String, _ requirement: Package.Dependency.Requirement) -> Package.Dependency
/// Adds a remote package dependency given a branch requirement.
///
/// .package(url: "https://example.com/example-package.git", branch: "main"),
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - branch: A dependency requirement. See static methods on `Package.Dependency.Requirement` for available options.
static func package(name: String? = nil, url: String, branch: String) -> Package.Dependency
/// Adds a remote package dependency given a revision requirement.
///
/// .package(url: "https://example.com/example-package.git", revision: "aa681bd6c61e22df0fd808044a886fc4a7ed3a65"),
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - revision: A dependency requirement. See static methods on `Package.Dependency.Requirement` for available options.
static func package(name: String? = nil, url: String, revision: String) -> Package.Dependency
/// Add a package dependency starting with a specific minimum version, up to
/// but not including a specified maximum version.
///
/// The following example allows the Swift Package Manager to pick
/// versions `1.2.3`, `1.2.4`, `1.2.5`, but not `1.2.6`.
///
/// .package(url: "https://example.com/example-package.git", "1.2.3"..<"1.2.6"),
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - range: The custom version range requirement.
static func package(url: String, _ range: Range<Version>) -> Package.Dependency
/// Add a package dependency starting with a specific minimum version, going
/// up to and including a specific maximum version.
///
/// The following example allows the Swift Package Manager to pick
/// versions 1.2.3, 1.2.4, 1.2.5, as well as 1.2.6.
///
/// .package(url: "https://example.com/example-package.git", "1.2.3"..."1.2.6"),
///
/// - Parameters:
/// - name: The name of the package, or nil to deduce it from the URL.
/// - url: The valid Git URL of the package.
/// - range: The closed version range requirement.
static func package(url: String, _ range: ClosedRange<Version>) -> Package.Dependency
/// Add a dependency to a local package on the filesystem.
///
/// The Swift Package Manager uses the package dependency as-is
/// and does not perform any source control access. Local package dependencies
/// are especially useful during development of a new package or when working
/// on multiple tightly coupled packages.
///
/// - Parameter path: The path of the package.
static func package(path: String) -> Package.Dependency
```
# Package Dependency Requirement
`enum Package.Dependency.Requirement`
An enum that represents the requirement for a package dependency.
The dependency requirement can be defined as one of three different version requirements:
**A version-based requirement.**
Decide whether your project accepts updates to a package dependency up
to the next major version or up to the next minor version. To be more
restrictive, select a specific version range or an exact version.
Major versions tend to have more significant changes than minor
versions, and may require you to modify your code when they update.
The version rule requires Swift packages to conform to semantic
versioning. To learn more about the semantic versioning standard,
visit [semver.org](https://semver.org).
Selecting the version requirement is the recommended way to add a package dependency. It allows you to create a balance between restricting changes and obtaining improvements and features.
**A branch-based requirement**
Select the name of the branch for your package dependency to follow.
Use branch-based dependencies when you're developing multiple packages
in tandem or when you don't want to publish versions of your package dependencies.
Note that packages which use branch-based dependency requirements
can't be added as dependencies to packages that use version-based dependency
requirements; you should remove branch-based dependency requirements
before publishing a version of your package.
**A commit-based requirement**
Select the commit hash for your package dependency to follow.
Choosing this option isn't recommended, and should be limited to
exceptional cases. While pinning your package dependency to a specific
commit ensures that the package dependency doesn't change and your
code remains stable, you don't receive any updates at all. If you worry about
the stability of a remote package, consider one of the more
restrictive options of the version-based requirement.
Note that packages which use commit-based dependency requirements
can't be added as dependencies to packages that use version-based
dependency requirements; you should remove commit-based dependency
requirements before publishing a version of your package.
## Methods
```swift
/// Returns a requirement for the given exact version.
///
/// Specifying exact version requirements are not recommended as
/// they can cause conflicts in your dependency graph when multiple other packages depend on a package.
/// As Swift packages follow the semantic versioning convention,
/// think about specifying a version range instead.
///
/// The following example defines a version requirement that requires version 1.2.3 of a package.
///
/// .exact("1.2.3")
///
/// - Parameters:
/// - version: The exact version of the dependency for this requirement.
static func exact(_ version: Version) -> Package.Dependency.Requirement
/// Returns a requirement for a source control revision such as the hash of a commit.
///
/// Note that packages that use commit-based dependency requirements
/// can't be depended upon by packages that use version-based dependency
/// requirements; you should remove commit-based dependency requirements
/// before publishing a version of your package.
///
/// The following example defines a version requirement for a specific commit hash.
///
/// .revision("e74b07278b926c9ec6f9643455ea00d1ce04a021")
///
/// - Parameters:
/// - ref: The Git revision, usually a commit hash.
static func revision(_ ref: String) -> Package.Dependency.Requirement
/// Returns a requirement for a source control branch.
///
/// Note that packages that use branch-based dependency requirements
/// can't be depended upon by packages that use version-based dependency
/// requirements; you should remove branch-based dependency requirements
/// before publishing a version of your package.
///
/// The following example defines a version requirement that accepts any
/// change in the develop branch.
///
/// .branch("develop")
///
/// - Parameters:
/// - name: The name of the branch.
static func branch(_ name: String) -> Package.Dependency.Requirement
/// Returns a requirement for a version range, starting at the given minimum
/// version and going up to the next major version. This is the recommended version requirement.
///
/// - Parameters:
/// - version: The minimum version for the version range.
static func upToNextMajor(from version: Version) -> Package.Dependency.Requirement
/// Returns a requirement for a version range, starting at the given minimum
/// version and going up to the next minor version.
///
/// - Parameters:
/// - version: The minimum version for the version range.
static func upToNextMinor(from version: Version) -> Package.Dependency.Requirement
```
# Version
`struct Version`
A version according to the semantic versioning specification.
A package version is a three period-separated integer, for example `1.0.0`. It must conform to the semantic versioning standard in order to ensure
that your package behaves in a predictable manner once developers update their
package dependency to a newer version. To achieve predictability, the semantic versioning specification proposes a set of rules and
requirements that dictate how version numbers are assigned and incremented. To learn more about the semantic versioning specification, visit
[semver.org](https://semver.org).
**The Major Version**
The first digit of a version, or *major version*, signifies breaking changes to the API that require
updates to existing clients. For example, the semantic versioning specification
considers renaming an existing type, removing a method, or changing a method's signature
breaking changes. This also includes any backward-incompatible bug fixes or
behavioral changes of the existing API.
**The Minor Version**
Update the second digit of a version, or *minor version*, if you add functionality in a backward-compatible manner.
For example, the semantic versioning specification considers adding a new method
or type without changing any other API to be backward-compatible.
**The Patch Version**
Increase the third digit of a version, or *patch version*, if you are making a backward-compatible bug fix.
This allows clients to benefit from bugfixes to your package without incurring
any maintenance burden.
# Target
`class Target`
A target, the basic building block of a Swift package.
Each target contains a set of source files that are compiled into a module or test suite.
You can vend targets to other packages by defining products that include the targets.
A target may depend on other targets within the same package and on products vended by the package's dependencies.
## Methods
```swift
/// Creates a regular target.
///
/// A target can contain either Swift or C-family source files, but not both. It contains code that is built as
/// a regular module that can be included in a library or executable product, but that cannot itself be used as
/// the main target of an executable product.
///
/// - Parameters:
/// - name: The name of the target.
/// - dependencies: The dependencies of the target. A dependency can be another target in the package or a product from a package dependency.
/// - path: The custom path for the target. By default, the Swift Package Manager requires a target's sources to reside at predefined search paths;
/// for example, `[PackageRoot]/Sources/[TargetName]`.
/// Don't escape the package root; for example, values like `../Foo` or `/Foo` are invalid.
/// - exclude: A list of paths to files or directories that the Swift Package Manager shouldn't consider to be source or resource files.
/// A path is relative to the target's directory.
/// This parameter has precedence over the `sources` parameter.
/// - sources: An explicit list of source files. If you provide a path to a directory,
/// the Swift Package Manager searches for valid source files recursively.
/// - resources: An explicit list of resources files.
/// - publicHeadersPath: The directory containing public headers of a C-family library target.
/// - cSettings: The C settings for this target.
/// - cxxSettings: The C++ settings for this target.
/// - swiftSettings: The Swift settings for this target.
/// - linkerSettings: The linker settings for this target.
static func target(
name: String,
dependencies: [Target.Dependency] = [],
path: String? = nil,
exclude: [String] = [],
sources: [String]? = nil,
resources: [Resource]? = nil,
publicHeadersPath: String? = nil,
cSettings: [CSetting]? = nil,
cxxSettings: [CXXSetting]? = nil,
swiftSettings: [SwiftSetting]? = nil,
linkerSettings: [LinkerSetting]? = nil
) -> Target
/// Creates an executable target.
///
/// An executable target can contain either Swift or C-family source files, but not both. It contains code that
/// is built as an executable module that can be used as the main target of an executable product. The target
/// is expected to either have a source file named `main.swift`, `main.m`, `main.c`, or `main.cpp`, or a source
/// file that contains the `@main` keyword.
///
/// - Parameters:
/// - name: The name of the target.
/// - dependencies: The dependencies of the target. A dependency can be another target in the package or a product from a package dependency.
/// - path: The custom path for the target. By default, the Swift Package Manager requires a target's sources to reside at predefined search paths;
/// for example, `[PackageRoot]/Sources/[TargetName]`.
/// Don't escape the package root; for example, values like `../Foo` or `/Foo` are invalid.
/// - exclude: A list of paths to files or directories that the Swift Package Manager shouldn't consider to be source or resource files.
/// A path is relative to the target's directory.
/// This parameter has precedence over the `sources` parameter.
/// - sources: An explicit list of source files. If you provide a path to a directory,
/// the Swift Package Manager searches for valid source files recursively.
/// - resources: An explicit list of resources files.
/// - publicHeadersPath: The directory containing public headers of a C-family library target.
/// - cSettings: The C settings for this target.
/// - cxxSettings: The C++ settings for this target.
/// - swiftSettings: The Swift settings for this target.
/// - linkerSettings: The linker settings for this target.
static func executableTarget(
name: String,
dependencies: [Target.Dependency] = [],
path: String? = nil,
exclude: [String] = [],
sources: [String]? = nil,
resources: [Resource]? = nil,
publicHeadersPath: String? = nil,
cSettings: [CSetting]? = nil,
cxxSettings: [CXXSetting]? = nil,
swiftSettings: [SwiftSetting]? = nil,
linkerSettings: [LinkerSetting]? = nil
) -> Target
/// Creates a test target.
///
/// Write test targets using the XCTest testing framework.
/// Test targets generally declare a dependency on the targets they test.
///
/// - Parameters:
/// - name: The name of the target.
/// - dependencies: The dependencies of the target. A dependency can be another target in the package or a product from a package dependency.
/// - path: The custom path for the target. By default, the Swift Package Manager requires a target's sources to reside at predefined search paths;
/// for example, `[PackageRoot]/Sources/[TargetName]`.
/// Don't escape the package root; for example, values like `../Foo` or `/Foo` are invalid.
/// - exclude: A list of paths to files or directories that the Swift Package Manager shouldn't consider to be source or resource files.
/// A path is relative to the target's directory.
/// This parameter has precedence over the `sources` parameter.
/// - sources: An explicit list of source files. If you provide a path to a directory,
/// the Swift Package Manager searches for valid source files recursively.
/// - resources: An explicit list of resources files.
/// - cSettings: The C settings for this target.
/// - cxxSettings: The C++ settings for this target.
/// - swiftSettings: The Swift settings for this target.
/// - linkerSettings: The linker settings for this target.
static func testTarget(
name: String,
dependencies: [Target.Dependency] = [],
path: String? = nil,
exclude: [String] = [],
sources: [String]? = nil,
resources: [Resource]? = nil,
cSettings: [CSetting]? = nil,
cxxSettings: [CXXSetting]? = nil,
swiftSettings: [SwiftSetting]? = nil,
linkerSettings: [LinkerSetting]? = nil
) -> Target
/// Creates a system library target.
///
/// Use system library targets to adapt a library installed on the system to work with Swift packages.
/// Such libraries are generally installed by system package managers (such as Homebrew and apt-get)
/// and exposed to Swift packages by providing a `modulemap` file along with other metadata such as the library's `pkgConfig` name.
///
/// - Parameters:
/// - name: The name of the target.
/// - path: The custom path for the target. By default, the Swift Package Manager requires a target's sources to reside at predefined search paths;
/// for example, `[PackageRoot]/Sources/[TargetName]`.
/// Don't escape the package root; for example, values like `../Foo` or `/Foo` are invalid.
/// - pkgConfig: The name of the `pkg-config` file for this system library.
/// - providers: The providers for this system library.
static func systemLibrary(
name: String,
path: String? = nil,
pkgConfig: String? = nil,
providers: [SystemPackageProvider]? = nil
) -> Target
/// Creates a binary target that references a remote artifact.
///
/// A binary target provides the url to a pre-built binary artifact for the target. Currently only supports
/// artifacts for Apple platforms.
///
/// - Parameters:
/// - name: The name of the target.
/// - url: The URL to the binary artifact. This URL must point to an archive file
/// that contains a binary artifact in its root directory.
/// - checksum: The checksum of the archive file that contains the binary artifact.
///
/// Binary targets are only available on Apple platforms.
static func binaryTarget(
name: String,
url: String,
checksum: String
) -> Target
/// Creates a binary target that references an artifact on disk.
///
/// A binary target provides the path to a pre-built binary artifact for the target.
/// The Swift Package Manager only supports binary targets for Apple platforms.
///
/// - Parameters:
/// - name: The name of the target.
/// - path: The path to the binary artifact. This path can point directly to a binary artifact
/// or to an archive file that contains the binary artifact at its root.
///
/// Binary targets are only available on Apple platforms.
static func binaryTarget(
name: String,
path: String
) -> Target
```
# Target Dependency
`class Target.Dependency`
The different types of a target's dependency on another entity.
## Methods
```swift
/// Creates a dependency on a target in the same package.
///
/// - parameters:
/// - name: The name of the target.
/// - condition: A condition that limits the application of the target dependency. For example, only apply a
/// dependency for a specific platform.
static func target(
name: String,
condition: TargetDependencyCondition? = nil
) -> Target.Dependency
/// Creates a target dependency on a product from a package dependency.
///
/// - parameters:
/// - name: The name of the product.
/// - package: The name of the package.
/// - condition: A condition that limits the application of the target dependency. For example, only apply a
/// dependency for a specific platform.
static func product(
name: String,
package: String,
condition: TargetDependencyCondition? = nil
) -> Target.Dependency
/// Creates a by-name dependency that resolves to either a target or a product but after the Swift Package Manager
/// has loaded the package graph.
///
/// - parameters:
/// - name: The name of the dependency, either a target or a product.
/// - condition: A condition that limits the application of the target dependency. For example, only apply a
/// dependency for a specific platform.
static func byName(
name: String
condition: TargetDependencyCondition? = nil
) -> Target.Dependency
```
# Target Dependency Condition
`class TargetDependencyCondition`
A condition that limits the application of a target's dependency.
## Methods
```swift
/// Creates a target dependency condition.
///
/// - Parameters:
/// - platforms: The applicable platforms for this target dependency condition.
static func when(platforms: [Platform]? = nil) -> TargetDependencyCondition
```
# Resource
`struct Resource`
A resource to bundle with the Swift package.
If a Swift package declares a Swift tools version of 5.3 or later, it can include resource files.
Similar to source code, the Swift Package Manager scopes resources to a target, so you must put them
into the folder that corresponds to the target they belong to.
For example, any resources for the `MyLibrary` target must reside in `Sources/MyLibrary`.
Use subdirectories to organize your resource files in a way that simplifies file identification and management.
For example, put all resource files into a directory named `Resources`,
so they reside at `Sources/MyLibrary/Resources`.
By default, the Swift Package Manager handles common resources types for Apple platforms automatically.
For example, you don’t need to declare XIB files, storyboards, Core Data file types, and asset catalogs
as resources in your package manifest.
However, you must explicitly declare other file types—for example image files—as resources
using the `process(_:localization:)` or `copy(_:)` rules.
Alternatively, exclude resource files from a target
by passing them to the target initializer’s `exclude` parameter.
## Methods
```swift
/// Applies a platform-specific rule to the resource at the given path.
///
/// Use the `process` rule to process resources at the given path
/// according to the platform it builds the target for. For example, the
/// Swift Package Manager may optimize image files for platforms that
/// support such optimizations. If no optimization is available for a file
/// type, the Swift Package Manager copies the file.
///
/// If the given path represents a directory, the Swift Package Manager
/// applies the process rule recursively to each file in the directory.
///
/// If possible use this rule instead of `copy(_:)`.
///
/// - Parameters:
/// - path: The path for a resource.
/// - localization: The explicit localization type for the resource.
static func process(
_ path: String,
localization: Localization? = nil
) -> Resource
/// Applies the copy rule to a resource at the given path.
///
/// If possible, use `process(_:localization:)`` and automatically apply optimizations
/// to resources.
///
/// If your resources must remain untouched or must retain a specific folder structure,
/// use the `copy` rule. It copies resources at the given path, as is, to the top level
/// in the package’s resource bundle. If the given path represents a directory, Xcode preserves its structure.
///
/// - Parameters:
/// - path: The path for a resource.
static func copy(
_ path: String
) -> Resource
```
# Localization
`struct Resource.Localization`
Defines the explicit type of localization for resources.
## Cases
```swift
/// A constant that represents default internationalization.
case `default`
/// A constant that represents base internationalization.
case base
```
# LanguageTag
`struct LanguageTag`
A wrapper around an IETF language tag.
To learn more about the IETF worldwide standard for language tags,
see [RFC5646](https://tools.ietf.org/html/rfc5646).
## Methods
```swift
/// Creates a language tag from its IETF string representation.
init(_ tag: String)
```
# CSetting
`struct CSetting`
A C-language build setting.
## Methods
```swift
/// Provides a header search path relative to the target's directory.
///
/// Use this setting to add a search path for headers within your target.
/// You can't use absolute paths and you can't use this setting to provide
/// headers that are visible to other targets.
///
/// The path must be a directory inside the package.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameters:
/// - path: The path of the directory that contains the headers. The path is relative to the target's directory.
/// - condition: A condition that restricts the application of the build setting.
static func headerSearchPath(_ path: String, _ condition: BuildSettingCondition? = nil) -> CSetting
/// Defines a value for a macro.
///
/// If you don't specify a value, the macro's default value is 1.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameters:
/// - name: The name of the macro.
/// - value: The value of the macro.
/// - condition: A condition that restricts the application of the build setting.
static func define(_ name: String, to value: String? = nil, _ condition: BuildSettingCondition? = nil) -> CSetting
/// Sets unsafe flags to pass arbitrary command-line flags to the corresponding build tool.
///
/// As the usage of the word "unsafe" implies, the Swift Package Manager
/// can't safely determine if the build flags have any negative
/// side effect on the build since certain flags can change the behavior of
/// how it performs a build.
///
/// As some build flags can be exploited for unsupported or malicious
/// behavior, the use of unsafe flags make the products containing this
/// target ineligible for use by other packages.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameters:
/// - flags: The unsafe flags to set.
/// - condition: A condition that restricts the application of the build setting.
static func unsafeFlags(_ flags: [String], _ condition: BuildSettingCondition? = nil) -> CSetting
```
# CXXSetting
`struct CXXSetting`
A CXX-language build setting.
## Methods
```swift
/// Provides a header search path relative to the target's directory.
///
/// Use this setting to add a search path for headers within your target.
/// You can't use absolute paths and you can't use this setting to provide
/// headers that are visible to other targets.
///
/// The path must be a directory inside the package.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameters:
/// - path: The path of the directory that contains the headers. The path is relative to the target's directory.
/// - condition: A condition that restricts the application of the build setting.
static func headerSearchPath(_ path: String, _ condition: BuildSettingCondition? = nil) -> CXXSetting
/// Defines a value for a macro.
///
/// If you don't specify a value, the macro's default value is 1.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameters:
/// - name: The name of the macro.
/// - value: The value of the macro.
/// - condition: A condition that restricts the application of the build setting.
static func define(_ name: String, to value: String? = nil, _ condition: BuildSettingCondition? = nil) -> CXXSetting
/// Sets unsafe flags to pass arbitrary command-line flags to the corresponding build tool.
///
/// As the usage of the word "unsafe" implies, the Swift Package Manager
/// can't safely determine if the build flags have any negative
/// side effect on the build since certain flags can change the behavior of
/// how a build is performed.
///
/// As some build flags can be exploited for unsupported or malicious
/// behavior, a product can't be used as a dependency in another package if one of its targets uses unsafe flags.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameters:
/// - flags: The unsafe flags to set.
/// - condition: A condition that restricts the application of the build setting.
static func unsafeFlags(_ flags: [String], _ condition: BuildSettingCondition? = nil) -> CXXSetting
```
# SwiftSetting
`struct SwiftSetting`
A Swift language build setting.
## Methods
```swift
/// Defines a compilation condition.
///
/// Use compilation conditions to only compile statements if a certain condition is true.
/// For example, the Swift compiler will only compile the
/// statements inside the `#if` block when `ENABLE_SOMETHING` is defined:
///
/// #if ENABLE_SOMETHING
/// ...
/// #endif
///
/// Unlike macros in C/C++, compilation conditions don't have an
/// associated value.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameters:
/// - name: The name of the macro.
/// - condition: A condition that restricts the application of the build setting.
static func define(_ name: String, _ condition: BuildSettingCondition? = nil) -> SwiftSetting
/// Sets unsafe flags to pass arbitrary command-line flags to the corresponding build tool.
///
/// As the usage of the word "unsafe" implies, the Swift Package Manager
/// can't safely determine if the build flags have any negative
/// side effect on the build since certain flags can change the behavior of
/// how a build is performed.
///
/// As some build flags can be exploited for unsupported or malicious
/// behavior, a product can't be used as a dependency in another package if one of its targets uses unsafe flags.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameters:
/// - flags: The unsafe flags to set.
/// - condition: A condition that restricts the application of the build setting..
static func unsafeFlags(_ flags: [String], _ condition: BuildSettingCondition? = nil) -> SwiftSetting
```
# LinkerSetting
`struct LinkerSetting`
A linker build setting.
## Methods
```swift
/// Declares linkage to a system library.
///
/// This setting is most useful when the library can't be linked
/// automatically, such as C++ based libraries and non-modular
/// libraries.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameters:
/// - library: The library name.
/// - condition: A condition that restricts the application of the build setting.
static func linkedLibrary(_ library: String, _ condition: BuildSettingCondition? = nil) -> LinkerSetting
/// Declares linkage to a system framework.
///
/// This setting is most useful when the framework can't be linked
/// automatically, such as C++ based frameworks and non-modular
/// frameworks.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameters:
/// - framework: The framework name.
/// - condition: A condition that restricts the application of the build setting.
static func linkedFramework(_ framework: String, _ condition: BuildSettingCondition? = nil) -> LinkerSetting
/// Sets unsafe flags to pass arbitrary command-line flags to the corresponding build tool.
///
/// As the usage of the word "unsafe" implies, the Swift Package Manager
/// can't safely determine if the build flags have any negative
/// side effect on the build since certain flags can change the behavior of
/// how a build is performed.
///
/// As some build flags can be exploited for unsupported or malicious
/// behavior, a product can't be used as a dependency in another package if one of its targets uses unsafe flags.
///
/// - Since: First available in PackageDescription 5.0
///
/// - Parameters:
/// - flags: The unsafe flags to set.
/// - condition: A condition that restricts the application of the build setting.
static func unsafeFlags(_ flags: [String], _ condition: BuildSettingCondition? = nil) -> LinkerSetting
```
# SwiftVersion
`enum SwiftVersion`
The version of the Swift language to use for compiling Swift sources in the package.
```swift
enum SwiftVersion {
case v3
case v4
case v4_2
case v5
/// A user-defined value for the Swift version.
///
/// The value is passed as-is to the Swift compiler's `-swift-version` flag.
case version(String)
}
```
# CLanguageStandard
`enum CLanguageStandard`
The supported C language standard to use for compiling C sources in the package.
```swift
enum CLanguageStandard {
case c89
case c90
case c99
case c11
case c17
case c18
case c2x
case gnu89
case gnu90
case gnu99
case gnu11
case gnu17
case gnu18
case gnu2x
case iso9899_1990 = "iso9899:1990"
case iso9899_199409 = "iso9899:199409"
case iso9899_1999 = "iso9899:1999"
case iso9899_2011 = "iso9899:2011"
case iso9899_2017 = "iso9899:2017"
case iso9899_2018 = "iso9899:2018"
}
```
# CXXLanguageStandard
`enum CXXLanguageStandard`
The supported C++ language standard to use for compiling C++ sources in the package.
```swift
enum CXXLanguageStandard {
case cxx98 = "c++98"
case cxx03 = "c++03"
case cxx11 = "c++11"
case cxx14 = "c++14"
case cxx17 = "c++17"
case cxx1z = "c++1z"
case cxx20 = "c++20"
case cxx2b = "c++2b"
case gnucxx98 = "gnu++98"
case gnucxx03 = "gnu++03"
case gnucxx11 = "gnu++11"
case gnucxx14 = "gnu++14"
case gnucxx17 = "gnu++17"
case gnucxx1z = "gnu++1z"
case gnucxx20 = "gnu++20"
case gnucxx2b = "gnu++2b"
}
```
|