getty-zig / getty

A (de)serialization framework for Zig
https://getty.so
MIT License
183 stars 14 forks source link

Build failure when depending on both getty and getty-json #108

Closed LordMZTE closed 1 year ago

LordMZTE commented 1 year ago

Description

When a module depends on both getty and getty-json, it will fail to build.

How to Reproduce the Bug

  1. Create a build.zig.zon with this content:

    .{
    .name = "my_project",
    .version = "0.2.0",
    
    .dependencies = .{
        .getty = .{
            .url = "https://github.com/getty-zig/getty/archive/531295977a331fa73f450e101bea63da794f835e.tar.gz",
            .hash = "1220bb29b31954344a0d8cbb7e966f818677e7a0aa6840b95df724f74a8dd1fb734b",
        },
        .getty_json = .{
            .url = "https://github.com/getty-zig/json/archive/53ad59f2c4cd895841fc8c66bda7548850df998a.tar.gz",
            .hash = "12208121cb38480924fedb5a649b409f8cd27fb600b89880955ad97da66d9d59060d",
        },
    },
    }
  2. Try building the project it

Additional Context

This is the error message produced:

zig build-exe zupper Debug native: error: the following command failed with 1 compilation errors:
/home/lordmzte/.local/share/zupper/installs/master/zig build-exe /home/lordmzte/dev/zupper/src/main.zig -lcurl -larchive -lc -fno-strip --cache-dir /home/lordmzte/dev/zupper/zig-cache --global-cache-dir /home/lordmzte/.cache/zig --name zupper --mod getty::/home/lordmzte/.cache/zig/p/1220bb29b31954344a0d8cbb7e966f818677e7a0aa6840b95df724f74a8dd1fb734b/src/getty.zig --mod zig-args::/home/lordmzte/.cache/zig/p/1220e4ae687b355b164d986c6400eef6cfc2b1020718eaa72914865d344b2f192141/args.zig --mod ansi-term::/home/lordmzte/.cache/zig/p/12203d3ac1e29d8bafe6a1aa23412ad09fc3d2c95b568d428e55cd152feec204344c/src/main.zig --mod json:getty,concepts:/home/lordmzte/.cache/zig/p/12208121cb38480924fedb5a649b409f8cd27fb600b89880955ad97da66d9d59060d/src/json.zig --mod concepts::/home/lordmzte/.cache/zig/p/12204cbd628c6436be2c90d1e4b782a00be121133de83b0cdd800a2777dc1e1aee84/src/lib.zig --mod getty0::/home/lordmzte/.cache/zig/p/1220bb29b31954344a0d8cbb7e966f818677e7a0aa6840b95df724f74a8dd1fb734b/src/getty.zig --mod known-folders::/home/lordmzte/.cache/zig/p/122028c00915d9b37296059be8a3883c718dbb5bd174350caedf152fed1f46f99607/known-folders.zig --deps zig-args,known-folders,ansi-term,getty=getty0,json --enable-cache --listen=- 
Build Summary: 0/3 steps succeeded; 1 failed (disable with -fno-summary)
install transitive failure
+- install zupper transitive failure
   +- zig build-exe zupper Debug native 1 errors
/home/lordmzte/.cache/zig/p/1220bb29b31954344a0d8cbb7e966f818677e7a0aa6840b95df724f74a8dd1fb734b/src/getty.zig:1:1: error: file exists in multiple modules
/home/lordmzte/.cache/zig/p/1220bb29b31954344a0d8cbb7e966f818677e7a0aa6840b95df724f74a8dd1fb734b/src/getty.zig:1:1: note: root of module root.json.getty
/home/lordmzte/.cache/zig/p/1220bb29b31954344a0d8cbb7e966f818677e7a0aa6840b95df724f74a8dd1fb734b/src/getty.zig:1:1: note: root of module root.getty
ibokuri commented 1 year ago

The error only occurs when the both versions of Getty (the one depended on by the project and the one depended on by getty-json) are the same. If the versions are different, the error does not occur.

The underlying issue is in the package manager, not Getty (context). Specifically, the package manager does not yet deduplicate packages properly, hence why the compiler sees two different Getty modules even though they're the same.

There are ways to work around this, as is pointed out in the linked Discord thread, but it involves replacing the package manager logic that exists in both packages, and I don't feel that it is worth it. For now, projects that depend on both modules will just have to live with using mismatched versions until the issue is fixed in the package manager.