Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zig fetch --save localpath generates url+hash instead of just path #18639

Open
timfayz opened this issue Jan 21, 2024 · 0 comments · May be fixed by #21931
Open

zig fetch --save localpath generates url+hash instead of just path #18639

timfayz opened this issue Jan 21, 2024 · 0 comments · May be fixed by #21931
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@timfayz
Copy link

timfayz commented Jan 21, 2024

Zig Version

0.12.0-dev.2307+1b8f7e46f

Steps to Reproduce and Observed Behavior

lib/build.zig.zon

.{
    .name = "lib",
    .version = "0.1.0",
    .paths = .{""},
}

lib/build.zig

const std = @import("std");

pub fn build(b: *std.Build) void {
    _ = b.addModule("lib", .{
        .root_source_file = .{ .path = "lib.zig" },
    });
}

lib/lib.zig

pub fn get_number() usize {
    return 42;
}

_

app/build.zig.zon

.{
    .name = "app",
    .version = "0.1.0",
    .paths = .{""},
}

app/build.zig

const std = @import("std");

pub fn build(b: *std.Build) !void {
    const exe = b.addExecutable(.{
        .name = "main",
        .root_source_file = .{ .path = "main.zig" },
        .target = b.host,
    });

    const lib_mod = b.dependency("lib", .{}).module("lib");
    exe.root_module.addImport("lib", lib_mod);
    b.installArtifact(exe);
}

app/main.zig

const lib = @import("lib");

pub fn main() !void {
    @import("std").log.debug("{d}", .{lib.get_number()});
}

app and lib share the same parent folder.

Running:

$ cd app
$ zig fetch --save ../lib

Results in:

.{
    .name = "app",
    .version = "0.1.0",
    // new
    .dependencies = .{
        .lib = .{
            .url = "../lib",
            .hash = "1220773b828b56e62e7e70238b4213e99e8b7e4f8ccec8a70e1404bdfe4886bb0adf",
        },
    },
    .paths = .{""},
}

Running zig build thereafter produces an error:

thread 7278714 panic: unable to find module 'lib'
/Users/timfayz/.zig/lib/std/debug.zig:434:22: 0x1021314a3 in panicExtra__anon_14927 (build)
    std.builtin.panic(msg, trace, ret_addr);
                     ^
/Users/timfayz/.zig/lib/std/debug.zig:409:15: 0x102105477 in panic__anon_13700 (build)
    panicExtra(null, null, format, args);
              ^
/Users/timfayz/.zig/lib/std/Build.zig:1730:18: 0x1020c8af7 in module (build)
            panic("unable to find module '{s}'", .{name});
                 ^
/Users/timfayz/dev/test/fetchZonLocally/app/build.zig:4:52: 0x1020c86a7 in build (build)
    const lib_mod = b.dependency("lib", .{}).module("lib");
                                                   ^
/Users/timfayz/.zig/lib/std/Build.zig:1885:43: 0x1020b42fb in runBuild__anon_8021 (build)
        .ErrorUnion => try build_zig.build(b),
                                          ^
/Users/timfayz/.zig/lib/build_runner.zig:319:29: 0x1020af913 in main (build)
        try builder.runBuild(root);
                            ^
/Users/timfayz/.zig/lib/std/start.zig:585:37: 0x1020b4733 in main (build)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x10245d0f3 in ??? (???)
???:?:?: 0xc9677fffffffffff in ??? (???)
error: the following build command crashed:
/Users/timfayz/dev/test/fetchZonLocally/app/zig-cache/o/eb64301265b7ff0d532a4f9e65583421/build /Users/timfayz/.zig/zig /Users/timfayz/dev/test/fetchZonLocally/app /Users/timfayz/dev/test/fetchZonLocally/app/zig-cache /Users/timfayz/.cache/zig --seed 0x5be323c9

Expected Behavior

I believe zig fetch --save ../lib should be aware of the filesystem level and generate the following instead:

    ...
    .dependencies = .{
        .lib = .{
            .path = "../lib",
        },
    },
    ...
}

Changing .url to .path and removing .hash fix the error.

@timfayz timfayz added the bug Observed behavior contradicts documented or intended behavior label Jan 21, 2024
castholm added a commit to castholm/zig that referenced this issue Nov 6, 2024
The purpose of `zig fetch` is to copy a package to the global cache to
avoid needing to access the network. `path` entries in a build.zig.zon
are for relative paths inside a package. It does not make sense to
`--save` a package fetched by a (CWD-relative) file path.

Closes ziglang#18639
castholm added a commit to castholm/zig that referenced this issue Nov 10, 2024
The purpose of `zig fetch` is to copy a package to the global cache to
avoid needing to access the network. `path` entries in a build.zig.zon
are for relative paths inside a package. It does not make sense to
`--save` a package fetched by a (CWD-relative) file path.

Closes ziglang#18639
castholm added a commit to castholm/zig that referenced this issue Nov 14, 2024
The purpose of `zig fetch` is to copy a package to the global cache to
avoid needing to access the network. `path` entries in a build.zig.zon
are for relative paths inside a package. It does not make sense to
`--save` a package fetched by a (CWD-relative) file path.

Closes ziglang#18639
castholm added a commit to castholm/zig that referenced this issue Nov 17, 2024
The purpose of `zig fetch` is to copy a package to the global cache to
avoid needing to access the network. `path` entries in a build.zig.zon
are for relative paths inside a package. It does not make sense to
`--save` a package fetched by a (CWD-relative) file path.

Closes ziglang#18639
andrewrk pushed a commit to castholm/zig that referenced this issue Dec 14, 2024
The purpose of `zig fetch` is to copy a package to the global cache to
avoid needing to access the network. `path` entries in a build.zig.zon
are for relative paths inside a package. It does not make sense to
`--save` a package fetched by a (CWD-relative) file path.

Closes ziglang#18639
castholm added a commit to castholm/zig that referenced this issue Dec 15, 2024
The purpose of `zig fetch` is to copy a package to the global cache to
avoid needing to access the network. `path` entries in a build.zig.zon
are for relative paths inside a package. It does not make sense to
`--save` a package fetched by a (CWD-relative) file path.

Closes ziglang#18639
castholm added a commit to castholm/zig that referenced this issue Feb 28, 2025
The purpose of `zig fetch` is to copy a package to the global cache to
avoid needing to access the network. `path` entries in a build.zig.zon
are for relative paths inside a package. It does not make sense to
`--save` a package fetched by a (CWD-relative) file path.

Closes ziglang#18639
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant