Specifying file paths for local dependencies uses system-formatted paths?

For Zig 0.14.0, adding dependencies from local file paths seems to use whatever the ‘correct’ path is for the system rather than some platform-independent representation:

zig fetch --save ../foo/ on a linux host:

.dependencies = .{
    .foo = .{
        .url = "../foo/",
        .hash = "...",
    },
},

zig fetch --save ../foo/ on a windows host:

.dependencies = .{
    .foo = .{
        .url = "..\\foo\\",
        .hash = "...",
    },
},

Is this intended?

I speculate that it’s a side-effect of the code used on Windows to ensure the exact case of the path.

The important part is does the resulting configuration work on other platforms? If not, that’s a bug.

.url = "../not/an/url" is not valid package URL. Using file URLs like in .url = "file:///foo/bar.tar.gz" is supposed to be supported (but there are bugs), but those can only point to tarballs, not directories, via absolute paths and are primarily meant for fetching packages on a local intranet. For build-root relative packages you use .path = "foo/bar".

In addition, using zig fetch --save filesystem/path to add a build root-relative package not supposed to be supported. The purpose of zig fetch is to copy a package to Zig’s global cache to avoid needing to access the network, not to manage your build.zig.zon. --save is provided as a convenience because calculating the correct hash to put in your build.zig.zon by hand would be unreasonable, but it does not make sense to --save a package fetched by a (CWD-relative) file path as a path entry, because those are meant for build root-relative packages.

So for path entries you need to edit your build.zig.zon manually.

I have an old open PR that addresses this source of confusion and fixes the file URL bugs.

5 Likes

Thank you for the detailed reply. It is appreciated. :slight_smile:

The purpose of zig fetch is to copy a package to Zig’s global cache to avoid needing to access the network, not to manage your build.zig.zon

Are there plans to add a CLI to manage build.zig.zon dependencies, then?

:slight_smile:

2 Likes