[Question] Build package with submodule

I’ve recently built a fuzzy matching library, zig-flx. I’m using the submodule to maintain the c source files in c-lib folder.

Now, I’m building the examples/test-flx project to see if I can depend on my own module.

Good news is, I’m able to build everything correctly except the missing c-lib files.

:1:1: error: no input files
C:\Users\un\AppData\Local\zig\p\12205a4519fc774374102a05b52a460e4598019dc775d7fb535517171a45abad3a08\src\stb_ds.c:2:10: error: '../include/stb_ds.h' file not found

Of course, I am getting this error due to the missing submodule c-lib. I assumed the package manager didn’t know or care about the submodule. My current solution is to manually paste the entire folder into the cache directory. Now, everything works! :slight_smile:

So my question is, is there a way I don’t need to paste the submodule every time I test the library manually?

Any help is appreciated!

1 Like

Not sure what you mean by:

The package manager doesn’t know about git submodules, but it knows about the c-lib folder because it’s listed in the manifest:

I think you could list flx-c as a dependency of zig-flx and download it. You might need to expose the C source files somehow with the build.zig in flx-c, though.

Got it! I overthought it a little and thought the Zig package manager was doing the magic behind the scenes (like git clone, etc). I think it will just download the tar.gz specified in .zig.zon file. :thinking:

Sorry, I am new to Zig. Do you mean to add a .zig.zon file in flx-c? Then, I can add flx-c as a dependency to zig-flx? :thinking:

You can add flx-c as a dependency to zig-flx’s build.zig.zon without adding anything to flx-c. The problem, I believe, is that you can only use dependency’s artifacts and modules that have been exposed in its build.zig. So, in order to actually see and use those C source files in zig-flx, you’ll need to add a build.zig to flx-c and expose them somehow. You could probably create a Zig file c_lib.zig in flx-c that imports all of the C headers and expose it in the new build.zig as a module like so:

_ = b.addModule("c_lib.zig", .{ .root_source_file = root_source_file });
1 Like