Skip to content

Add Linux support#8

Merged
BrentMifsud merged 7 commits intomainfrom
bm/linux-support
Mar 2, 2026
Merged

Add Linux support#8
BrentMifsud merged 7 commits intomainfrom
bm/linux-support

Conversation

@BrentMifsud
Copy link
Copy Markdown
Owner

Summary

  • Adds a Linux CI job (swift:6.2 container on ubuntu-latest) to the existing test matrix
  • Adds #if canImport(FoundationNetworking) conditional imports across source and test files so the package compiles on Linux, where URLSession, URLRequest, URLCache, etc. live in FoundationNetworking rather than Foundation
  • Works around a swift-corelibs-foundation bug where URLCache does not differentiate cache entries by URL query parameters, using synthetic cache-key URLs that encode the full URL into the path component

Notable platform differences handled

  • public import vs import for FoundationNetworking depending on whether the file exposes networking types in its public API (MemberImportVisibility)
  • @inlinable removed from CachePolicy.urlRequestCachePolicy because swift-corelibs-foundation's URLRequest.CachePolicy cases are not @usableFromInline
  • URLError.Code(rawValue:) is failable on Linux, non-failable on Apple
  • URLCache(memoryCapacity:diskCapacity:) requires a diskPath: parameter on Linux
  • URL.appending(queryItems:) replaced with URLComponents-based construction for cross-platform reliability

Test plan

  • All 58 tests pass on macOS, iOS, tvOS, watchOS, visionOS (Apple CI)
  • All 58 tests pass on Linux (new CI job) — including query-parameter cache differentiation tests
  • Verified locally with swift build and swift test

🤖 Generated with Claude Code

BrentMifsud and others added 7 commits March 1, 2026 19:06
On Linux, Foundation networking types (URLSession, URLRequest, URLCache,
etc.) live in a separate FoundationNetworking module. Add conditional
imports to all source and test files that use these types. Also add a
Linux CI job using the swift:6.2 container on ubuntu-latest, and remove
a redundant @available annotation from MiddlewareTests that would be
meaningless on Linux.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use public import FoundationNetworking in files with public APIs that
  expose URLSession, URLCache, or URLRequest (URLSessionTransport,
  URLSessionClient, CacheMiddleware). Plain import for ClientError since
  URLError resolves through Foundation on Linux.
- Handle URLError.Code(rawValue:) being failable on Linux but
  non-failable on Apple platforms with #if canImport conditional.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
URLRequest.CachePolicy enum cases in swift-corelibs-foundation are not
marked @usableFromInline, so @inlinable code cannot reference them.
Remove @inlinable from urlRequestCachePolicy and use conditional public
imports so the return type resolves correctly on both platforms.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Linux's swift-corelibs-foundation requires the diskPath parameter for
URLCache init (no default value), while Apple's version defaults
directoryURL to nil. Use #if canImport(FoundationNetworking) to select
the correct initializer on each platform.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
URL.appending(queryItems:) behaves differently on Linux's
swift-corelibs-foundation, causing query parameters to be lost in URL
reconstruction. Replace with URLComponents-based construction which
handles query items reliably on both platforms.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
URLCache in swift-corelibs-foundation does not differentiate cache
entries by query parameters, causing these tests to fail. The tests
verify Foundation URLCache behavior rather than Simplicity logic, so
skip them on Linux with #if !canImport(FoundationNetworking).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
URLCache in swift-corelibs-foundation does not differentiate cache
entries by URL query parameters. Work around this by creating synthetic
cache key URLs that encode the full URL (including query string) into
the path component, ensuring unique cache entries on all platforms.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@BrentMifsud BrentMifsud self-assigned this Mar 2, 2026
@BrentMifsud BrentMifsud merged commit 0c8af19 into main Mar 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant