Skip to content

@cImport fails (macro substitution?) and compiler bug [ir.cpp:22931] #9996

@OBenjaminT

Description

@OBenjaminT

Remember to search before filing a new report

  • I searched for this bug and did not find it in the issue tracker, and furthermore, the title I used above will make this new bug report turn up in the search results for my query.

Zig Version

0.9.0-dev.1433+4a76523b9

Steps to Reproduce

I haven't narrowed the issue down. But basically you clone dwm and try and build it through a main.zig file.

git clone git://git.suckless.org/dwm

build.zig (what I could translate from the make files):

const std = @import("std");

pub fn build(b: *std.build.Builder) void {
    const target = b.standardTargetOptions(.{});
    const mode = b.standardReleaseOptions();

    const exe = b.addExecutable("zig-dwm", "main.zig");
    exe.linkLibC();
    exe.setTarget(target);
    exe.setBuildMode(mode);

    exe.linkSystemLibrary("X11");
    exe.linkSystemLibrary("Xinerama");
    exe.linkSystemLibrary("fontconfig");
    exe.linkSystemLibrary("Xft");
    exe.linkSystemLibrary("X11-xcb");
    exe.linkSystemLibrary("xcb");
    exe.linkSystemLibrary("xcb-res");

    exe.addLibPath("/usr/X11R6/lib");

    exe.addIncludeDir(".");
    exe.addIncludeDir("/usr/include/freetype2");
    exe.addIncludeDir("/usr/X11R6/include");
    exe.addIncludeDir("/usr/X11R8/lib");

    exe.addCSourceFiles(&.{
        "drw.c",
        "dwm.c",
        "util.c",
    }, &.{
        "-std=c99",
        "-pedantic", 
        "-Wall", 
        "-Wno-deprecated-declarations", 
        "-Os",
        "-D_DEFAULT_SOURCE",
        "-D_BSD_SOURCE",
        "-D_POSIX_C_SOURCE=200809L",
        "-DVERSION=\"6.2\"",
        "-DXINERAMA",
    });
    exe.install();
}

main.zig:

const dwm = @cImport(@cInclude("./dwm.c"));

pub fn main() anyerror!void {
    dwm.main();
}

And then run zig build run

Expected Behavior

Compiles normally, No errors.

(It compiles with zig cc perfectly fine.)

Actual Behavior

First it doesn't understand "dwm-"VERSION and fails to translate the brackets. (This happens twice)

If you remove the two occurrences of VERSION you get this error:

Unreachable at /home/vsts/work/1/s/src/stage1/ir.cpp:22931 in buf_write_value_bytes. This is a bug in the Zig compiler.thread 8047 panic: 
Unable to dump stack trace: debug info stripped
zig-dwm...The following command terminated unexpectedly:
~/zig build-exe ~/zig-dwm/main.zig -lc -lX11 -lXinerama -lfontconfig -lfreetype -lXft -lX11-xcb -lX11 -lxcb -lxcb -lxcb-res -cflags -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION="6.2" -DXINERAMA -- ~/zig-dwm/drw.c ~/zig-dwm/dwm.c ~/zig-dwm/util.c --cache-dir ~/zig-dwm/zig-cache --global-cache-dir ~/.cache/zig --name zig-dwm -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/harfbuzz -I /usr/include/glib-2.0 -I /usr/lib/glib-2.0/include -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/harfbuzz -I /usr/include/glib-2.0 -I /usr/lib/glib-2.0/include -I ~/zig-dwm -I /usr/include/freetype2 -I /usr/X11R6/include -I /usr/X11R8/lib -L /usr/X11R6/lib --enable-cache 
error: the following build command failed with exit code 6:
~/zig-dwm/zig-cache/o/6bc0c2586523ccc671438b5989f75207/build ~/zig ~/zig-dwm ~/zig-dwm/zig-cache ~/.cache/zig

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions