Description
When compiling rust-1.41.1 (x.py build
) build fails if zlib.h
is not present in a default location. Typically, pkg-config --cflags zlib
would provide the appropriate location for zlib in case it is not in /usr/include
, however rust does not make use of this. Also, editing config.toml
to add include path in cflags
or cxxflags
under [llvm]
will not solve this issue either.
I could find no documented way to alter cflags that works. During research I stumbled upon rust-lang/cargo#2112 which seems somewhat related, but altering RUSTFLAGS
didn't solve this issue.
I expected to see this happen: Rust compiling successfully.
Instead, this happened: x.py build fails
Meta
python3 ./x.py build --exclude src/tools/miri
:
[...]
running: "cc" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "/build/dev-lang.rust/1.41.1/work/rustc-1.41.1-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/build/libssh2-sys-4164d93400696d60/out/include" "-I" "libssh2/src" "-I" "/build/dev-lang.rust/1.41.1/work/rustc-1.41.1-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/build/libssh2-sys-4164d93400696d60/out/build" "-I" "/pkg/main/dev-libs.openssl.core.1.1.1d/include" "-fvisibility=hidden" "-DHAVE_LONGLONG" "-DHAVE_SNPRINTF" "-DHAVE_UNISTD_H" "-DHAVE_INTTYPES_H" "-DHAVE_STDLIB_H" "-DHAVE_SYS_SELECT_H" "-DHAVE_SYS_SOCKET_H" "-DHAVE_SYS_IOCTL_H" "-DHAVE_SYS_TIME_H" "-DHAVE_SYS_UN_H" "-DHAVE_O_NONBLOCK" "-DLIBSSH2_OPENSSL" "-DHAVE_LIBCRYPT32" "-DHAVE_EVP_AES_128_CTR" "-DLIBSSH2_HAVE_ZLIB" "-o" "/build/dev-lang.rust/1.41.1/work/rustc-1.41.1-src/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/build/libssh2-sys-4164d93400696d60/out/build/libssh2/src/crypt.o" "-c" "libssh2/src/crypt.c"
cargo:warning=libssh2/src/comp.c:41:11: fatal error: zlib.h: No such file or directory
cargo:warning= 41 | # include <zlib.h>
cargo:warning= | ^~~~~~~~
cargo:warning=compilation terminated.
exit code: 1
In this specific context, zlib is not installed in the default path, but pkg-config --cflags zlib
will return the appropriate flags to pass to cc
for a successful build.