Skip to content

Commit 6287938

Browse files
authored
Add Distributions.md and README section on obtaining Foundation (swiftlang#1848)
* Add Distributions.md and README section on obtaining Foundation Clarifies that the swift-foundation package exists to support Foundation's own development/testing workflow, and is not intended for use as a package dependency by other projects. * clarify the wording * reword a bit * Refinement * Emphasize that it's not supported to use the package for production purposes
1 parent 13a9723 commit 6287938

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

Distributions.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ On macOS, iOS, and other Apple platforms, apps should use the Foundation that co
1515

1616
On all other Swift platforms, `swift-foundation` is available as part of the toolchain. Simply `import FoundationEssentials` or `import FoundationInternationalization` to use its API. It is also re-exported from [swift-corelibs-foundation](http://github.com/apple/swift-corelibs-foundation)'s `Foundation`, `FoundationXML`, and `FoundationNetworking` modules.
1717

18+
## Obtaining Foundation
19+
20+
Foundation is available in several forms — built into the OS on Apple platforms,
21+
included in Swift toolchains, and as a Swift package. For guidance on which to
22+
use and the tradeoffs involved, see [Distributions.md](Distributions.md).
23+
24+
> [!IMPORTANT]
25+
> The swift-foundation package is intended to support development and testing of
26+
> Foundation itself. It is not supported for use as a package dependency in
27+
> other shipping projects. Prefer the built-in copy of Foundation that ships with
28+
> your toolchain or operating system instead.
29+
1830
## Building and Testing
1931

2032
> [!NOTE]

0 commit comments

Comments
 (0)