Adopt FoundationEssentials instead of Foundation where available#317
Adopt FoundationEssentials instead of Foundation where available#317t089 wants to merge 1 commit intoapple:mainfrom
Conversation
|
Thanks for this! This is a worthwhile change but we have to be careful with merging it, as it requires a semver major due to Swift’s “leaky” imports. |
hm, not sure I follow. Are you saying, |
|
It doesn’t make the full API available, but it makes some things available. An example of one such problem is available at https://forums.swift.org/t/pitch-fixing-member-import-visibility/71432. The Swift team consider this a bug, and I agree, but our semver policies take the language as it is, not as it is intended to be. So this will require us to burn a major. The good news is that a) this will be a “cheap” major, as most codebases won’t be affected and so they can use a both-major range, and b) we have to do one anyway. So we’ll definitely make this change, I just wanted to clarify that it won’t be immediately merged. |
|
@Lukasa would a package trait help us here? |
|
Not really, the impending major is enough. |
Replace bare `import Foundation` with conditional `#if canImport(FoundationEssentials)` in the remaining source and test files that don't depend on Foundation-only APIs (FileHandle, CharacterSet). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1418c1d to
55b1eb5
Compare
Use
FoundationEssentialsif available.Checklist
If you've made changes to
gybfiles.script/generate_boilerplate_files_with_gyband included updated generated files in a commit of this pull requestMotivation:
Would be great that packages that depend on
swift-cryptocan be built without linking fullFoundation.Modifications:
This patch simply replaces
import Foundationwith a conditionalimport 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.