I’m making a small gui library and I’ve put all the elements into a subdirectory within src, resulting in a directory structure like this:
src
├── elements
│ ├── buttons.zig
│ ├── containers.zig
│ ├── dropdowns.zig
│ ├── inputs.zig
│ └── sliders.zig
├── gui-grabbing.zig
├── main.zig
├── root.zig
└── utils
└── parsing.zig
The issue I’m having is that every .zig file in the elements directory needs to use some functions from the gui-grabbing.zig file. Although writing @import("../gui-grabbing.zig") is not too much of an issue currently, I feel it is rather likely I will eventually end up with more nesting in the directory, making different files require a different amount of ../s prefixed before the actual name of the imported file.
As such, I would really like to eliminate it somehow. For a while I’ve been using @import("root") and had const grabbing = @import("gui-grabbing.zig") in root.zig, however I’ve since gathered that @import("root") imports the root file of the user of the library, rather than the library’s root.
The only other idea I’ve had for solving the issue would’ve been making a module with gui-grabbing.zig as its root in build.zig, but I’m still rather unfamiliar with the build system and am not sure if that approach might have some other less obvious issues.
Basically, what’s the best way to deal with this sort of “un-nesting”?