Skip to content

[FreeBSD] Adding FreeBSD support#77836

Merged
michael-yuji merged 14 commits into
swiftlang:mainfrom
michael-yuji:mchiu/freebsd
Jun 19, 2025
Merged

[FreeBSD] Adding FreeBSD support#77836
michael-yuji merged 14 commits into
swiftlang:mainfrom
michael-yuji:mchiu/freebsd

Conversation

@michael-yuji

Copy link
Copy Markdown
Member

This commit adds required conditional compilation blocks to enable building and running
on FreeBSD (tested on x86_64 FreeBSD 14.1-RELEASE-p6).

Also implements FreeBSD synchronization shims using _umtx_op(2)

@michael-yuji michael-yuji requested a review from a team as a code owner November 25, 2024 22:53
@lin72h

lin72h commented Nov 25, 2024

Copy link
Copy Markdown

It's my early Christmas gift. Thanks for working on this.

@michael-yuji

Copy link
Copy Markdown
Member Author

It's my early Christmas gift. Thanks for working on this.

unfortunately this PR alone here is not enough. I do have patches to other swift components to get it fully working and going to PR them to coming weeks. But even with those, you'll need to have a functional swiftc (by bootstrapping a swift 5.8+) on FreeBSD to build them. personally I've done a multi-stages bootstrap until I now have a toolchain ready.

you also need a patch to the base libc++ to workaround this issue

@lin72h

lin72h commented Nov 26, 2024

Copy link
Copy Markdown

it's very impressive work especially the bootstrap part!

Comment thread stdlib/public/Platform/SwiftGlibc.h.gyb
@finagolfin

Copy link
Copy Markdown
Member

Nice, there is some work to get Swift 6 bootstrapping again, #77815, that you'll want to follow.

Pinging @mhjacobson and @3405691582, who added BSD support before and may be able to help review.

@3405691582

Copy link
Copy Markdown
Member

As a heads up, the code uses LLVM target triples and the build system has a few places where it assumes that the platform calls the architecture with the same name as LLVM does. This isn't a problem for FreeBSD on what LLVM calls x86_64, since they apparently both seem to use the same spelling, but for what LLVM calls aarch64, both OpenBSD and FreeBSD call it arm64. This causes headaches.

In the past, I've tried to keep some meaningful separation between platform spelling and LLVM spelling, but I'm reconsidering that in #77879. You probably won't need to do anything right now for this pr if you're just targeting x86_64, though, and what you have seems good to me, but keep this in mind if you're going to also be working on arm64.

@khng300

khng300 commented Dec 1, 2024

Copy link
Copy Markdown

As a heads up, the code uses LLVM target triples and the build system has a few places where it assumes that the platform calls the architecture with the same name as LLVM does. This isn't a problem for FreeBSD on what LLVM calls x86_64, since they apparently both seem to use the same spelling, but for what LLVM calls aarch64, both OpenBSD and FreeBSD call it arm64. This causes headaches.

In the past, I've tried to keep some meaningful separation between platform spelling and LLVM spelling, but I'm reconsidering that in #77879. You probably won't need to do anything right now for this pr if you're just targeting x86_64, though, and what you have seems good to me, but keep this in mind if you're going to also be working on arm64.

Which is not correct for the FreeBSD part. On FreeBSD itself, arm64 is the TARGET, meanwhile aarch64 is the TARGET_ARCH and MACHINE_ARCH. Below is what I got from a build of the FreeBSD tree on my side:

CMD cc -target aarch64-unknown-freebsd15.0 --sysroot=

For reference how we build the -target tuple in the tree:

Makefile.inc1:		MACHINE_ARCH=${TARGET_ARCH}
Makefile:	TARGET=${_TARGET} TARGET_ARCH=${_TARGET_ARCH} ${_MAKEARGS}
Makefile:_TARGET_ARCH=	${TARGET:S/arm64/aarch64/:S/riscv/riscv64/:S/arm/armv7/}
./Makefile.inc1:MACHINE_TRIPLE?=${MACHINE_ARCH:S/amd64/x86_64/}-${MACHINE_TRIPLE_ABI}-freebsd${OS_REVISION}

@QuietMisdreavus QuietMisdreavus removed their request for review December 2, 2024 17:47
@michael-yuji

Copy link
Copy Markdown
Member Author

@swift-ci please smoke test

@michael-yuji

Copy link
Copy Markdown
Member Author

@swift-ci please test

Comment thread cmake/modules/SwiftConfigureSDK.cmake Outdated
Comment thread include/swift/AST/AutoDiff.h Outdated
@CodingCarpincho

Copy link
Copy Markdown

@shahmishal Could you or someone else kick off the CI here so we can get Michael’s work merged?

@3405691582

Copy link
Copy Markdown
Member

@swift-ci please test.

Comment thread include/swift/AST/AutoDiff.h Outdated
Comment thread include/swift/SILOptimizer/Differentiation/DifferentiationInvoker.h Outdated
Comment thread stdlib/public/core/CTypes.swift Outdated
Comment thread stdlib/public/runtime/CMakeLists.txt Outdated
@michael-yuji

Copy link
Copy Markdown
Member Author

@swift-ci please test

@etcwilde

Copy link
Copy Markdown
Member

@swift-ci please test

@michael-yuji michael-yuji enabled auto-merge June 17, 2025 21:48
@michael-yuji

Copy link
Copy Markdown
Member Author

@swift-ci please test windows

@etcwilde

Copy link
Copy Markdown
Member

macOS test failure is a regression brought in by #82275.

@etcwilde

Copy link
Copy Markdown
Member

#82329 landed with a fix.

@etcwilde

Copy link
Copy Markdown
Member

@swift-ci please test macOS

@michael-yuji michael-yuji merged commit cf2f715 into swiftlang:main Jun 19, 2025
4 of 5 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Swift on FreeBSD Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.