Skip to content

[FreeBSD] Adding FreeBSD support #77836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 19, 2025
Merged

Conversation

michael-yuji
Copy link
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
Copy link

lin72h commented Nov 25, 2024

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

@michael-yuji
Copy link
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
Copy link

lin72h commented Nov 26, 2024

it's very impressive work especially the bootstrap part!

@finagolfin
Copy link
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
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
Copy link

khng300 commented Dec 1, 2024

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
Member Author

@swift-ci please smoke test

@michael-yuji
Copy link
Member Author

@swift-ci please test

@CodingCarpincho
Copy link

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

@3405691582
Copy link
Member

@swift-ci please test.

@michael-yuji
Copy link
Member Author

@swift-ci please test

@etcwilde
Copy link
Member

@swift-ci please test

@michael-yuji michael-yuji enabled auto-merge June 17, 2025 21:48
@michael-yuji
Copy link
Member Author

@swift-ci please test windows

@etcwilde
Copy link
Member

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

@etcwilde
Copy link
Member

#82329 landed with a fix.

@etcwilde
Copy link
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.