ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.65k stars 2.53k forks source link

zig build SIGSEGV with C++ source files and C as ofmt #21675

Open gptlang opened 2 weeks ago

gptlang commented 2 weeks ago

Zig Version

0.14.0-dev.1798+148b5b4c7

Steps to Reproduce and Observed Behavior

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{ .default_target = .{ .ofmt = .c } });

    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "LightChase",
        .target = target,
        .optimize = optimize,
    });
    exe.addCSourceFile(.{ .file = b.path("src/main.cxx"), .flags = &.{"-std=c++20"} });
    exe.linkLibCpp();
    b.installArtifact(exe);
}

Expected Behavior

Not error?

Actual behavior

$ zig build
install
└─ install LightChase
   └─ zig build-exe LightChase Debug native failure
error: the following command terminated unexpectedly:
/home/acheong/.zvm/master/zig build-exe -ofmt=c -cflags -std=c++20 -- /home/acheong/Projects/huawei/LightChase/src/main.cxx -ODebug -target native -mcpu native -Mroot -lc++ --cache-dir /home/acheong/Projects/huawei/LightChase/.zig-cache --global-cache-dir /home/acheong/.cache/zig --name LightChase --zig-lib-dir /home/acheong/.zvm/master/lib/ --listen=- 
Build Summary: 0/3 steps succeeded; 1 failed
install transitive failure
└─ install LightChase transitive failure
   └─ zig build-exe LightChase Debug native failure
error: the following build command failed with exit code 1:
/home/acheong/Projects/huawei/LightChase/.zig-cache/o/fd303a8b3608b22b313bd10a7f69bf9c/build /home/acheong/.zvm/master/zig /home/acheong/.zvm/master/lib /home/acheong/Projects/huawei/LightChase /home/acheong/Projects/huawei/LightChase/.zig-cache /home/acheong/.cache/zig --seed 0x885fd524 -Z0e6b505e4c6f0b71
$ zig build-exe -ofmt=c -cflags -std=c++20 -- /home/acheong/Projects/huawe
i/LightChase/src/main.cxx -ODebug -target native -mcpu native -Mroot -lc++ --cache-dir /home/acheong/Projects/huawei/LightChase/.zig-cache -
-global-cache-dir /home/acheong/.cache/zig --name LightChase --zig-lib-dir /home/acheong/.zvm/master/lib/

fish: Job 1, '/home/acheong/.zvm/master/zig b…' terminated by signal SIGSEGV (Address boundary error)
gptlang commented 2 weeks ago

Rather than SIGSEGV maybe return an error message saying it's not meant to be possible.