i agree that i should i try map my own concepts of source-file organization onto the zig nomenclature – if for no other reason than to avoid using terms like ‘module’ and ‘package’ with meanings different from zig…
and let’s remove any specific references to java (which clearly uses the term ‘package’ to mean something very different from a zig ‘package’)…
to that end, let me present a source-file organization that is “neutral” to this terminology… what i’m looking for here is the best way to realize this (conceptual) three-level hierarchy within zig…
- bundle
- bucket
- Unit
- Unit
...
- bucket
...
- bundle
...
the ‘bundle’ is my unit of delivery and seems to easily map onto a zig ‘package’… and correct me if i’m wrong, but one zig ‘package’ can depend on other zig ‘packages’… from my perspective, this “depends” relation should be acyclic…
this is essentially the domain of build.zig.zon
, not unlike the package.json
file in a npm
package… i release that the contents of the zig ‘package’ are invariably fetched into the cache; but for clarity, let’s imagine that the “top-level” of my current project workspace contains copies of (or links to) each package’s content… and yes, i realize that i can chose a “local” name for each package distinct from the name given by its provider…
at the lowest level of my hierarchy, assume that each ‘Unit’ is a source-file named Unit.zig
… and while Unit.zig
can (obviously) use "std"
and other zig libraries, my units will mostly import other units found somewhere in my project workspace… the Unit import relationship is also acyclic by design.
the middle layer of my hiearchy – the ‘bucket’ – really exists as a way to further aggregate Unit source files into a logical collection that is somehow distinct from the physical ‘bundle’ in which it is contained… as a “best practice”, bucket names strive to be globally unique by following a convention such as git.biosbob.utils
or com.txn.cc23xx
… (a similar “prefix” discipline could be applied to bucket names as well…)
for one unit to “import” another unit, it will use a canonical identifier of the form bucket-name/Unit-name
… and obviously, zig provides multiple opportunities to create a “local” alias for this canonical identifier… in zig, i would want to say something like:
const Timer = @import("git.biosbob.utils/Timer");
so now let me ask about realizing this in zig… presumably, git.biosbob
could create a top-level bundle (ie, a zig package) that aggregates multiple Units with names of the form git.biosbob.*
… and i could specifically create a zig module for each – with a name like "git.biosbob.utils/Timer"
that is associated with a single root source file… since the “tree” associated with each such module contain just one file, presumably i have no issues with overlapping root trees…
alternatively, i could place a special bucket-root.zig
file in each of my bucket folders and declare this file as the root of a zig module named "git.biosbob.utils"
… internally, this file would look something like:
pub const Timer = @import("./Timer.zig");
...
the client would then import this unit by saying:
const Timer = @import("git.biosbob.utils").Timer;
personally, i prefer the "git.biosbob.utils/Timer"
approach; one less set of bucket-root.zig
files to maintain and clutter up my workspace… but clearly the number of zig modules named in each zig package will be much larger…
which then leads to my final observation and question… by following what some might see as a “rigid” folder/file organization, i can VERY EASILY generate the requisite build.zig
and build.zig.zon
files to realize my source code organization paradigm within zig…
i already name my bundles/buckets/Units in my project workspace… why not simply harvest that information as a specification for information that is ultimately codified in build.zig
and build.zig.zon
??? is there any precendence for generating these files in the zig ecosystem???