#cImport behaviour changes in Zig v0.12.0

1 messages · Page 1 of 1 (latest)

rapid violet
#

Hi to all!
I am trying to migrate my personal projects to v0.12.0. I rely heavily on calling C-Code.
So far I used the "@cImport()" and "@cInclude()" functions inside the Zig code and addIncludePath()/addSystemIncludePath() to add the header include paths.

So far I am able to build the C-Code correctly, however even a simple const c = @cImport({ @cInclude("board.h"); }); is unable to find the "board.h" header. error: 'board.h' file not found. Context: Here board.h is a part of the C-BSP i need for my project. This path is added to the C-compilation step but not resolved in Zig.

How has this behaviour changed? What do I need to add the path in the build system?

Thanks in advance.

Francisco

pulsar talon
#

If possible, could you post your full build.zig? There's probably some essential step missing

rapid violet
#

pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});

const microzig = microzig_build.init(b, .{});

for (variants) |variant| {
    const firmware = microzig.add_firmware(b, .{
        .name = variant.name,
        .target = variant.target,
        .optimize = optimize,
        .root_source_file = .{ .path = variant.root_source_file },
    });

    firmware.add_system_include_path(b.path("picolibc/clang-compiled/picolibc/include"));
    firmware.add_object_file(b.path("picolibc/clang-compiled/picolibc/libc.a"));
    firmware.add_object_file(b.path(gecko_sdk_base_dir ++ "/emdrv/nvm3/lib/libnvm3_CM3_gcc.a"));

    // Config path
    firmware.add_include_path(b.path("c/config"));

    for (gecko_include_path) |path| {
        firmware.add_include_path(b.path(path));
    }

    firmware.add_include_path(b.path("c/board/inc"));

    for (gecko_sdk_source_paths) |path| {
        firmware.add_c_source_file(.{ .file = b.path(path), .flags = &gecko_sdk_c_flags });
    }

    for (board_source_paths) |path| {
        firmware.add_c_source_file(.{ .file = b.path(path), .flags = &gecko_sdk_c_flags });
    }

    microzig.install_firmware(b, firmware, .{});
}

}

pulsar talon
#

where is board.h supposed to be located?

#

since you're using microzig it's a bit difficult to tell what is going on, it's possible it could also be a bug or oversight in microzig's build system abstractions

rapid violet
#

board.h is located in "c/board/inc/"

pulsar talon
#

try firmware.modukles.app.addIncludePath

#

I would suggest reporting this issue back to microzig if you think the intent is to add the include path to all modules and not just the root artifact