⚡
zig-0.15 breaking change 集
遭遇した breaking change を都度記録していく
zig-0.15.1
ひっそりと 0.15.2
Writer 系
std ライブラリーの IO の刷新が来ていて、
名付けて
Writergate
async I/O 復活の布石らしい。
- writer
try stdout.flush(); // Don't forget to flush!
fmt
ドキュメント
https://ziglang.org/documentation/master/std/#std.Io.Writer.print
format method 呼び出しに "{f}" が必要
allocPrintZ
allocPrintZ -> allocPrintSentinel with sentinel: 0
ArrayList(u8) から writer を作る件
var out_buffer = std.ArrayList(u8).init(allocator);
defer out_buffer.deinit();
var writer = out_buffer.writer();
👇
var out_buffer = std.array_list.Managed(u8).init(allocator);
defer out_buffer.deinit();
var buf: [1024]u8 = undefined;
var adapter = out_buffer.writer().adaptToNewApi(&buf);
// std.io.Writer を値渡しすると壊れる
var writer: *std.io.Writer = &adapter.new_interface;
allocator から直接。
var out = std.Io.Writer.Allocating.init(allocator);
defer out.deinit();
// std.io.Writer を値渡しすると壊れる
var writer: *std.io.Writer = &out.writer;
vtable
std.json.stringify
https://github.com/the-argus/zig-compile-commands より。
fn writeCompileCommands(file: *std.fs.File, compile_commands: []CompileCommandEntry) !void {
const options = std.json.StringifyOptions{
.whitespace = .indent_tab,
.emit_null_optional_fields = false,
};
try std.json.stringify(compile_commands, options, file.*.writer());
}
👇
fn writeCompileCommands(file: *std.fs.File, compile_commands: []CompileCommandEntry) !void {
var buf: [1024]u8 = undefined;
var writer = file.*.writer(&buf);
var s = std.json.Stringify{
.writer = &writer.interface,
.options = .{
.whitespace = .indent_tab,
.emit_null_optional_fields = false,
},
};
try s.write(compile_commands);
try writer.interface.flush(); // 必要 !
}
Reader系
readUntilDelimiterOrEofAlloc
takeDelimiterExclusive
std.ArrayList
std.array_list.Managed
usingnamespace 消滅
addTranslateC で zig module を生成するように書き換える。
// c.zig
pub usingnamespace @cImport({
@cInclude("EGL/egl.h");
@cInclude("GLES/gl.h");
@cInclude("android/choreographer.h");
@cInclude("android/log.h");
@cInclude("android/sensor.h");
@cInclude("android/set_abort_message.h");
@cInclude("android_native_app_glue.h");
});
👇
// c.h include をまとめた c の header を作る
#include <EGL/egl.h>;
#include <GLES/gl.h>;
#include <android/choreographer.h>;
#include <android/log.h>;
#include <android/sensor.h>;
#include <android/set_abort_message.h>;
#include <android_native_app_glue.h>;
// translate して zig module 化
const t = b.addTranslateC(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/c.h"),
});
t.addIncludePath(.{ .cwd_relative = b.fmt("{s}/sources/android/native_app_glue", .{apk.ndk.path}) });
// import できるようにする
exe.root_module.addImport("c", t.createModule());
const c = @import("c.zig");
// 👇
const c = @import("c");
addLibrary (addSharedLibrary と addStaticLibrary 消滅)
const exe = b.addSharedLibrary(.{
.name = "native-activity",
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/main.zig"),
.link_libc = true,
});
👇
const exe = b.addLibrary(.{
.name = "native-activity",
.root_module = b.addModule("native-activity", .{
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/main.zig"),
.link_libc = true,
}),
.linkage = .dynamic,
});
target
isWasm => cpu.arch.isWasm
debugger
codelldb でローカル変数の中身が表示できない
const exe = b.addExecutable(.{
.name = "hoge",
.root_module = mod,
// for debug break point
.use_llvm = true,
});
Discussion