Zig module not visible after import

I’m attempting to import GitHub - ziglibs/zlm: Zig linear mathemathics into my project. I’ve prepared the following in my build.zig.zon file based on doing a zig fetch --save:

.dependencies = .{
    .zlm = .{
        .url = "https://github.com/ziglibs/zlm/archive/35b76fae19f9d0a1ed541db621d7c4b3e266087e.tar.gz",
        .hash = "1220342ac333965de915f74a8425e4848ffe46852da0e4789103f9ec650c3cd22456",
    },
}

And I’m then using the imported module in my build.zig file like so:

const zlm = b.dependency("zlm", ...);
my_library.root_module.addImport("zlm", zlm.module("zlm"));

However, two weird things are going on here. Firstly, in the b.dependency("zlm", ...) call, if I supply the .target and .optimize fields then I get the following strange compilation error:

error: invalid option: -Dcpu
error: invalid option: -Dtarget
error: invalid option: -Doptimize
/home/vesper/.config/VSCodium/User/globalStorage/ziglang.vscode-zig/zig_install/lib/std/Build.zig:1954:35: 0x1116824 in dependency__anon_11147 (build)
            return dependencyInner(b, name, pkg.build_root, if (@hasDecl(pkg, "build_zig")) pkg.build_zig else null, pkg_hash, pkg.deps, args);
                                  ^
/home/vesper/Documents/bspsuite/build.zig:22:29: 0x1115de7 in build (build)
    const zlm = b.dependency("zlm", .{
                            ^

If I remove those fields then the build script compiles OK, but my library compilation fails when I attempt to use zlm:

src/bspsuite/math.zig:1:28: error: no module named 'zlm' available within module root
pub usingnamespace @import("zlm").SpecializeOn(f64);
                           ^~~~~

I’m pretty sure the module I’m looking for is actually called "zlm", as this is what the zlm example says to import. Does anyone know what might be going on here?

The correct way, is without target and optimize because the zlm module does not expose them as options.

For the my_library step you add the import zlm.
Do you also import it for other steps, such as test, or run?

1 Like

Oh you’re right, I hadn’t added the import to the unit test target, and that was what I was running. That makes a lot of sense :grin:

Regarding the imported module and the options it exposes, is there an easy way to figure that kind of stuff out without having to dig into the build file in the module itself?

1 Like

The only way is from package build.zig module declaration.

OK, that’s fair enough I guess. Thanks for the help!