#how to put a path to a lib as a module

1 messages · Page 1 of 1 (latest)

stable rivet
#

how would i do that?

half folio
#

with zig fetch --save <path>

#

then import it as a dependency and create a module from it

dusky spoke
#

from path:

build.zig.zon:

.dependencies = .{
    .module_name = .{ .path = "../module_path" },
},

build.zig:

const module_name_dep = b.dependency("module_name", .{ .target = target, .optimize = optimize });

exe_mod.addImport("module_name", module_name_dep.module("module_name");

if you don't have a build.zig in the other module, you'll need to create it in this build.zig (instead of module_name_dep.module("..."))

const module_name_mod = b.createModule(.{
    .root_module_path = module_name_dep.path("src/lib.zig"),
});
#

oh can you zig fetch --save a path too?

half folio
dusky spoke
#

you can but it sets it as url and hash in build.zig.zon instead of path

#

but the hash needs to be changed every time you modify the package

#

(it probably doesn't check for that and will be a problem in the future)

half folio
#

oh yeah and the other thing is I have my own libraries each one with their own build.zig and build.zig.zon so probably this is not the same use case as op, my bad