#using zig build in a C++ project

1 messages · Page 1 of 1 (latest)

ancient carbon
#

this is the build.zig

const std = @import("std");

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

    const cpp_flags: []const []const u8 = switch (optimize) {
        .Debug => &.{ "-fsanitize=address,undefined", "-O0", "-ggdb" },
        .ReleaseSmall => &.{ "-fno-sanitize=address,undefined", "-Oz" },
        .ReleaseSafe => &.{ "-fsanitize=address,undefined", "-O3" },
        .ReleaseFast => &.{ "-fno-sanitize=address,undefined", "-O3" },
    };

    const exe = b.addExecutable(.{
        .name = "vine",
        .root_module = b.createModule(.{
            .target = target,
            .optimize = optimize,
        }),
        .linkage = .dynamic,
    });
    exe.addCSourceFiles(.{
        .files = &.{
            "main.cpp",
            "uci.cpp",
        },
        .flags = cpp_flags,
        .language = .cpp,
        .root = b.path("src/"),
    });
    exe.linkLibCpp();

    b.installArtifact(exe);

    const run_step = b.step("run", "Run the app");

    const run_cmd = b.addRunArtifact(exe);
    run_step.dependOn(&run_cmd.step);

    run_cmd.step.dependOn(b.getInstallStep());

    if (b.args) |args| {
        run_cmd.addArgs(args);
    }
}
```but when i run it in debug i get linker errors for address sanitizer, am i missing anything for getting asan to work?
#

(neither static or dynamic linking work)

#

if i dont try to use asan it works fine

surreal parrot
#

zig does not ship with asan, only ubsan (written in zig) and tsan (compiled from source)

ancient carbon
#

ubsan (written in zig)
?

#

you mean to say ubsan was ported to zig?