Skip to content

Replace import Foundation with FoundationEssentials#897

Open
madsodgaard wants to merge 16 commits intoswift-server:mainfrom
madsodgaard:foundation-essentials
Open

Replace import Foundation with FoundationEssentials#897
madsodgaard wants to merge 16 commits intoswift-server:mainfrom
madsodgaard:foundation-essentials

Conversation

@madsodgaard
Copy link
Contributor

@madsodgaard madsodgaard commented Mar 3, 2026

Replaces all the foundation imports.

One issue is that HTTPClient.init?(httpsURLWithSocketPath socketPath: String, uri: String = "/") uses addingPercentEncoding() from Foundation. So instead, we use a pure Swift impl. that does the same.

We also need to disable default traits from swift-configuration to prevent linking Foundation, because the JSON trait does that.

This also adds a linkage test to prevent regressions to CI.

@t089
Copy link
Contributor

t089 commented Mar 3, 2026

One option could be to vendor / copy the percent encoding from FoundationEssentials (too bad this is not public api)

https://github.com/swiftlang/swift-foundation/blob/479abe7e3a9df37c02a2a228d482f2d8978b3f91/Sources/FoundationEssentials/URL/URLEncoder.swift#L55

@madsodgaard
Copy link
Contributor Author

madsodgaard commented Mar 3, 2026

@t089 Yeah, that is similar to what I did for swift-openapi-runtime apple/swift-openapi-runtime#176

@t089
Copy link
Contributor

t089 commented Mar 3, 2026

Feels like we should create a swift-percent-encoding nano package ... if only there was a package that could host such foundational essentials ...

@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Mar 3, 2026
@madsodgaard
Copy link
Contributor Author

madsodgaard commented Mar 4, 2026

Unfortunately the URLComponents APIs did not behave as a I expected. So, I had to move away from them, and use a Swift-only impl of addingPercentEncoding, which we also did for swift-openapi-runtime.

@madsodgaard madsodgaard requested review from Lukasa and weissi March 4, 2026 10:20
@0xTim
Copy link
Member

0xTim commented Mar 4, 2026

Created swiftlang/swift-foundation#1796

ktoso added a commit to swiftlang/swift-java-jni-core that referenced this pull request Mar 5, 2026
ktoso added a commit to swiftlang/swift-java-jni-core that referenced this pull request Mar 5, 2026
* Include LinkageTest to avoid accidentally linking Foundation

This is based off the test included in
swift-server/async-http-client#897 by @Mads

* try simplified linkage test and install java before it

* work on env var

* JAVA_HOME detection in LinkageTest

* fix typo
.package(url: "https://github.com/apple/swift-distributed-tracing.git", from: "1.3.0"),
.package(url: "https://github.com/apple/swift-configuration.git", from: "1.0.0"),
// Disable all traits to prevent linking Foundation
.package(url: "https://github.com/apple/swift-configuration.git", from: "1.0.0", traits: []),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a breaking change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, since AHC wasn't using any of the API that's guarded by the default traits.

@madsodgaard
Copy link
Contributor Author

Hey, just wanted to follow up on this. Anything missing from my end?

Would be great to move this along, it's one of the final things missing for us to remove full Foundation dependency👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants