Upcoming zig 0.12 changes of writing `build.zig`

(originally posted here: https://zig.news/liyu1981/upcoming-zig-012-changes-of-writing-buildzig-1hb7)

Note for myself 🙂

Add module dependency

In short, before version 0.12.0-dev.1828+225fe6ddb, in build.zig, add pkg modules to my exe as follows

const zcmd_dep = b.dependency("zcmd", .{});
const jstring_dep = b.dependency("jstring", .{});

...

var zlex_exe = b.addExecutable(.{
...    
});

zlex_exe.addModule("zcmd", zcmd_dep.module("zcmd"));
zlex_exe.addModule("jstring", jstring_dep.module("jstring"));

will not work in newer versions (like master_0.12.0-dev.2818+97290e0bf), as breaking changes in zig build.

the new way is

const zcmd_dep = b.dependency("zcmd", .{});
const jstring_dep = b.dependency("jstring", .{});

...

var zlex_exe = b.addExecutable(.{
...    
});

zlex_exe.root_module.addImport("zcmd", zcmd_dep.module("zcmd"));
zlex_exe.root_module.addImport("jstring", zcmd_dep.module("jstring"));

the new addImport function doc is here.

addModule

this one is an easy change, just need to change from

    _ = b.addModule("bison_data", .{ .source_file = .{ .path = b.pathFromRoot("bison/data") } });

to

    _ = b.addModule("bison_data", .{ .root_source_file = .{ .path = b.pathFromRoot("bison/data") } });

as struct field source_file renamed to root_source_file. Naming and renaming the 2 fundamental tasks when coding so this is well understood XD. Hopefully we can see a much stable interfaces in future.