|
| 1 | +<!-- |
| 2 | +This source file is part of the Swift.org open source project |
| 3 | +
|
| 4 | +Copyright (c) 2026 Apple Inc. and the Swift project authors |
| 5 | +Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | +
|
| 7 | +See https://swift.org/LICENSE.txt for license information |
| 8 | +See https://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 9 | +--> |
| 10 | + |
| 11 | +# Obtaining Foundation |
| 12 | + |
| 13 | +There are multiple ways to obtain Foundation, and they have different tradeoffs |
| 14 | +to consider. This document discusses the various ways Foundation is distributed |
| 15 | +and offers recommended workflows. |
| 16 | + |
| 17 | +_This document was inspired by the equivalent [Distributions.md](https://github.com/swiftlang/swift-testing/blob/main/Distributions.md) in [swift-testing](https://github.com/swiftlang/swift-testing)._ |
| 18 | + |
| 19 | +## Distribution locations |
| 20 | + |
| 21 | +Foundation is distributed in the following places: |
| 22 | + |
| 23 | +* In Apple's [macOS, iOS, and other Apple platforms][apple-platforms], as a |
| 24 | + framework built into the operating system. |
| 25 | +* In [Swift.org toolchains][install], as a library included in the toolchain. |
| 26 | + |
| 27 | +The locations above are considered **built-in** because they're included with a |
| 28 | +larger collection of software (such as an operating system, toolchain, or IDE) |
| 29 | +and consist of _pre-compiled_ copies of the `FoundationEssentials` and |
| 30 | +`FoundationInternationalization` modules. |
| 31 | + |
| 32 | +> [!IMPORTANT] |
| 33 | +> Prefer using a built-in copy of Foundation unless you're making changes to |
| 34 | +> Foundation itself. |
| 35 | +
|
| 36 | +Foundation is also available as a Swift **package library product** from the |
| 37 | +[swiftlang/swift-foundation][swift-foundation] repository. This copy is _not_ |
| 38 | +considered built-in because it must be downloaded and compiled separately by |
| 39 | +each client. |
| 40 | + |
| 41 | +## Caveats when using swift-foundation as a package |
| 42 | + |
| 43 | +Although Foundation is available as a Swift package, and hence you _can_ declare |
| 44 | +a dependency on [swift-foundation][] during development, it is not suitable for |
| 45 | +use in a package or app that you intend to ship. Doing so has several downsides: |
| 46 | + |
| 47 | +* **It requires building Foundation and its dependencies from source.** |
| 48 | + This significantly increases your build time. |
| 49 | +* **You may encounter build failures when another package uses a built-in |
| 50 | + Foundation.** If you use swift-foundation as a package, but you depend on a |
| 51 | + library from another package which uses a built-in copy of Foundation (as |
| 52 | + this document recommends), this can cause build failures due to ambiguous |
| 53 | + symbol definitions or module conflicts. |
| 54 | + |
| 55 | +## When to use swift-foundation as a package |
| 56 | + |
| 57 | +If you are contributing to Foundation or otherwise working on its source code, |
| 58 | +building it as a Swift package is the recommended workflow. The core contributors |
| 59 | +regularly develop Foundation this way, and its CI builds as a package as well. |
| 60 | +See [Contributing][] for detailed steps on getting started. |
| 61 | + |
| 62 | +It's also sometimes helpful to use swift-foundation as a package in order to |
| 63 | +validate how changes made to Foundation will impact tools or libraries that |
| 64 | +depend on it, or to test changes to both Foundation and a related project in |
| 65 | +conjunction with each other. When using one of these workflows locally, it's |
| 66 | +important to be mindful of the [caveats][] above, but during local development |
| 67 | +it's often possible to take extra care to avoid those problems. |
| 68 | + |
| 69 | +[apple-platforms]: https://developer.apple.com/documentation/foundation |
| 70 | +[install]: https://www.swift.org/install |
| 71 | +[supported platforms]: https://github.com/swiftlang/swift-foundation/blob/main/README.md |
| 72 | +[Xcode IDE]: https://developer.apple.com/xcode/ |
| 73 | +[Command Line Tools for Xcode package]: https://developer.apple.com/documentation/xcode/installing-the-command-line-tools/ |
| 74 | +[swift-foundation]: https://github.com/swiftlang/swift-foundation |
| 75 | +[swift-collections]: https://github.com/swiftlang/swift-collections |
| 76 | +[swift-foundation-icu]: https://github.com/swiftlang/swift-foundation-icu |
| 77 | +[swift-syntax]: https://github.com/swiftlang/swift-syntax |
| 78 | +[Contributing]: https://github.com/swiftlang/swift-foundation/blob/main/CONTRIBUTING.md |
| 79 | +[caveats]: #caveats-when-using-swift-foundation-as-a-package |
0 commit comments