I could make the root package depend on the child package but, the child package is kind of an example which depends on the root package, so pointing each other in the build.zig.zon, I get error: file exists in multiple modules,
which is kind of expected i suppose?
I don’t think you should create circular dependencies in build.zig.zon.
Instead I think dependencies should form an acyclic graph.
I think you have these options:
put your example within your lib and only have one project (dependency)
put your example outside your lib and create a 3rd project that bundles lib + examples
don’t bundle examples and just link to them as example applications
I think you want to do the first with 2 dependencies (but I don’t think cycles are allowed), but if you want a lib and examples separate but also something that bundles them, I think you need to go to the ABC setup.
A is the library, B is the example and C is the “meta” package that bundles A and B in a way that is nearly identical to the user using A, except that they also are able to run examples from B. Basically merging the options/steps of A and B.
So far I have only done 1. and 3. because they are simpler. I imagine figuring out how to do 2. well would involve some subtle details, but I also imagine that some projects have already done this.
What I have seen more often so far, is that projects just include examples directly and thus end up with a single dependency that does everything, maybe in combination with flags or conditional compilation to avoid downloading gigabytes of data required to get examples to run, until that data is actually needed. I think either mach or zig-gamedev was working like that at some point (but it might have changed since I last looked at it).
This is just my current thinking so far, I would have to get some more practical experience with these situations, before I can say whether this is definitely how it works.
Hmm, I see, the reason I am not going with the first option is it’s kind of just feels like a test component rather than an example(even though it’s showing how to use the exports/functions of the lib), I think examples should be standalone, sort of like also give the user an idea how the packag/lib is being linked or the whole build process too. I think for now spawning another zig process is alright.