Importation and dependencies

Note that in Zig, you can directly import other Zig files in your same directory or in a subdirectory, so you could put a file at the upper ‘src’ directory level that imports the lower level files:

File: src/api.zig

pub const hello = @import("subdir1/hello.zig");
pub const print = @import("subdir2/print.zig");

And then crete the module using this file as the root_source_file. Let’s say you provide it via anonymous import to your other files as api, then you can for example:

File: src/subdir1/hello.zig

const print = @import("api").print;
// use print
4 Likes