Skip to content

Cannot compile C file including systemd/sd-journal.h #25969

@psznm

Description

@psznm

Zig Version

0.16.0-dev.1363+d2b1aa48a

Steps to Reproduce and Observed Behavior

install
└─ install test
   └─ compile exe test Debug native 1 errors
.zig-cache/o/e41889ec32e3fb4ce338a9a64d670654/journal.zig:435:9: error: expected statement, found 'pub'
        pub const b = @compileError("unable to resolve var init expr");
        ^~~
error: 1 compilation errors
failed command: /opt/zig-x86_64-linux-0.16.0-dev.1363+d2b1aa48a/zig build-exe -lsystemd -fsanitize-c=full -ODebug --dep journal -Mroot=/home/kmarek/git/zig-systemd-test/main.zig -ODebug -Mjournal=.zig-cache/o/e41889ec32e3fb4ce338a9a64d670654/journal.zig -lc --cache-dir .zig-cache --global-cache-dir /home/kmarek/.cache/zig --name test --zig-lib-dir /opt/zig-x86_64-linux-0.16.0-dev.1363+d2b1aa48a/lib/ --listen=-

Build Summary: 1/4 steps succeeded (1 failed)
install transitive failure
└─ install test transitive failure
   └─ compile exe test Debug native 1 errors

error: the following build command failed with exit code 1:
.zig-cache/o/f8b17bc098d58944d4143cab677a593d/build /opt/zig-x86_64-linux-0.16.0-dev.1363+d2b1aa48a/zig /opt/zig-x86_64-linux-0.16.0-dev.1363+d2b1aa48a/lib /home/kmarek/git/zig-systemd-test .zig-cache /home/kmarek/.cache/zig --seed 0x40d7cc4b -Zc19a739fec1e265e

// build.zig
const std = @import("std");

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

    const exe_mod = b.createModule(.{
        .root_source_file = b.path("main.zig"),
        .target = target,
        .sanitize_c = if (optimize == .Debug) .full else .off,
        .optimize = optimize,
        .link_libc = true,
    });

    exe_mod.linkSystemLibrary("systemd", .{ .use_pkg_config = .no });
    exe_mod.addImport("journal", b.addTranslateC(.{
        .root_source_file = b.path("journal.c"),
        .optimize = optimize,
        .target = target,
    }).createModule());

    b.installArtifact(b.addExecutable(.{
        .name = "test",
        .root_module = exe_mod,
    }));
}
// journal.c

#include <systemd/sd-journal.h>
// main.zig
const journal = @import("journal");
pub fn main() !void {
    _ = journal;
}

Expected Behavior

Should have compiled OK (0.15.2 compiles OK)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions