# Integrating Zig and SwiftUI

One approach to building a native GUI for a cross-platform application is to write all of the business logic in a cross-platform language (C, Rust, Zig, etc.) and then write the platform-specific GUI code. This is the approach I take with my my terminal emulator and it works really well. As of the current date writing this post, 93% of my repository is business logic in Zig and C, and 4% is macOS-specific GUI code in Swift.

As a result, my terminal emulator is truly native: you get native Mac windows, Mac GUI components (buttons, text fields), etc. It looks and feels great. But its also still cross-platform: I support Linux (using GTK) while sharing ~90% of all code. In this post, I’ll share details about how this setup works and why I approached GUI programming this way.

# How a Zig IDE Could Work

After parsing, the Ast is converted to an intermediate representation, Zir. This is where Zig diverges a bit from more typical statically compiled languages. Zir actually resembles something like Python’s bytecode — an intermediate representation that an interpreter for a dynamically-typed language would use. That’s because it is an interpreter’s IR — the next stage would use Zir to evaluate comptime.

Ast and Zir infra is good. It is per-file, so it naturally just works in an IDE.

# Bun v0.3.0

Today, Bun has two main priorities: stability and compatibility with Node.js and Web APIs. In v0.3.0, we’ve made significant progress toward both of these goals.

Bun is an interesting new Node.js alternative based on JavaScriptCore, with additional features, such as bundling, transpiling, and managing packages. It is written in Zig, gluing a lot of of third-party C and C++ code.