Skip to content

feat: add FreeBSD support #7606

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 23 commits into from
Jun 21, 2025
Merged

feat: add FreeBSD support #7606

merged 23 commits into from
Jun 21, 2025

Conversation

charlesrocket
Copy link
Contributor

@charlesrocket charlesrocket commented Jun 16, 2025

@charlesrocket charlesrocket requested a review from a team as a code owner June 16, 2025 16:39
@charlesrocket
Copy link
Contributor Author

libxev needs to be replaced after the upstream merge

Copy link
Member

@pluiedev pluiedev left a comment

Choose a reason for hiding this comment

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

Also in general I think that instead of Linux/BSD we should just unify on "the GTK app", even though GTK can technically also be built for macOS and Windows. It's a bit of a mess, since FreeBSD behaves like Linux in userland and more like macOS in kernel land, so I really am not sure how best we should explain this.

@@ -1823,7 +1823,7 @@ keybind: Keybinds = .{},
/// Automatically hide the quick terminal when focus shifts to another window.
/// Set it to false for the quick terminal to remain open even when it loses focus.
///
/// Defaults to true on macOS and on false on Linux. This is because global
/// Defaults to true on macOS and on false on Linux/BSD. This is because global
/// shortcuts on Linux require system configuration and are considerably less
Copy link
Member

Choose a reason for hiding this comment

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

You forgot to edit this one, too. I wonder if we should just replace all instances of "Linux" to "the GTK app (runtime)"... pending discussion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another option is to replace Linux with Unix/Unix-like.

Copy link
Member

Choose a reason for hiding this comment

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

The thing is that macOS is also technically a Unix system (even more so than Linux), but on the user-facing level the BSDs are far more similar to Linux. It's a tricky nomenclature problem for sure

Comment on lines +2384 to +2410
@"linux-cgroup": LinuxCgroup = if (builtin.os.tag == .linux)
.@"single-instance"
else
.never,
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a specific switch for Linux even though the option already indicates that it's Linux-specific? Maybe we should rename the option then?

Copy link
Contributor Author

@charlesrocket charlesrocket Jun 16, 2025

Choose a reason for hiding this comment

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

It should be just cgroups since one can enable it on BSD as well, so I just gated it for now. Config change such as this should probably be done in its own PR, but I can push it if it is okay.

@pluiedev
Copy link
Member

pluiedev commented Jun 16, 2025

I'm going to convert this PR to draft for now since some parts of it are still unfinished (i.e. localization support) and pending on the libxev PR. It's just not productive right now IMO to assess this PR as it currently stands. Once the libxev PR is merged and this PR has reached (near-)feature parity with Linux, then we can again mark it as ready for review.

@pluiedev pluiedev marked this pull request as draft June 16, 2025 20:59
@charlesrocket
Copy link
Contributor Author

charlesrocket commented Jun 16, 2025

@pluiedev fixed local issues, builds are passing now with i18n. Oh, theres error on the release that I need to look into.

Comment on lines 289 to 297
run: |
# switch to pkg
wget https://ziglang.org/builds/zig-x86_64-freebsd-0.15.0-dev.777+6810ffa42.tar.xz
tar -xf zig-x86_64-freebsd-0.15.0-dev.777+6810ffa42.tar.xz
zig-x86_64-freebsd-0.15.0-dev.777+6810ffa42/zig build -Dapp-runtime=none test
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, is it not possible to use 0.14.0 or 0.14.1? Seems like this could cause headaches later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fresh zig is already in the latest branch so it will be in quarterly soon. This is just a temp workaround.

@00-kat
Copy link
Contributor

00-kat commented Jun 16, 2025

Also in general I think that instead of Linux/BSD we should just unify on "the GTK app"

Aside: the repo currently has os/macos and os/linux labels; would FreeBSD get its own label or should there be a label for “GTK app” instead?

@charlesrocket
Copy link
Contributor Author

charlesrocket commented Jun 17, 2025

@00-kat I'd say it should be both BSD and GTK (gui/gtk). There is probably no need to have individual labels for BSDs (at least not yet).

@charlesrocket
Copy link
Contributor Author

Translations are working as expected now.

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Looks very good. Here is the TODO on my end:

  • Review the xev changes and fix as necessary
  • Migrate CI to Namespace and verify it works there
  • Consider adding prefer to the non-dynamic xev to avoid the comptime checks here

@mitchellh
Copy link
Contributor

Note: vmactions/freebsd-vm doesn't work on Namespace yet. I've opened a support ticket with them to get this looked at (cc @hugosantos). I didn't block libxev on it because its low traffic, but I want to wait for that to merge this because its so much more expensive to run Ghostty's CI.

@charlesrocket
Copy link
Contributor Author

@mitchellh I thought boxybsd could be used, but I doubt I can get GH runner working. There is also https://github.com/acj/freebsd-firecracker-action.

@mitchellh
Copy link
Contributor

Namespace fixed the issue, we can run the FreeBSD VM action on Namespace now, see libxev: mitchellh/libxev#168

@mitchellh
Copy link
Contributor

Moving this to ready for review and will make some tweaks to get this merged. It may not be perfect yet but it at least gets Ghostty working to some extent (similar to Windows).

@mitchellh mitchellh marked this pull request as ready for review June 18, 2025 15:30
@mitchellh
Copy link
Contributor

@charlesrocket We only test unit tests on FreeBSD right now in CI. It would be better to test both the GLFW and GTK builds as well. Can you work on a future PR to address that?

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Excellent work @charlesrocket. Thank you very much! 😄

FreeBSD will remain a lower tier platform for now since none of the maintainers have access to actually test on it, but we at least have CI ensuring we don't break it and an active community member to help support it.

We can talk about more maintenance going forward in Discord. Thanks 😄

@mitchellh
Copy link
Contributor

Hm, looks like the FreeBSD CI job failed... kind of a weird failure. I'll rerun it and see if that works.

@charlesrocket
Copy link
Contributor Author

@mitchellh definitely, finishing the freebsd port and will switch to GLFW build error.

@charlesrocket charlesrocket requested a review from a team as a code owner June 19, 2025 11:28
@charlesrocket charlesrocket force-pushed the fbsd branch 2 times, most recently from 658e6a9 to 4a5164b Compare June 19, 2025 21:54
@mitchellh
Copy link
Contributor

@charlesrocket The firecracker VM approach didn't work for probably unrelated CI reasons. I'm sorry I haven't had time to look into this yet. I'd be fine merging this WITHOUT CI for now but we have to both be okay with the reality that FreeBSD support will probably bitrot until we have CI support because we don't have anyone staying on top of it.

If you're okay with that in the interim we can remove the freebsd job and try a subsequent PR to add it.

@charlesrocket
Copy link
Contributor Author

@mitchellh I am okay with missing CI for now

Copy link
Member

@pluiedev pluiedev left a comment

Choose a reason for hiding this comment

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

I still have my reservations about some of these changes (a lot of them look a bit too tacked-on with the builtin.target.os.tag check), but I don't feel like blocking this further.

In the future I think there needs to be a cleanup PR to unify the terminology a little bit: we should use "GTK app" instead of "Linux" in a lot of cases within the codebase, unless something is truly specific to Linux (nothing immediately comes to mind yet). This IMO is the least intrusive option since although the GTK app can technically be built for macOS, we never distribute it in that form and we generally assume it to be run in a FreeDesktop-based environment (Linux, FreeBSD, etc.). We also should probably update the website ahead of Ghostty 1.2 to reflect this nomenclature change.

@@ -21,14 +22,22 @@ pub fn init(b: *std.Build, cfg: *const Config) !GhosttyI18n {
defer steps.deinit();

inline for (internal_os.i18n.locales) |locale| {
// There is no encoding suffix in the LC_MESSAGES path on FreeBSD,
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker, but I'm curious how programs like vim gets away with it on FBSD. Are there truly no programs out there that contain the encoding suffix?

@@ -1823,7 +1823,7 @@ keybind: Keybinds = .{},
/// Automatically hide the quick terminal when focus shifts to another window.
/// Set it to false for the quick terminal to remain open even when it loses focus.
///
/// Defaults to true on macOS and on false on Linux. This is because global
/// Defaults to true on macOS and on false on Linux/BSD. This is because global
/// shortcuts on Linux require system configuration and are considerably less
Copy link
Member

Choose a reason for hiding this comment

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

Note to self: go through all the configs mentioning "Linux" and think about whether it applies to BSDs as well

@@ -2812,7 +2815,7 @@ pub fn loadCliArgs(self: *Config, alloc_gpa: Allocator) !void {
// styling, etc. based on the command.
//
// See: https://github.com/Vladimir-csp/xdg-terminal-exec
if (comptime builtin.os.tag == .linux) {
if ((comptime builtin.os.tag == .linux) or (comptime builtin.os.tag == .freebsd)) {
Copy link
Member

Choose a reason for hiding this comment

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

We should probably add a helper function inside std/os that determines whether the current system is based on FreeDesktop (XDG) standards, since I can totally see us needing to expand this check a lot later on.

@Owl-Lord
Copy link

i mean if the want for more portability beyond freebsd is interesting i have quiet a few friends who use openbsd which i could ask to help with knowledge about the inner workings of it

@mitchellh
Copy link
Contributor

@pluiedev

I still have my reservations about some of these changes (a lot of them look a bit too tacked-on with the builtin.target.os.tag check), but I don't feel like blocking this further.

I don't think there was much. There was zero cases added to the GTK app (just an xev check unrelated to BSD), and almost the entirety of OS tag checks are in the build system and src/os package, both of which are inherently extremely OS/target dependent. I think it's pretty clean, considering.

In the future I think there needs to be a cleanup PR to unify the terminology a little bit: we should use "GTK app" instead of "Linux" in a lot of cases within the codebase, unless something is truly specific to Linux (nothing immediately comes to mind yet).

This is probably right. I've avoided "GTK" in case we ever actually dropped GTK as the default for Linux (and now BSD). But that's probably a stretch. Using the apprt as the description is probably more appropriate. I think macOS is in line with that because while macOS uses the libghostty apprt technically, its really a dedicated macOS app there consuming that.

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Approved, given the caveats noted earlier, which I'll repeat here.

We never got CI working. As such, we've all agreed that the FreeBSD support may bitrot. We don't have any active maintainers running FreeBSD (or any BSD for that matter). We can't guarantee that PRs the community or ourselves make will continue to work on FreeBSD. As such, we should strive to get FreeBSD in CI.

Until then, I don't want to block improvements on our portability, so I'm willing to approve and merge with that disclaimer out of the way.

And I want to thank @charlesrocket again for the excellent effort and work to get us here!

@mitchellh mitchellh merged commit 9d922e1 into ghostty-org:main Jun 21, 2025
37 checks passed
@github-actions github-actions bot added this to the 1.2.0 milestone Jun 21, 2025
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.

6 participants