iTranslated by AI
Zig v0.14.0 Released
Intro
It's March, and lately, everyone's been talking about how cold it is. I've heard that Kyoto, where I live, apparently only has summer and winter, and spring never truly arrives. I can't leave the house without my scarf and some Famichiki (FamilyMart chicken).
Anyway, Zig v0.14.0 was released on March 5, 2025 (JST). Following the postponement of the original January 1st release and the subsequent delay of the February 14th release, this is a long-awaited release, two months behind the initial schedule.
In this article, I'll pick up and introduce some of the changes in 0.14.0 that caught my attention. For a full list of changes, please refer to the release notes.
UEFI Removed from Tier System
Zig classifies the support status for each platform using a Tier System. Tier 1 support level guarantees that non-experimental features will work without issues, and as of 0.14.0, only x86_64-linux is in Tier 1. Other major platforms for x64 (Mac/Windows) are in Tier 2.
Zig also supports building UEFI applications, allowing you to write UEFI code with the same feel as building a regular user app. Of course, you can also use the standard library, which doesn't depend on an OS. As of 0.13.0, x64 UEFI platform support was Tier 2. Starting from 0.14.0, it seems that the UEFI platform has been excluded from the regular Tier System. However, this doesn't mean these platforms are no longer usable; they have simply been removed from the Tier System classification.
Many Symbols in the Standard Library Renamed
When migrating from 0.13.0 to 0.14.0, the most significant effort will likely be renaming symbols in the standard library. Zig includes a Style Guide in its documentation, which defines naming conventions for variables and other identifiers. While these aren't baked into the language specification and aren't strictly mandatory, many variable names in the standard library in 0.13.0 did not follow these conventions. In 0.14.0, many symbols have been renamed to adhere to these naming rules.
The impact is particularly significant for the std.builtin.Type enum. Fields that were previously TitleCase, such as .Int or .Pointer, have been renamed to lowercase, like .int or .pointer. Additionally, fields that conflict with reserved words, such as struct or union, now use Quoted Identifiers like @"struct" or @"union".
Furthermore, symbols under std.os.uefi have been changed en masse to follow the naming conventions. Those who are building their own bootloaders should take note.
build.zig.zon
The build.zig.zon file is the definition file used for package management in Zig. It is equivalent to Rust's Cargo.toml or JavaScript's package.json. Zig has an official package manager called Zon, and by describing dependency packages in this file, it will automatically download them during the build. My impression is that not many people use it yet. There is practically no documentation for it.
Now, the build.zig.zon file is written using Zig's struct literals. Starting from 0.14.0, a required field called fingerprint has been added. This serves as a unique ID for the package. Previously, if you wanted to add a package, you had to either copy the hash value written in the package's README or use some "black magic" to calculate the hash of the package you wanted as a dependency. This fingerprint is expected to resolve such inconveniences. However, it is explicitly stated that currently, no tools (officially provided by Zig) are available to utilize the fingerprint yet.
Despite this, calculating the fingerprint is much easier than before. If you run zig build without defining a fingerprint first, the hash value you should use will be displayed in the error message:
/home/smallkirby/norn/build.zig.zon:1:2: error: missing top-level 'fingerprint' field; suggested value: 0xe35841a04984176
.{
^
Additionally, the name field representing the project name has changed from a string to an enum literal. Along with this change, characters and symbols that are invalid as Zig identifiers can no longer be used for the name.
Parsing ZON Files
Another point related to build.zig.zon: even though ZON files are defined as Zig structs, there was previously no feature to load and parse them. In 0.14.0, you can now import ZON files. It is also possible to load and parse them at runtime.
However, the type of the struct being loaded must be known in advance. For example, if you want to read version information from build.zig.zon within build.zig, you would write it like this:
const ZonStruct = struct {
version: []const u8,
name: @Type(.enum_literal),
fingerprint: u64,
minimum_zig_version: []const u8,
dependencies: struct {},
paths: []const []const u8,
};
const zon: ZonStruct = @import("build.zig.zon");
const norn_version = zon.version;
It's quite a bit of work. In fact, it would be nice if the definition for build.zig.zon were included in the standard library.
Decl Literals
A new syntax called Decl Literals has been introduced. This looks quite useful, while also being a bit "weird":
const S = struct {
x: u32,
const default: S = .{ .x = 123 };
};
If a struct definition and constant like this existed, until 0.13.0, you had to use default like this:
var value = S.default;
With Decl Literals, it can be written as follows:
var value: S = .default;
The notation .default, which was previously just an Enum Literal, has been expanded, allowing you to write .default. Since the resulting type is S, this literal becomes synonymous with S.default. Honestly, in this example, it just looks like the place where S is written has changed, but when assigning to an existing variable of type S, you can simply write value = .default. A practical example where this is effectively used is the Calling Convention example below.
Calling Convention
In Zig, you can specify the calling convention of a function. There were conventions like Zig's default .Stdcall, .C for following the C calling convention, and .Naked which doesn't have a prologue or epilogue:
// A call that Zig can optimize as it sees fit
fn zigFunction() void {}
// Follows the C calling convention
fn cFunction() callconv(.C) void {}
Starting from 0.14.0, CallingConvention has become a Tagged Union, defining calling rules for various platforms supported by Zig. Starting with .x86_64_sysv, there are also things like .x86_64_interrupt and .avr_signal:
Since it is a Tagged Union, it is possible to have different types for each union value. This allows some conventions to take options. For example, you can now specify stack alignment or (for x86 only) the number of registers to use for argument passing.
If you thought .Naked or .C didn't follow the naming convention, you are correct. These have been renamed to .naked and .c. Note that in 0.14.0, aliases are provided so that the traditional .Naked and .C can still be used, but they are deprecated and scheduled for removal in a future release. Also, the following notation uses the Decl Literals introduced earlier. It's the first user:
/// Deprecated; use `.c`.
pub const C: CallingConvention = .c;
/// Deprecated; use `.naked`.
pub const Naked: CallingConvention = .naked;
@branchHint
The @setCold() built-in function, which existed until 0.13.0, has been removed. I used to use it in OS panic handlers (functions that don't return).
In its place, the more versatile @branchHint() built-in has been added. This completely encompasses @setCold() and also allows specifying branch prediction hints such as .likely and .unlikely. Previous uses of @setCold() can be replaced with @branchHint(.cold).
Allocator API
std.mem.Allocator is an interface with a function table called std.mem.Allocator.VTable, allowing memory allocators to be used via a common API regardless of the backend implementation. Previously, it had three functions: alloc(), free(), and resize(). A new function, remap(), has been added.
The difference between resize() and remap() is whether the pointer to the memory region after resizing has the potential to change. resize() returns an error if the specified region cannot be resized. On the other hand, the newly added remap() will allocate a new region, copy the contents of the old region, and free the original region if it cannot be resized in place. If the region can be resized without changing its address, both will be identical / should be implemented as such.
Global Variable Addresses
This is a long-awaited fix! Previously, due to a bug, it was not possible to initialize a global variable using the address of another global variable:
const a: u64 = 3;
const S = struct { ptr: *u64 };
const b: S = .{ .ptr = &a }; // LLVM crashes
Starting from 0.14.0, this is now possible. Additionally, global variables can now reference each other's addresses:
const Node = struct {
next: *const Node,
};
const a: Node = .{ .next = &b };
const b: Node = .{ .next = &a };
Previously, as a workaround, I had to initialize b with undefined first and then assign &a at program startup, which was quite tedious. I'm very happy this has been fixed.
Comparing Packed Structs
In Zig, struct comparison is done using std.meta.eql(). Alternatively, you can use the @bitCast() builtin to turn the struct into a simple scalar value and compare that (Zig allows integer types of arbitrary bit widths).
Starting from 0.14.0, it is now possible to compare Packed Structs using regular comparison operators. This seems quietly convenient:
test {
const S = packed struct(u32) { x: u32 };
const a = S{ .x = 123 };
const b = S{ .x = 123 };
try testing.expect(std.meta.eql(a, b));
try testing.expect(a == b); // <== NEW!
}
Interesting Bug
Lastly, I'd like to introduce a bug that caught my attention. In 0.14.0, the following test no longer passes:
const S1 = packed struct {
x: u16,
y: *u64,
};
var variable: u64 = 3;
test {
const value1 = S1{ .x = 42, .y = &variable };
try testing.expectEqual(&variable, value1.y);
try test1(value1);
}
noinline fn test1(value: S1) !void {
try testing.expectEqual(&variable, value.y);
}
It seems that putting a pointer to a global variable inside a Packed Struct causes a bug. This issue apparently surfaced when upgrading to LLVM 19 and was identified last year through automated testing. However, it seems the test was temporarily disabled and the release went out either without a fix or because they forgot it was disabled. Since this is a fairly common use case (I noticed it while setting up GDTR in my hobby OS), I hope it gets fixed soon. Interestingly, this issue has been assigned a 0.14.1 milestone, but I wonder... have there ever been patch version updates for Zig before?
Outro
Zig appears to be aiming to move away from its dependency on the LLVM Project. As stated in the linked issue, they plan to eliminate dependencies on all components, such as LLVM, Clang, and LLD. The reasons cited include a desire to avoid being affected by LLVM bugs, the inconvenience of having to install LLVM to build Zig, and the fact that the compiler's binary size is large and its speed is slow. As a first step, the x64 native backend in 0.14.0 has reportedly passed 98% of the tests. These release notes also mention that in the next release, the native backend will become the default for debug builds.
Let's all prepare for the arrival of the native backend by adding -fno-llvm to our CI tests.
Discussion