Skip to content

zig cc for OSX: sysroot usage #15098

Open
@motiejus

Description

@motiejus

As per guidance of @kubkon , if MacOS SDK is provided, all headers should come from the sysroot. To avoid issues like #11422. However, it seems like it does not: zig cc will still try to include things in /path/to/zig/lib/libcxx/....

Here is Bazel complaining:

$ bazel build --platforms @zig_sdk//libc_aware/platform:macos_aarch64_sdk.13.1 :which_libc
INFO: Analyzed target //test/c:which_libc (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /code/bazel-zig-cc/test/c/BUILD:3:10: Compiling test/c/main.c failed: undeclared inclusion(s) in rule '//test/c:which_libc':
this rule is missing dependency declarations for the following files included by 'test/c/main.c':
  'external/zig_sdk/lib/libcxx/include/stdio.h'
  'external/zig_sdk/lib/libcxx/include/__config'
<...> 

Rightfully so. If I try to reproduce this with a "hello world" main.c:

$ rm -fr ~/.cache/zig /tmp/bazel-zig-cc; ZIG_VERBOSE_CC=1 ZIG_VERBOSE_LINK=1 /code/zig/build/stage3/bin/zig cc -target aarch64-macos-none --sysroot=$HOME/x/MacOSX13.1.sdk -F/System/Library/Frameworks -c main.c -o main
/code/zig/build/stage3/bin/zig clang main.c -target aarch64-unknown-macosx11.7.1-unknown -nostdinc -fno-spell-checking -isystem /code/zig/build/stage3/lib/zig/include -isystem /code/zig/build/stage3/lib/zig/libc/include/aarch64-macos.11-none -isystem /code/zig/build/stage3/lib/zig/libc/include/any-macos.11-any -isystem /code/zig/build/stage3/lib/zig/libc/include/any-macos-any -Xclang -target-cpu -Xclang generic -Xclang -target-feature -Xclang -a510 -Xclang -target-feature -Xclang -a65 -Xclang -target-feature -Xclang -a710 -Xclang -target-feature -Xclang -a76 -Xclang -target-feature -Xclang -a78 -Xclang -target-feature -Xclang -a78c -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 -arith-bcc-fusion -Xclang -target-feature -Xclang -arith-cbz-fusion -Xclang -target-feature -Xclang -ascend-store-address -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-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 -el2vmsa -Xclang -target-feature -Xclang -el3 -Xclang -target-feature -Xclang +ete -Xclang -target-feature -Xclang -exynos-cheap-as-move -Xclang -target-feature -Xclang -f32mm -Xclang -target-feature -Xclang -f64mm -Xclang -target-feature -Xclang -fgt -Xclang -target-feature -Xclang -fix-cortex-a53-835769 -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-adrp-add -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 -hbc -Xclang -target-feature -Xclang -hcx -Xclang -target-feature -Xclang -i8mm -Xclang -target-feature -Xclang -jsconv -Xclang -target-feature -Xclang -ldapr -Xclang -target-feature -Xclang -lor -Xclang -target-feature -Xclang -ls64 -Xclang -target-feature -Xclang -lse -Xclang -target-feature -Xclang -lse2 -Xclang -target-feature -Xclang -lsl-fast -Xclang -target-feature -Xclang -mops -Xclang -target-feature -Xclang -mpam -Xclang -target-feature -Xclang -mte -Xclang -target-feature -Xclang +neon -Xclang -target-feature -Xclang -no-bti-at-return-twice -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 -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 -use-scalar-inc-vl -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 -v8.8a -Xclang -target-feature -Xclang -v8a -Xclang -target-feature -Xclang -v8r -Xclang -target-feature -Xclang -v9.1a -Xclang -target-feature -Xclang -v9.2a -Xclang -target-feature -Xclang -v9.3a -Xclang -target-feature -Xclang -v9a -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=11.7.1 -Wno-overriding-t-option -fsanitize=undefined -fsanitize-trap=undefined -mred-zone -fno-omit-frame-pointer -fstack-protector-strong --param ssp-buffer-size=4 -D_DEBUG -O0 -fPIC -fno-unwind-tables -gdwarf-4 -MD -MV -MF /home/motiejus/.cache/zig/tmp/63dd55c415acbf6d-main.o.d -c -o /home/motiejus/.cache/zig/tmp/63dd55c415acbf6d-main.o

We can see that it does add -isystem /code/zig/build/stage3/lib/zig/include and others.

Expected result

If --sysroot is specified, all the includes should come from the sysroot, not Zig SDK.

Actual result

Even though --sysroot is specified, some include dirs are in the Zig SDK. If I add -I$sysroot/usr/include to the compiler line, it will append it to the compiler, but not replace it (also as expected).

Metadata

Metadata

Assignees

No one assigned

    Labels

    os-macosquestionNo questions on the issue tracker, please.zig ccZig as a drop-in C compiler feature

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions