How to use translate-c

I want to use capstone with zig. I found a project that can be linked https://github.com/allyourcodebase/capstone.
At the same time, I’d like to use zls for code completion. Right now, my approach is to first translate the C header with zig translate-c in zig 0.17

const install_translated = b.addInstallFile( t.output_file, "translated.zig", ); b.getInstallStep().dependOn(&install_translated.step);

And then

const mod = b.addModule("capstone", .{ .root_source_file = b.path("src/translated.zig"), .target = target, });

Now I can use capstone with zig.

const cs = @import("translated.zig");

Is there a better way to do these?

Have you read this?

Yes,but now i use zig master, I also read https://codeberg.org/ziglang/translate-c

    const translate_c = b.dependency("translate_c", .{});
    const t = Translator.init(translate_c, .{
        .c_source_file = b.path("to_translate.h"),
        .target = target,
        .optimize = optimize,
    });
    const install_translated = b.addInstallFile(
        t.output_file,
        "translated.zig",
    );

I first run zig build actually to get the translated.zig, then change my build.zig , remove the translate-c dependency.

The intended usage is to keep the ziglang/translate-c dependency and let the build system handle caching the translated code. If ZLS completions aren’t working for you with that setup, that’d be a separate issue.

1 Like

Thanks! Maybe I should take a look at zls.