# The adoption of \`import FoundationEssentials\` throughout the package ecosystem

**URL:** <https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112>\
**Category:** Development\
**Created:** [January 13, 2026, 4:28pm UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112 "2026-01-13T16:28:17Z")\
**Posts on this page:** 14\
**Page:** 2

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [February 24, 2026, 4:01pm UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/22 "2026-02-24T16:01:36Z")

</div>

> [@allevato](#):
>
> `MemberImportVisibility` specifically carves out an exception for re-exports (either through Clang modules' `export *` or Swift's `@_exported import`), and `Foundation` re-exports `FoundationEssentials`, so I don't believe that alone would help matters?

That should still be fine if `A` in the example above doesn’t itself re-export `Foundation`, right? Or does the exception apply through the whole tree?

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [February 24, 2026, 4:29pm UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/23 "2026-02-24T16:29:27Z")

</div>

> [@xwu](#):
>
> That should still be fine if `A` in the example above doesn’t itself re-export `Foundation`, right? Or does the exception apply through the whole tree?

In isolation, I think that case would be fine.

In practice, for a project that has many more imports, it might not be as straightforward. Clang modules are notoriously leaky as well, at least in Apple's SDKs, which all use `export *` to avoid breaking clients when they migrate to modules if they rely on C's "importing a header means you can see everything it imports, transitively" textual inclusion behavior. So importing some other Clang module in that file, if it depends on Foundation, might cause the same issue to reemerge.

Of course, this may not be the case on non-Apple platforms where Foundation has a pure Swift implementation (ignoring CoreFoundation, of course), and that seems to be the focus of this discussion. I would hope that Apple platforms would also figure out how to represent `FoundationEssentials/Internationalization` as well so that we can _truly_ write cross-platform packages without conditional compilation, but I realize there are decades worth of ABI and source compatibility concerns at play there, which are also entirely out of scope for the Swift open-source project.

---

<div class="post-metadata">

**Author:** ![Cyberbeni](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cyberbeni/32/46241_2.png) [@Cyberbeni](https://forums.swift.org/u/Cyberbeni)\
**Post date:** [February 25, 2026, 9:34am UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/24 "2026-02-25T09:34:16Z")

</div>

Is anyone actually working on getting the changes merged? I've seen no activity in the repos that are blocking my projects from removing Foundation dependency:

> <https://github.com/apple/swift-metrics/pull/158>
>
> Use FoundationEssentials if it is available
> 
> \### Motivation:
> 
> Reduce size of… any application using swift-metrics on linux

> <https://github.com/apple/swift-crypto/pull/317>
>
> Use \`FoundationEssentials\` if available.
> 
> 
> 
> \### Checklist
> \- \[x\] I've run te…sts to see all new and existing tests pass (macOS and linux)
> \- \[x\] I've followed the code style of the rest of the project
> \- \[x\] I've read the \[Contribution Guidelines\](CONTRIBUTING.md)
> \- \[x\] I've updated the documentation if necessary
> 
> \#### If you've made changes to \`gyb\` files
> \- \[\] I've run \`.script/generate\_boilerplate\_files\_with\_gyb\` and included updated generated files in a commit of this pull request
> \`\`\`
> bash .script/generate\_boilerplate\_files\_with\_gyb
> bash: .script/generate\_boilerplate\_files\_with\_gyb: No such file or directory
> \`\`\`
> 
> \### Motivation:
> 
> Would be great that packages that depend on \`swift-crypto\` can be built without linking full \`Foundation\`.
> 
> \### Modifications:
> 
> This patch simply replaces \`import Foundation\` with a conditional \`import FoundationEssentials\`.
> 
> In some files this also required to explicitly import the C standard lib.
> 
> Maybe we could follow the same approach as in https://github.com/swiftlang/swift-tools-support-core/blob/main/Sources/TSCLibc/libc.swift and add an internal module that abstracts this import dance in a single place.
> 
> \### Result:
> 
> After this change the package should only depend on \`FoundationEssentials\`.

As for `InternalImportsByDefault`, I think it should've been something that's defined in Package.swift (and through swiftc parameters when using cmake/etc.), so there is a single source of truth for which dependencies are allowed to be used in public APIs.

---

<div class="post-metadata">

**Author:** ![madsodgaard](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/madsodgaard/32/43318_2.png) [@madsodgaard](https://forums.swift.org/u/madsodgaard)\
**Post date:** [February 25, 2026, 9:39am UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/25 "2026-02-25T09:39:45Z")

</div>

I am slowly working through some. Did PRs for protobuf: [Move runtime to `FoundationEssentials` by madsodgaard · Pull Request #1993 · apple/swift-protobuf · GitHub](https://github.com/apple/swift-protobuf/pull/1993) and looking at openapi-runtime.

The changes should be quite simple if the package does not use anything from Foundation. So I am sure the maintainers would appreciate a PR 😃

---

<div class="post-metadata">

**Author:** ![ktoso](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ktoso/32/44526_2.png) [@ktoso](https://forums.swift.org/u/ktoso)\
**Post date:** [February 25, 2026, 10:59am UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/26 "2026-02-25T10:59:18Z")

</div>

> [@Cyberbeni](#):
>
> Is anyone actually working on getting the changes merged?

I mean the ESG update was literarily yesterday... Yes, SSWG projects will move to adopt this pattern.

---

<div class="post-metadata">

**Author:** ![t089](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/t089/32/40449_2.png) [@t089](https://forums.swift.org/u/t089)\
**Post date:** [February 25, 2026, 11:33am UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/27 "2026-02-25T11:33:32Z")

</div>

It might make sense to add a CI step to validate that the produced products don't "accidentally" link Foundation. I think we did something like this in the AWS Lambda runtime. CC @sebsto

---

<div class="post-metadata">

**Author:** ![sebsto](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sebsto/32/27165_2.png) [@sebsto](https://forums.swift.org/u/sebsto)\
**Post date:** [February 25, 2026, 11:48am UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/28 "2026-02-25T11:48:07Z")

</div>

Indeed, I wrote a script that runs in the CI to check the absence of foundation-related libraries. The scripts builds a Lambda function and checks that the binary is not linked with `libFoundation.so`, `libFoundationInternationalization.so`, or `lib_FoundationICU.so`

The scrip is here

> <https://github.com/awslabs/swift-aws-lambda-runtime/blob/main/.github/workflows/scripts/check-link-foundation.sh>

Happy to read your feedback

---

<div class="post-metadata">

**Author:** ![Cyberbeni](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cyberbeni/32/46241_2.png) [@Cyberbeni](https://forums.swift.org/u/Cyberbeni)\
**Post date:** [April 17, 2026, 11:18am UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/29 "2026-04-17T11:18:14Z")

</div>

Is there a reason why straightforward PRs get ignored for weeks/months?

The swift-crypto PR is still open (although the person should just be blocked and the PR closed, so someone who doesn't do license laundering can create a new PR)

Then these are also already 2 weeks old:

> <https://github.com/apple/swift-nio/pull/3567>
>
> Split FoundationEssentials extensions from NIOFoundationCompat
> 
> \### Motivation…:
> 
> Resolves #3038 
> 
> \### Modifications:
> 
> Split NIOFoundationCompat into two and only import FoundationEssentials and NIOFoundationEssentialsCompat where appropriate.
> 
> \### Result:
> 
> ByteBuffer/Codable extensions can be used without vendoring the code or linking to Foundation.

> <https://github.com/apple/swift-nio-transport-services/pull/251>
>
> Only depend on NIOFoundationCompat on Apple platforms
> 
> \### Motivation:
> 
> http…s://github.com/apple/swift-nio-transport-services/pull/211#issuecomment-4170778092
> 
> \### Modifications:
> 
> Only depend on NIOFoundationCompat on Apple platforms because it's only imported when Network can also be imported, so we don't unnecessarily depend transitively on Foundation.
> 
> (We should use anyAppleOS as the condition if/when it becomes available in SPM too: https://forums.swift.org/t/introducing-anyappleos/85728 )
> 
> \### Result:
> 
> Stripped release binary is 20MB instead of 65MB in a project using mqtt-nio

---

<div class="post-metadata">

**Author:** ![snej](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/snej/32/365_2.png) [@snej](https://forums.swift.org/u/snej)\
**Post date:** [April 17, 2026, 3:54pm UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/30 "2026-04-17T15:54:03Z")

</div>

Yesterday I went through my package-in-progress and Essentials-ized as many imports as possible. Of the source files that actually needed Foundation, in a few cases it was due to Unicode support, which I can probably do without, but more often due to the use of FileManager or Input/OutputStream.

It seems sad that I can’t use standard filesystem APIs without dragging in all of ICU too.

Is there any alternative? I know about FileDescriptor (sp?) but that would require writing a higher-level streaming API around it. It might also expose platform-specific behaviors. And as for a DIY FileManager, I know from experience that building a robust cross-platform API for manipulating the filesystem is nontrivial.

---

<div class="post-metadata">

**Author:** ![t089](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/t089/32/40449_2.png) [@t089](https://forums.swift.org/u/t089)\
**Post date:** [April 17, 2026, 3:57pm UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/31 "2026-04-17T15:57:59Z")

</div>

Can you try [NIOFileSystem](https://github.com/apple/swift-nio/tree/main/Sources/_NIOFileSystem)?

---

<div class="post-metadata">

**Author:** ![Joannis\_Orlandos](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joannis_orlandos/32/732_2.png) [@Joannis\_Orlandos](https://forums.swift.org/u/Joannis_Orlandos)\
**Post date:** [April 18, 2026, 6:35pm UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/32 "2026-04-18T18:35:30Z")

</div>

Or [GitHub - swiftlang/swift-subprocess: Subprocess is a cross-platform package for spawning processes in Swift. · GitHub](https://github.com/swiftlang/swift-subprocess) for Process

---

<div class="post-metadata">

**Author:** ![niktishakov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/niktishakov/32/47689_2.png) [@niktishakov](https://forums.swift.org/u/niktishakov)\
**Post date:** [October 15, 2026, 7:14pm UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/33 "2026-10-15T19:14:44Z")

</div>

While measuring Android app sizes I kept running into the "which dependency still pulls in Foundation?" question, so I wrote a small tool for it: [why-foundation](https://github.com/niktishakov/why-foundation).

It loads the resolved package graph, evaluates `#if` conditions, package traits and `swiftSettings` defines for Android or Linux, and lists every target that still pulls in Foundation, with the dependency path that leads there:

```swift
swift-protobuf › SwiftProtobuf
  path: Shared → SwiftProtobuf (swift-protobuf)
  resources in Package.swift (SwiftPM's generated resource accessor imports Foundation)
  Sources/SwiftProtobuf/BinaryDelimited.swift:16 import Foundation

```

It also sorts the findings into targets that look easy to switch to `FoundationEssentials`, targets that use APIs only available in full Foundation (`URLSession`, `NSLock`, legacy formatters), and Apple-only targets. It works on packages and on the package dependencies of Xcode projects. I checked its verdicts against `llvm-readelf` on real Android builds.

It complements the CI linkage check @sebsto mentioned above: that one tells you Foundation got linked, this one tells you why.

One thing it surfaced: packages that declare `PrivacyInfo.xcprivacy` under `#if canImport(Darwin)` still link Foundation when you cross-compile for Android from a Mac, because the manifest is evaluated on the host. swift-crypto is one example. I opened [swiftlang/swift-package-manager#10694](https://github.com/swiftlang/swift-package-manager/pull/10694), which limits privacy manifests to Apple platforms in Swift Build, so this gets fixed without changes to the packages.

Feedback welcome, especially false positives.

**Update:** it's now also a GitHub Action, so the CI check from the guidance above is one step:

```yaml
- uses: niktishakov/why-foundation@v0
  with:
    product: MyLibrary

```

It downloads a prebuilt binary, so it takes seconds on Linux and macOS runners.

---

<div class="post-metadata">

**Author:** ![Cyberbeni](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/cyberbeni/32/46241_2.png) [@Cyberbeni](https://forums.swift.org/u/Cyberbeni)\
**Post date:** [October 15, 2026, 9:31pm UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/34 "2026-10-15T21:31:20Z")

</div>

@niktishakov Isn't it fixed already in Swift 6.4.1? [[6.4.1] Ignore undeclared PrivacyInfo.xcprivacy when not targeting Apple platforms by rconnell9 · Pull Request #10580 · swiftlang/swift-package-manager · GitHub](https://github.com/swiftlang/swift-package-manager/pull/10580)

edit: nevermind, that's for when it's not declared in Package.swift

---

<div class="post-metadata">

**Author:** ![niktishakov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/niktishakov/32/47689_2.png) [@niktishakov](https://forums.swift.org/u/niktishakov)\
**Post date:** [October 16, 2026, 6:45am UTC](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/35 "2026-10-16T06:45:22Z")

</div>

Right, [swiftlang/swift-package-manager#10580](https://github.com/swiftlang/swift-package-manager/pull/10580) covers privacy manifests that aren’t declared in `Package.swift`. Packages like swift-crypto declare it under `#if canImport(Darwin)`, which is still true when you cross-compile from a Mac, so they keep linking Foundation. [swiftlang/swift-package-manager#10694](https://github.com/swiftlang/swift-package-manager/pull/10694) is the follow-up that was discussed in the review of [swiftlang/swift-package-manager#10575](https://github.com/swiftlang/swift-package-manager/pull/10575).

[Previous page](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112.md?page=1)
