You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
when CC environment variable is set to zig and zig cannot provide libc, error: unable to create compilation: UnableToSpawnCCompiler #8960
bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.zig ccZig as a drop-in C compiler feature
To reproduce the issue, pick a system where Zig cannot provide libc, such as FreeBSD (until #2876 is solved) and override the CC environment variable to be Zig.
When trying to link libc, you will get some output like this:
[ 12%] Building C object CMakeFiles/z.dir/compress.o
Zig attempted to find the path to native system libc headers by executing this command:
/home/andrewrk/zig-bootstrap/out/host/bin/zig cc -fno-sanitize=all -target x86_64-native -mcpu=x86_64_v2 -E -Wp,-v -xc /dev/null
error: unable to create compilation: UnableToSpawnCCompiler
Zig attempted to find the path to native system libc headers by executing this command:
/home/andrewrk/zig-bootstrap/out/host/bin/zig cc -fno-sanitize=all -target x86_64-native -mcpu=x86_64_v2 -E -Wp,-v -xc /dev/null
error: unable to create compilation: UnableToSpawnCCompiler
However we can make this work, by detecting when the CC environment variable is set to Zig inside libc_installation.zig, and invoking cc rather than the zig compiler from CC, in order to find the native libc installation paths.
Another bug, which needs to be fixed in order to solve this one, is that Zig does not pick part the CC parameters and separate them by spaces, as is widely supported by systems that recognize the CC environment variable.
Until this is solved, the workaround for this problem is to execute zig libc before overriding the environment variable and save the output somewhere. Then use it in the CLI when overriding CC, like this:
zig libc >~/tmp/libc.txt
export ZIG_LIBC=$HOME/tmp/libc.txt
export CC="zig cc ..."
By utilizing the toolchain idea from #8973, during creation of the toolchain dir:
record native libc information to $TOOLCHAIN_BIN/../lib/libc.txt
upon using a toolchain driver (wrapper), it shall pass --libc $TOOLCHAIN_BIN/../lib/libc.txt to main zig
In the case of zig-bootstrap, #8973 is used to generate a toolchain dir at a folder inside the zig-bootstrap artifact with a relative dir to find zig.exe artifact.
edit: many ways to encode libc.txt kvpairs; it could just be embedded in the wrapper exe and no need for libc.txt
bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.zig ccZig as a drop-in C compiler feature
Activity
mikdusan commentedon Jun 3, 2021
By utilizing the
toolchainidea from #8973, during creation of the toolchain dir:$TOOLCHAIN_BIN/../lib/libc.txt--libc $TOOLCHAIN_BIN/../lib/libc.txtto main zigIn the case of
zig-bootstrap, #8973 is used to generate a toolchain dir at a folder inside thezig-bootstrapartifact with a relative dir to find zig.exe artifact.edit: many ways to encode
libc.txtkvpairs; it could just be embedded in the wrapper exe and no need for libc.txtnative libc detection: respect spaces in CC env var
native libc detection: respect spaces in CC env var
native libc detection: respect spaces in CC env var