Skip to content

Add FreeBSD platform support#565

Open
networkextension wants to merge 4 commits into
swiftlang:mainfrom
networkextension:freebsd-platform
Open

Add FreeBSD platform support#565
networkextension wants to merge 4 commits into
swiftlang:mainfrom
networkextension:freebsd-platform

Conversation

@networkextension

@networkextension networkextension commented Jun 20, 2026

Copy link
Copy Markdown

Summary

Introduces a FreeBSDPlatform target so swiftly compiles and runs on FreeBSD, alongside the existing Linux and macOS platforms.

Approach

  • New FreeBSDPlatform (struct FreeBSD: Platform), modeled on LinuxPlatform since FreeBSD's Swift toolchains are tarball-based like Linux. detectPlatform returns a single PlatformDefinition.freebsd; the install/extract/directory logic reuses the portable POSIX/Foundation paths.
  • Swiftly and TestSwiftly select it via #elseif os(FreeBSD), and the POSIX os(macOS) || os(Linux) guards in SwiftlyCore (ProcessInfo, Platform, Platform+Process, Terminal) now include FreeBSD.
  • Adds PlatformDefinition.freebsd.
  • FreeBSDPlatform is gated with .when(platforms: [.custom("freebsd")]) (thanks @kkebo), matching the LinuxPlatform/MacOSPlatform entries — PackageDescription has no .freebsd case, but .custom("freebsd") works, so it stays out of the graph on non-FreeBSD builds.
  • The release-packaging tool's run() throws on FreeBSD for now (the Linux release path is musl-SDK specific).

Testing

Builds and runs natively on FreeBSD 15.1 / aarch64 (swiftly --help, swiftly --version) with a native swift-6.3.2-RELEASE toolchain.

Note: swift.org doesn't yet publish FreeBSD toolchains, so this is foundational platform support — it makes swiftly itself build/run on FreeBSD.

Introduces a `FreeBSDPlatform` target (`struct FreeBSD: Platform`) so swiftly
compiles and runs on FreeBSD, alongside the existing Linux and macOS platforms.

- New `FreeBSDPlatform` target, modeled on `LinuxPlatform` (FreeBSD's toolchain
  layout is tarball-based like Linux). `detectPlatform` returns a single
  `.freebsd` `PlatformDefinition`; install/extract/dirs reuse the portable
  POSIX/Foundation paths.
- Wired into `Swiftly`/`TestSwiftly` (`#elseif os(FreeBSD)`), and the POSIX
  `os(macOS) || os(Linux)` guards in `SwiftlyCore` (ProcessInfo, Platform,
  Platform+Process, Terminal) now include FreeBSD.
- Added `PlatformDefinition.freebsd`.
- `FreeBSDPlatform` is an unconditional package dependency that self-guards with
  `#if os(FreeBSD)`, because `PackageDescription` currently has no `.freebsd`
  platform (so `.when(platforms: [.freebsd])` is unavailable).
- The release-packaging tool's `run()` throws on FreeBSD for now (the Linux
  release path is musl-SDK specific).

Verified: builds and runs (`swiftly --help` / `--version`) natively on
FreeBSD 15.1/aarch64.
Two follow-ups to the FreeBSDPlatform support:

- FreeBSD.swift: verifySwiftlySystemPrerequisites checked the Linux CA
  bundle paths (/etc/ssl/certs/ca-certificates.crt,
  /etc/pki/tls/certs/ca-bundle.crt), which don't exist on FreeBSD, so it
  always reported "ca-certificates not installed". Check the FreeBSD trust
  store instead: /usr/local/etc/ssl/cert.pem (security/ca_root_nss),
  /etc/ssl/cert.pem (base), and /usr/local/share/certs/ca-root-nss.crt.

- SwiftlyTests.swift: the MockToolchainDownloader helpers
  (makeMockedSwiftly/makeMockedToolchain, the signatures cache, and the
  on-disk toolchain verifier) were guarded #if os(Linux)/#elseif os(macOS)
  only, so the test target failed to compile on FreeBSD. Add os(FreeBSD)
  to the Linux branches; the Linux mock builds a .tar.gz + GPG signature,
  which is exactly what FreeBSDPlatform consumes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kkebo

kkebo commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

.when(platforms: [.freebsd]) can't be used

You can use .when(platforms: [.custom("freebsd")]) instead.

…rm dep

Per review feedback (@kkebo): instead of depending on FreeBSDPlatform
unconditionally (and relying on the target's internal `#if os(FreeBSD)`
self-guard), gate the dependency with `.when(platforms: [.custom("freebsd")])`,
matching the LinuxPlatform/MacOSPlatform entries. This keeps FreeBSDPlatform
out of the dependency graph entirely on non-FreeBSD builds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@networkextension

Copy link
Copy Markdown
Author

Thanks @kkebo — that's much cleaner. Applied in 4f25b50: the three FreeBSDPlatform dependencies now use .when(platforms: [.custom("freebsd")]), matching the LinuxPlatform/MacOSPlatform entries, so it's no longer pulled into the graph on non-FreeBSD builds. I'll update the PR description note accordingly.

SelfUpdate.execute hit `fatalError("Unsupported OS")` on FreeBSD, which
crashed the whole test process (SIGTRAP) and aborted the suite. Treat
FreeBSD like Linux (tarball-based): build a freebsd/swiftly-*.tar.gz
download URL for an explicitly-requested version, and match the Linux
release artifact in the auto-update path (the swift.org website API has
no FreeBSD platform yet; this can switch to a dedicated FreeBSD artifact
once one is published).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

3 participants