Skip to content

darwin libc not available during cImport #11631

@haze

Description

@haze

Zig Version

0.10.0-dev.2122+f161d3875

Steps to Reproduce

 cakewalk % head -n 10 src/main.zig                                                                                                                         ~/code/cakewalk
pub const clang = @cImport({
    @cInclude("clang-c/Index.h");
});

const std = @import("std");
const out = std.log.scoped(.cakewalk);
const ast = @import("ast.zig");
const ClassMethod = @import("Method.zig");

// NOTE(haze): @properties => setters & getters
 cakewalk % cat build.zig                                                                                                                                   ~/code/cakewalk
const std = @import("std");

pub fn build(b: *std.build.Builder) void {
    // Standard target options allows the person running `zig build` to choose
    // what target to build for. Here we do not override the defaults, which
    // means any target is allowed, and the default is native. Other options
    // for restricting supported target set are available.
    const target = b.standardTargetOptions(.{});

    // Standard release options allow the person running `zig build` to select
    // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
    const mode = b.standardReleaseOptions();

    const exe = b.addExecutable("cakewalk", "src/main.zig");
    exe.addIncludePath("/nix/store/hpk7m3zqrlfsmzhhg6yyyqjs6v5bsgfg-clang-14.0.1-dev/include");
    exe.linkSystemLibraryName("clang");
    exe.setTarget(target);
    exe.setBuildMode(mode);
    exe.install();
    exe.linkLibC();

    const run_cmd = exe.run();
    run_cmd.step.dependOn(b.getInstallStep());
    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

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

    const exe_tests = b.addTest("src/main.zig");
    exe_tests.setTarget(target);
    exe_tests.setBuildMode(mode);

    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&exe_tests.step);
}
 cakewalk % zig build --verbose-cc run                                                                                                                      ~/code/cakewalk
warning: Unrecognized C flag from NIX_CFLAGS_COMPILE: -iframework
warning: Unrecognized C flag from NIX_CFLAGS_COMPILE: /nix/store/lfv6d9007cp44ir53akdpgj4369l8j0v-apple-framework-CoreFoundation-11.0.0/Library/Frameworks
warning: Unrecognized C flag from NIX_CFLAGS_COMPILE: -iframework
warning: Unrecognized C flag from NIX_CFLAGS_COMPILE: /nix/store/lfv6d9007cp44ir53akdpgj4369l8j0v-apple-framework-CoreFoundation-11.0.0/Library/Frameworks
 -x c -fno-caret-diagnostics -target aarch64-unknown-macosx-gnu -nostdinc -fno-spell-checking -isystem /Users/haze/Code/zig/lib/include -Xclang -target-cpu -Xclang apple-a14 -Xclang -target-feature -Xclang -a65 -Xclang -target-feature -Xclang -a76 -Xclang -target-feature -Xclang +aes -Xclang -target-feature -Xclang +aggressive-fma -Xclang -target-feature -Xclang +alternate-sextload-cvt-f32-pattern -Xclang -target-feature -Xclang +altnzcv -Xclang -target-feature -Xclang +am -Xclang -target-feature -Xclang -amvs -Xclang -target-feature -Xclang -apple-a12 -Xclang -target-feature -Xclang -apple-a13 -Xclang -target-feature -Xclang -apple-a7 -Xclang -target-feature -Xclang +arith-bcc-fusion -Xclang -target-feature -Xclang +arith-cbz-fusion -Xclang -target-feature -Xclang -balance-fp-ops -Xclang -target-feature -Xclang -bf16 -Xclang -target-feature -Xclang -brbe -Xclang -target-feature -Xclang -bti -Xclang -target-feature -Xclang -call-saved-x10 -Xclang -target-feature -Xclang -call-saved-x11 -Xclang -target-feature -Xclang -call-saved-x12 -Xclang -target-feature -Xclang -call-saved-x13 -Xclang -target-feature -Xclang -call-saved-x14 -Xclang -target-feature -Xclang -call-saved-x15 -Xclang -target-feature -Xclang -call-saved-x18 -Xclang -target-feature -Xclang -call-saved-x8 -Xclang -target-feature -Xclang -call-saved-x9 -Xclang -target-feature -Xclang +ccdp -Xclang -target-feature -Xclang +ccidx -Xclang -target-feature -Xclang +ccpp -Xclang -target-feature -Xclang -cmp-bcc-fusion -Xclang -target-feature -Xclang +complxnum -Xclang -target-feature -Xclang +CONTEXTIDREL2 -Xclang -target-feature -Xclang -cortex-a78c -Xclang -target-feature -Xclang -cortex-r82 -Xclang -target-feature -Xclang +crc -Xclang -target-feature -Xclang +crypto -Xclang -target-feature -Xclang -custom-cheap-as-move -Xclang -target-feature -Xclang +disable-latency-sched-heuristic -Xclang -target-feature -Xclang +dit -Xclang -target-feature -Xclang +dotprod -Xclang -target-feature -Xclang -ecv -Xclang -target-feature -Xclang -ete -Xclang -target-feature -Xclang -exynos-cheap-as-move -Xclang -target-feature -Xclang -exynosm4 -Xclang -target-feature -Xclang -f32mm -Xclang -target-feature -Xclang -f64mm -Xclang -target-feature -Xclang -fgt -Xclang -target-feature -Xclang +flagm -Xclang -target-feature -Xclang -force-32bit-jump-tables -Xclang -target-feature -Xclang +fp16fml -Xclang -target-feature -Xclang +fp-armv8 -Xclang -target-feature -Xclang +fptoint -Xclang -target-feature -Xclang +fullfp16 -Xclang -target-feature -Xclang +fuse-address -Xclang -target-feature -Xclang +fuse-aes -Xclang -target-feature -Xclang +fuse-arith-logic -Xclang -target-feature -Xclang +fuse-crypto-eor -Xclang -target-feature -Xclang +fuse-csel -Xclang -target-feature -Xclang +fuse-literals -Xclang -target-feature -Xclang -harden-sls-blr -Xclang -target-feature -Xclang -harden-sls-nocomdat -Xclang -target-feature -Xclang -harden-sls-retbr -Xclang -target-feature -Xclang -hcx -Xclang -target-feature -Xclang -i8mm -Xclang -target-feature -Xclang +jsconv -Xclang -target-feature -Xclang +lor -Xclang -target-feature -Xclang -ls64 -Xclang -target-feature -Xclang +lse -Xclang -target-feature -Xclang -lsl-fast -Xclang -target-feature -Xclang +mpam -Xclang -target-feature -Xclang -mte -Xclang -target-feature -Xclang +neon -Xclang -target-feature -Xclang -neoversee1 -Xclang -target-feature -Xclang -neoversen1 -Xclang -target-feature -Xclang -neoversen2 -Xclang -target-feature -Xclang -neoversev1 -Xclang -target-feature -Xclang -no-neg-immediates -Xclang -target-feature -Xclang -no-zcz-fp -Xclang -target-feature -Xclang +nv -Xclang -target-feature -Xclang -outline-atomics -Xclang -target-feature -Xclang +pan -Xclang -target-feature -Xclang +pan-rwv -Xclang -target-feature -Xclang +pauth -Xclang -target-feature -Xclang +perfmon -Xclang -target-feature -Xclang +pmu -Xclang -target-feature -Xclang -predictable-select-expensive -Xclang -target-feature -Xclang +predres -Xclang -target-feature -Xclang -rand -Xclang -target-feature -Xclang +ras -Xclang -target-feature -Xclang +rcpc -Xclang -target-feature -Xclang +rcpc-immo -Xclang -target-feature -Xclang +rdm -Xclang -target-feature -Xclang -reserve-x1 -Xclang -target-feature -Xclang -reserve-x10 -Xclang -target-feature -Xclang -reserve-x11 -Xclang -target-feature -Xclang -reserve-x12 -Xclang -target-feature -Xclang -reserve-x13 -Xclang -target-feature -Xclang -reserve-x14 -Xclang -target-feature -Xclang -reserve-x15 -Xclang -target-feature -Xclang -reserve-x18 -Xclang -target-feature -Xclang -reserve-x2 -Xclang -target-feature -Xclang -reserve-x20 -Xclang -target-feature -Xclang -reserve-x21 -Xclang -target-feature -Xclang -reserve-x22 -Xclang -target-feature -Xclang -reserve-x23 -Xclang -target-feature -Xclang -reserve-x24 -Xclang -target-feature -Xclang -reserve-x25 -Xclang -target-feature -Xclang -reserve-x26 -Xclang -target-feature -Xclang -reserve-x27 -Xclang -target-feature -Xclang -reserve-x28 -Xclang -target-feature -Xclang -reserve-x3 -Xclang -target-feature -Xclang -reserve-x30 -Xclang -target-feature -Xclang -reserve-x4 -Xclang -target-feature -Xclang -reserve-x5 -Xclang -target-feature -Xclang -reserve-x6 -Xclang -target-feature -Xclang -reserve-x7 -Xclang -target-feature -Xclang -reserve-x9 -Xclang -target-feature -Xclang -rme -Xclang -target-feature -Xclang +sb -Xclang -target-feature -Xclang +sel2 -Xclang -target-feature -Xclang +sha2 -Xclang -target-feature -Xclang +sha3 -Xclang -target-feature -Xclang -slow-misaligned-128store -Xclang -target-feature -Xclang -slow-paired-128 -Xclang -target-feature -Xclang -slow-strqro-store -Xclang -target-feature -Xclang -sm4 -Xclang -target-feature -Xclang -sme -Xclang -target-feature -Xclang -sme-f64 -Xclang -target-feature -Xclang -sme-i64 -Xclang -target-feature -Xclang -spe -Xclang -target-feature -Xclang -spe-eef -Xclang -target-feature -Xclang +specrestrict -Xclang -target-feature -Xclang +ssbs -Xclang -target-feature -Xclang -strict-align -Xclang -target-feature -Xclang -sve -Xclang -target-feature -Xclang -sve2 -Xclang -target-feature -Xclang -sve2-aes -Xclang -target-feature -Xclang -sve2-bitperm -Xclang -target-feature -Xclang -sve2-sha3 -Xclang -target-feature -Xclang -sve2-sm4 -Xclang -target-feature -Xclang -tagged-globals -Xclang -target-feature -Xclang +tlb-rmi -Xclang -target-feature -Xclang -tme -Xclang -target-feature -Xclang -tpidr-el1 -Xclang -target-feature -Xclang -tpidr-el2 -Xclang -target-feature -Xclang -tpidr-el3 -Xclang -target-feature -Xclang +tracev8.4 -Xclang -target-feature -Xclang -trbe -Xclang -target-feature -Xclang +uaops -Xclang -target-feature -Xclang -use-experimental-zeroing-pseudos -Xclang -target-feature -Xclang -use-postra-scheduler -Xclang -target-feature -Xclang -use-reciprocal-square-root -Xclang -target-feature -Xclang +v8.1a -Xclang -target-feature -Xclang +v8.2a -Xclang -target-feature -Xclang +v8.3a -Xclang -target-feature -Xclang +v8.4a -Xclang -target-feature -Xclang -v8.5a -Xclang -target-feature -Xclang -v8.6a -Xclang -target-feature -Xclang -v8.7a -Xclang -target-feature -Xclang -v8r -Xclang -target-feature -Xclang +vh -Xclang -target-feature -Xclang -wfxt -Xclang -target-feature -Xclang -xs -Xclang -target-feature -Xclang +zcm -Xclang -target-feature -Xclang +zcz -Xclang -target-feature -Xclang -zcz-fp-workaround -Xclang -target-feature -Xclang +zcz-gp -mmacos-version-min=12.3.1 -g -fsanitize=undefined -fsanitize-trap=undefined -mred-zone -fno-omit-frame-pointer -D_DEBUG -Og -fstack-protector-strong --param ssp-buffer-size=4 -fPIC -fno-unwind-tables -MD -MV -MF /Users/haze/Code/cakewalk/zig-cache/o/5631d7c3def33ffdb9b4f1857468d0c0/cimport.h.d -I /nix/store/hpk7m3zqrlfsmzhhg6yyyqjs6v5bsgfg-clang-14.0.1-dev/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -iwithsysroot /nix/store/hpk7m3zqrlfsmzhhg6yyyqjs6v5bsgfg-clang-14.0.1-dev/include -iwithsysroot /nix/store/wlp2bii0r52zh2p7bkp84v0jwqj22ya9-libcxx-11.1.0-dev/include -iwithsysroot /nix/store/4y75qfpvq1mxifm2i4c6k52a3a9rc3hw-libcxxabi-11.1.0-dev/include -iwithsysroot /nix/store/grc1xfrcl512j1qrn8cdjd1gyaxhq6ca-libobjc-11.0.0/include -iwithsysroot /nix/store/hpk7m3zqrlfsmzhhg6yyyqjs6v5bsgfg-clang-14.0.1-dev/include -iwithsysroot /nix/store/wlp2bii0r52zh2p7bkp84v0jwqj22ya9-libcxx-11.1.0-dev/include -iwithsysroot /nix/store/4y75qfpvq1mxifm2i4c6k52a3a9rc3hw-libcxxabi-11.1.0-dev/include -iwithsysroot /nix/store/grc1xfrcl512j1qrn8cdjd1gyaxhq6ca-libobjc-11.0.0/include -Xclang -detailed-preprocessing-record /Users/haze/Code/cakewalk/zig-cache/o/5631d7c3def33ffdb9b4f1857468d0c0/cimport.h
./src/main.zig:1:19: error: C import failed
pub const clang = @cImport({
                  ^
/nix/store/hpk7m3zqrlfsmzhhg6yyyqjs6v5bsgfg-clang-14.0.1-dev/include/clang-c/Index.h:19:10: note: 'time.h' file not found
#include <time.h>
         ^
cakewalk...The following command exited with error code 1:
/Users/haze/Code/zig/_build.macos-arm64/zig build-exe /Users/haze/Code/cakewalk/src/main.zig -lclang -lc --verbose-cc --cache-dir /Users/haze/Code/cakewalk/zig-cache --global-cache-dir /Users/haze/.cache/zig --name cakewalk -I /nix/store/hpk7m3zqrlfsmzhhg6yyyqjs6v5bsgfg-clang-14.0.1-dev/include --enable-cache 
error: the following build command failed with exit code 1:
/Users/haze/Code/cakewalk/zig-cache/o/af98af65172951b69cc60fe1d520576a/build /Users/haze/Code/zig/_build.macos-arm64/zig /Users/haze/Code/cakewalk /Users/haze/Code/cakewalk/zig-cache /Users/haze/.cache/zig --verbose-cc run

basically, have a project that depends on a c library (in my case, libclang) and attempt to cImport/cInclude a header from that project

(in my case for nix, zig can't find the header I'm including, even though verbose-cc knows about it)
if I manually add the include path to the build.zig, I then see the error that time.h cannot be found

Expected Behavior

A successful compilation

Actual Behavior

An error complaining that time.h is not found

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.os-macosmacOS

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions