Does zig.zon not support non zig based projects

YO

Allow me to spin you a short story. If you don’t want the leading up to the problem sweet nothings feel free to skip to “The Problem”.

So I plopped into my work desk today after work and said let’s mess with this interesting idea.

I discovered that he is using luajit. Ok let’s install that.

Great, I can build it with make cool.

zig build → oop this doesn’t work because make install for luajit has installed c headers into a different directory than this guys build.zig expects.

Let’s go the extra mile and try to encapsulate this in zig. Maybe even put in a PR.

I’d like to pull down this c code and therefore have these headers in a guaranteed location. Ok let’s try to do this with .zig.zon.

The Problem

When I run zig fetch --save https://github.com/LuaJIT/LuaJIT/archive/87ae18af97fd4de790bb6c476b212e047689cc93.tar.gz I’m greeted with the following error.

error: unable to determine name; fetched package has no build.zig.zon file

Is this intended? Am I to interpret this as zig.zon only being compatible with zig projects?

My goal here is to pull some c files down from a commit and then build with zig. (idk if I want to commit to dealing with actually doing the work of rewriting a complex makefile in zig, but this seems like I’m on a common path here.)

Is the intention that my current path is invalid? Am I doing something incorrect? Is there not a way to pull a repo without a build.zig.zon down?

The Assumed Solution

Ok so if I fork luajit and add a build.zig.zon the fetch does in fact work. Or it at least updates my dependencies file correctly.

Ok sweet… where are my files. Oh, looks like they are in some cache somewhere. Let’s look through the cache. Oh no, the cache isn’t very legible I don’t know if it’s in the local or global cache. I think it’s meant to be in global? Is it doing some lazy loading or something and it see’s I haven’t actually tried to use it yet and it isn’t actually fetching?

The dreaded potential outcome

Is the only way to use the package manager to actually completely build a project in zig? That can be a heavy lift sometimes.

I’ve found the last 2 projects I’ve considered undertaking this effort for have all been running code generation tooling and that has scared me off.

I’d like to do this if possible.

The beautiful evanescent ideal future

I create a “default starting point” for creating zig extensions for neovim.
Or at least build upon this guy’s current work.

$ zig fetch --help
Usage: zig fetch [options] <url>
Usage: zig fetch [options] <path>

    Copy a package into the global cache and print its hash.

Options:
  -h, --help                    Print this help and exit
  --global-cache-dir [path]     Override path to global Zig cache directory
  --debug-hash                  Print verbose hash information to stdout
  --save                        Add the fetched package to build.zig.zon
  --save=[name]                 Add the fetched package to build.zig.zon as name
  --save-exact                  Add the fetched package to build.zig.zon, storing the URL verbatim
  --save-exact=[name]           Add the fetched package to build.zig.zon as name, storing the URL verbatim

you need --save=[name] since the name cannot be determined

4 Likes

Damn my bad.
Answer was in the cli help message.
Tried to be diligent before asking should have looked a little harder.
my b.

4 Likes

no need to apologize, one could easily argue that the error message you got should have mentioned the possibility of using --save=[name]

6 Likes