Unable to import module on zig 0.17

Hello I am currently migrating my codebase to using translate-c and modules that compile C/C++ using modules instead of @cImport. My project is a game engine using Vulkan as its backend. All my other dependencies have been straightforward to migrate, but I have run into trouble with AMD’s Vulkan Memory Allocator (VMA). It is a nearly purely C++ header file (It has a C API), but it NEEDS to be compiled by LLVM since it uses so many C++ features (Templates). I had this same issue with other libraries, but I was able to translate-c them accordingly.

I get the following error when trying to use the module:

src/graphics.zig:5:21: error: no module named 'vma' available within module 'root'
const vma = @import("vma");

Here is the complete source code for vma.cpp:

#define VMA_IMPLEMENTATION
#include <vk_mem_alloc.h>

#include <vulkan/vulkan.h>

It is defined as follows in my build.zig:

 const vma_mod = b.createModule(.{
        .optimize = optimize,
        .target = target,
        .link_libc = true,
        .link_libcpp = true,
    });
    vma_mod.addCMacro("VMA_IMPLEMENTATION", "");
    vma_mod.addCSourceFile(.{
        .file = b.path("lib/vma.cpp"),
        .flags = &.{"-lc++"},
    });
    vma_mod.addIncludePath(b.path("lib/VulkanMemoryAllocator-3.2.1/include"));
    vma_mod.linkSystemLibrary("vulkan", .{ .needed = true });

Then in my main executable’s root module I’m importing it as follows:

const ceres_voxel = b.addExecutable(.{
    .name = "Engine",
    .use_llvm = true,
    .root_module = b.createModule(.{
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
        .imports = &.{
            ...
            .{
                .name = "vma",
                .module = vma_mod,
            },
            ...
        },
    }),
});

I have no compilation errors from the vma module and if I use ceres_voxel.root_module.addImport() instead of adding the module to the struct on definition I have the same issue.

I like to stay on the latest tagged release so any help is appreciated!

(This happens in both 0.17 and 0.17.1)
(Let me know if you want the full source of the build.zig and I will reply with it)

The only difference is that addImport dupes the name, but .imports options doesn’t.

Is the name generated with unstable/re-used memory??

Just to clarify, no module named 'vma' is happening when you try to build the ceres_voxel executable? It’d be helpful if you could provide the full error output.

Full compilation error

install
└─ install Engine
   └─ compile exe Engine debug native 1 errors
src/graphics.zig:5:21: error: no module named 'vma' available within module 'root'
const vma = @import("vma");
                    ^~~~~
referenced by:
    graphics.VulkanState: src/graphics.zig:223:20
    main: src/main.zig:321:24
    4 reference(s) hidden; use '-freference-trace=6' to see all references
error: 1 compilation errors
failed command: /usr/bin/zig build-exe -fllvm -Odebug --dep vulkan --dep vma --dep glfw --dep ft --dep zmath --dep stb -Mroot=src/main.zig -lvulkan -Odebug --dep c_builtins --dep helpers -Mvulkan=.zig-cache/o/2b5d2aaa4a5a98ed02838ef9d5caabed/generated.zig -cflags -lc++ -- lib/vma.cpp -Odebug -I lib/VulkanMemoryAllocator-3.2.1/include -DVMA_IMPLEMENTATION= -Mvma -lglfw -Odebug --dep c_builtins --dep helpers -Mglfw=.zig-cache/o/29b27b497ee041d79b9c6e3d40a32c18/generated.zig -I/usr/include/freetype2 -I/usr/include/libpng16 -lfreetype -Odebug --dep c_builtins --dep helpers -Mft=.zig-cache/o/ec5717ab031c822751cf8aa048f28c37/generated.zig --dep zmath_options -Mzmath=zig-pkg/zmath-0.11.0-dev-wjwivaAtAwA7W0_rRXAqdwjWGigw6_pxgsYtAdjUbqUj/src/root.zig -cflags -- ./lib/stb_image.h ./lib/stb_rect_pack.h -Odebug -DSTB_IMAGE_IMPLEMENTATION= -DSTB_RECT_PACK_IMPLEMENTATION= -Mstb -Mc_builtins=zig-pkg/translate_c-2.0.2-Q_BUWvBNBwDnyehSiuAJmdFcMYHYGA-Jc3KiYdrV2Dqx/lib/c_builtins.zig -Mhelpers=zig-pkg/translate_c-2.0.2-Q_BUWvBNBwDnyehSiuAJmdFcMYHYGA-Jc3KiYdrV2Dqx/lib/helpers.zig -Mzmath_options=.zig-cache/o/22df1ab59a6744239badc64329e425d5/options.zig -lc++ -lc --cache-dir .zig-cache --global-cache-dir /home/gwn/.cache/zig --build-root . --name Engine --zig-lib-dir /usr/lib/zig/ --listen=-

Build Summary: 30/33 steps succeeded (1 failed)
install transitive failure
└─ install Engine transitive failure
   └─ compile exe Engine debug native 1 errors

Also pointing out that you can’t @import modules unless they have a root zig file.

Which your module does not, though that should report a different error…