#Current consensus for dependencies

1 messages · Page 1 of 1 (latest)

hardy rapids
#

Do I use Zigmod or Zon? Do I even use a package manager? How can I rely on third-party libraries in a reproducable way? What's the current guidance on this?

willow dome
#

you could try zigmod but i just use the built in one cause its "easier" since zigs already installed

#

relying on third party libraries in a reproducable way is kinda a crapshoot if the most liable thing to break is the build system shipped by zig itself

hardy rapids
#

i wanted to pull in the zig impl of clap for CLI parsing stuff

#

also reading the Bun codebase trying to see how they solve this but it's v possible they just write everything themselves

willow dome
#

if you look at the github issues for clap they show you what to do

hardy rapids
#

yeah but i'm worried how downstream users of my code will handle it if i end up doing two different things side by side?

willow dome
#

who cares about downstream users if you are shipping arg parsing?

#

unless you doing some kinda unholy thing where you argparse as an API

hardy rapids
#

i don't understand the first part sorry

#

i'm writing a binary

#

that i'd also like to expose as a library (i know how to do this with rust, for instance)

#

only the binary will need argparsing

willow dome
#

you'd need to test to see what happens i suppose for if you only add clap as a module to an exe and not to a module you export for others to make use of

#

assuming you have your code setup such that you have a module and exe in a single repo or somethin like that

hardy rapids
#

yeah this is another thing i need to solve, but i'm trying to get a minimum prototype atm

#

thanks for responding btw, much appreciated

willow dome
#

nah the package manager is kinda undocumented as far as i know

#

anyway dispite being undocumented the package manager isnt very sophisticated

#

but basically all that you do is that you add something with a

.dependencies = .{
  .some_dep_name = .{
    .url = "https://something",
  },
},

Then it does some magic with the zig fetch command which can basically only fetch a .tar.gz from a web url at the moment

#

then it spits out a complaint that the hash is missing and you put that field in

hardy rapids
#

so .url should point to a tarball directly?

willow dome
#

yeah

supple parcel
#

Also supports git urls

willow dome
#

when did that get added

supple parcel
#

during one of the recent build system rewrites I believe

willow dome
#

also wouldnt it be kinda inefficient to download the git tree in addition to the source files? Or maybe thats not how git urls work

supple parcel
#

it downloads a commit, not a tree

hardy rapids
#

right, that's cool and could be v useful for me

willow dome
#

oh you specify the commit, thats interesting

hardy rapids
#

so something like https://github.com/Hejsil/zig-clap/commit/cf3a4e763831dd7e0845fef4f209f5c780eda375?

#

or literally just the sha digest?

supple parcel
#

git+https://github.com/Hejsil/zig-clap.git#cf3a4e763831dd7e0845fef4f209f5c780eda375

hardy rapids
#

legend

#

oof

#
$ zig build
error: UnsupportedUrlScheme
supple parcel
#

only on zig master

#

basically the same thing as https://github.com/Hejsil/zig-clap/archive/cf3a4e763831dd7e0845fef4f209f5c780eda375.tar.gz

hardy rapids
#

only supports sha2-256

#

i should just update zig to master

#

nvm got it

#

okay now i just have an import error

#
$ cat build.zig.zon
.{
    .name = "zig-thing",
    .version = "0.1.0",
    .dependencies = .{
      .clap = .{
        .url = "git+https://github.com/Hejsil/zig-clap.git#cf3a4e763831dd7e0845fef4f209f5c780eda375",
        .hash = "1220b641ac5ed4187f293906201ee07f98423c942bf82e28c7c75a22d700b494c177",
      },
    },
    .paths = .{"", "src/main.zig"},
}
$ zig build
src/main.zig:1:22: error: no module named 'clap' available within module root
const clap = @import("clap");
supple parcel
#

that's expected, you need to update build.zig too

#

also paths should look more like .{ "build.zig", "build.zig.zon", "src" }

hardy rapids
supple parcel
#

It's now a dependency, so you can load the dependency, get the module that dependency exports, and add the module to your compile step.

hardy rapids