Migration Guide from 0.11.0 to 0.12.0

In an attempt to catalog what I learned from trying to update a project from 0.11.0 to 0.12.0, I’ve made a list of deprications and a suggestion of what to change it to. Feel free to add on.

Build System Changes

exe.addModule(module) was removed. Change to exe.root_module.addImport(module)

Build.LazyPath.relative(path) was changed to give a warning. Use b.path(path) instead.
You can also use b.path(path) instead of .root_source_file = .{ .path = “src/main.zig” },

CrossTarget was removed. You can use b.resolveTargetQuery() instead with the same struct members to get a ResolvedTarget.

Language Changes

If a variable is never mutated, it is required to be const. You will probably do a lot of find and replace with varconst. This is a compiler error now.

@fabs(), std.math.fabs(), and std.math.abs() were removed. There is a new @abs builtin that is a drop in replacement for all of these.

std.mem.copy was removed. You can use either the @memcpy builtin, or std.mem.copyForwards or std.mem.copyBackwards. If the memory regions do not overlap, either of the std.mem.copy* methods should work just fine

Enum Casing: A lot of enum variants were changed to lower case names. So for example Endian used to be .Big and .Little. Now it is .big and .little. Other enums were affected as well.

std.mem.writeIntSlice* was removed. Need to figure out how to migrate this.

std.os was largely moved to std.posix.

std.c.MAP.PRIVATE was changed. Can’t figure out the right syntax to get this in 0.12.0.

Any others that I missed? I’ll keep adding as I find them. Thanks

7 Likes

From what I can see, the only way to get something similar to std.mem.writeIntSliceLittle() is the following.

// previously
const i: i32 = 42;
const slice = data[start..end];
std.mem.writeIntSliceLittle(i32, slice, i);

// One change could be
const writer = std.io.fixedBufferStream(slice).writer();
try writer.writeInt(i32, i, .little);

One drawback is that this introduces an error result into your function, so where std.mem.writeIntSliceLittle() had a return type of void, writer.writeInt() returns anyerror!void.

The main reason I can’t use std.mem.writeInt() is because std.mem.writeInt() takes an array, not a slice. So can’t really use it for runtime writing. Unless there is a way to get a dynamic slice to be an array that I am not aware of.

Is there a better way to do this?

my 0.11 → 0.12 adjustments for some programs written in Zig:

  • one (file compressor/decompressor)
  • two (forth-like virtual machine)
  • three (just intonation synthesizer)

that was the most annoying and strange change in std library, related post

1 Like

If you slice with comptime-known start and end positions, the result is a pointer to an array, rather than a slice.

std.mem.writeInt(i32, data[start..][0..4], i, .little);

Does that help?

That was the trick for writeIntSlice* and readIntSlice*, thanks for the help @david_vanderson !