Skip to content

Update to Zig 0.16.0#12726

Draft
vancluever wants to merge 1 commit into
ghostty-org:mainfrom
vancluever:zig-0.16
Draft

Update to Zig 0.16.0#12726
vancluever wants to merge 1 commit into
ghostty-org:mainfrom
vancluever:zig-0.16

Conversation

@vancluever

@vancluever vancluever commented May 18, 2026

Copy link
Copy Markdown
Contributor

Closes #12228
Supersedes #12388

UPDATED - Also check comments for additional details!

This commit represents the majority of the work necessary to upgrade Ghostty to use Zig 0.16.0.

At this point, all tests pass under Linux, but more work may be necessary to get them to build and function on other platforms.

There are some parts of this update that deserve commentary, so that follows below:

Expanded use of global state (IO/environment related)

Global state, once generally only used by the C library, has now been expanded to be used across the project at large. The static local variable that holds the state has been moved private in its source container with all attributes that need to be accessed globally gated behind accessors, most of which guard on testing and send test copies instead. Use of the global state in non-testing scenarios asserts that the state has been initialized through init naturally through the optional assertion process.

The rationale for this change is to have a location to store a general-purpose I/O implementation and environment variables, both of which are now provided through Juicy Main and hence can no longer be accessed or mutated through stdlib without use of lower-level system calls and hacks (some of which are employed, but sparingly).

As the code matures, dependence on global state should naturally slim down.

We do not allow global state to be used in libghostty-vt. There are comptime guards that prevent this should compilation of libghostty-vt end up pulling global.zig. This means that as per the last paragraph, work has already begun to de-couple the codebase from global state where necessary. Additionally, in some places where environment needs to be updated and where it can be done in an isolated fashion, environment maps are used - system-level injection of environment through the use of setenv or unsetenv now only happens during early initialization (and hopefully we can remove these in the future too, especially since they require re-synchronization of the higher-level environment primitives after this is done).

The lib/compat Tree

Some stdlib features that have been removed but still either seem they would be valuable to us or outright complex to move away from (particularly SegmentedList) have been extracted from 0.15.2, updated as needed, and placed in src/lib/compat. The intention again is to allow for piecemeal migration to more modern implementations or possibly straight local versions.

This paradigm has also allowed us to add std.Io.Condition.waitTimeout, which incidentally was missed in the 0.16.0 shuffle and has been re-added for 0.17.0. We can remove this in favor of the upstream when we eventually migrate to that, obviously.

Note that there was a lot more of this extracted code when this work was started, but a lot of said code has been removed (namely environment or process/fd-related functionality).

translate-c Issues (functional on Linux, Darwin WIP)

There have been a number of C translation issues that we have been working through through submitted patches and the great help from folks on the Arocc and Zig side. This is ongoing, with the remaining work to getting things fixed mainly focused on the MacOS side. Stay tuned for further developments.

As mentioned at the top, follow comments for more details!

@jacobsandlund jacobsandlund left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

uucode related changes look good!

@vancluever

Copy link
Copy Markdown
Contributor Author

Vexu/arocc#1010 has been opened to address the previously mentioned arocc issue.

There now seems to be an issue with the translated Zig artifact. Will work on tracking this down next:

generated.zig:6603:194: error: expected ';' after statement
        if (__builtin.constant_p(!(@as(c_int, 0) != 0)) != 0) if (!(@as(c_int, 0) != 0)) _ = g_string_free(string, @intFromBool(!(@as(c_int, 0) != 0))) else _ = g_string_free_and_steal(string) else _ = g_string_free(string, @intFromBool(!(@as(c_int, 0) != 0)));

@vancluever

vancluever commented May 22, 2026

Copy link
Copy Markdown
Contributor Author

Opened a couple of translate-c issues:

These two changes along with the Aro update seem to have unblocked us and I can proceed with fixing the full build again. 🙂 🤞

@vancluever

Copy link
Copy Markdown
Contributor Author

I'm now happy to say that the project builds, tests, and runs under Linux!

image

The pkg-config bits that we were using to work around the translate-c issues have been moved back to translate-c since the previously mentioned fixes unblock us there.

Nothing particularly notable otherwise to mention (Vexu/arocc#1010 has been merged though!). I'm not going to say that there aren't any upgrade-related regressions yet, although I'm not aware of any, and I'm planning on driving this soon to check. My focus now will be moving to Darwin (testing/building on MacOS). There are also some issues with the translate-c fixes on Darwin and other platforms, so these need to be corrected too.

@vancluever

Copy link
Copy Markdown
Contributor Author

Update on MacOS progress: we were blocked last week by various Arocc Arm/NEON support issues, for which the Aro maintainers were very prompt in resolving (thanks have been relayed!)

I worked to roll these in during the week last week and was blocked by what was ultimately resolved in Vexu/arocc#1039. I'm now working through resolving some local toolchain issues that seem to keep wuffs from properly building on the iOS targets, then I can move on to more general MacOS syntax fixes, etc.

@vancluever

Copy link
Copy Markdown
Contributor Author

Update: Work is continuing, we are continuing to work through the MacOS translation issues (Vexu/arocc#1052 is the latest).

In the meantime I am refreshing this repo with the latest main and working on some updates to our handling of Juicy main data (I/O and env) that we discussed internally.

More updates as they come!

@vancluever vancluever force-pushed the zig-0.16 branch 6 times, most recently from 6d52855 to 0c2296b Compare June 26, 2026 07:07
@vancluever

vancluever commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

The aforementioned rebase/rework has now been completed. I've updated the main PR description to reflect the current state of the work.

Long story short:

  • We're not using global_single_threaded anymore - we now use our own locally-created std.Io.Threaded, done versus taking what is in Juicy Main so that we can have better control over the environment if need be (also we need to anyway for the C library).
  • This and the environment are stored in global state.
  • libghostty-vt does not use global state and there are comptime guards now in global.zig that prevent it from happening. This allowed us to catch a number of places where it was possibly being relied on, and de-couple those portions from it, moving the codebase closer to a fully post-0.16.0 feel.
  • A bunch of the compat code that I pulled in from 0.15.2 std.posix and other places has now been removed, in favor of using the lower-level posix.system calls directly where applicable, and moving other parts to using higher-level primitives, namely environment - environment pointers going out of sync was actually what prompted this.

Linux build and tests should pass again as it did during the last major push. Will be pivoting back now again to MacOS builds and getting further C translation issues fixed and possibly other MacOS build issues that arise.

@mitchellh

Copy link
Copy Markdown
Contributor

Amazing work @vancluever Thank you so much ❤️

@vancluever vancluever force-pushed the zig-0.16 branch 3 times, most recently from a69a675 to bf5f82a Compare June 29, 2026 01:22
This commit represents the majority of the work necessary to upgrade
Ghostty to use Zig 0.16.0.

At this point, the project builds, tests, and runs under Linux. More
work may be necessary for other platforms, and possibly to fix any
(currently unknown) upgrade regressions.

Co-authored-by: Leah Amelia Chen <hi@pluie.me>
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.

Zig 0.16 migration

3 participants