#How do I add module to Zig project in 2023?

1 messages · Page 1 of 1 (latest)

cunning jolt
#

I'm aware of Package Manager MVP (https://github.com/ziglang/zig/pull/14265) and I assume that's the official package manager solution. However because of the lack of documentation I can't figure out how to add a module or package, like clap (https://github.com/Hejsil/zig-clap) to my own project.

What's the build.zig.zon (https://github.com/ziglang/zig/issues/14290) ? I guess it's like package.json or Cargo.toml but where is its specification?

GitHub

Demo
andy@ark ~> cd tmp/
andy@ark ~/tmp> git clone https://github.com/andrewrk/ffmpeg --depth 1
Cloning into 'ffmpeg'...
remote: Enumerating objects: 4138, done.
remote: Counting obje...

GitHub

Simple command line argument parsing library. Contribute to Hejsil/zig-clap development by creating an account on GitHub.

GitHub

Extracted from #14265. Zig Object Notation Instead of... [package] name=libffmpeg version=5.1.2 [dependency] name=libz url=https://github.com/andrewrk/libz/archive/f0e53cc2391741034b144a2c2076ed8a9...

rotund portal
#

An example:
build.zig.zon

.{
    .name = "bottom-zig",
    .version = "0.0.2",
    .dependencies = .{
        .args = .{
            .url = "https://github.com/MasterQ32/zig-args/archive/e0fd4e607a22c80977a75186798f1cb98b7ed698.tar.gz",
            .hash = "1220b38b261a6bdafa9495e1ea736984e995c4aa57306fc6734551518d5e7e486a0a",
        },
    },
}

on build.zig:

    const args = std.build.dependency(b, "args", .{});
...
...

exe.addModule("zig-args", args.module("args"));
cunning jolt
#

Can I use git submodule instead of downloading archive from github?

rotund portal
#

exe.addAnonymousModule("bottom", std.build.CreateModuleOptions{ .source_file = .{ .path = "bottom.zig" } });

You can use this

#

but you are not using the package manager there

#

the package manager is thought to be to not having to deal with submodules

#

which I appreciate

hasty thunder
#

is there a way to create anon modules with dependencies and stuff, like the old Pkg stuff?

naive quiver
#

yes

#

CreateModuleOptions has a dependencies field :)

rotund portal
#

yep

#

is an optional