conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
7.95k stars 951 forks source link

[question] Conan + Meson + sysroot issue #16468

Open donlk opened 2 weeks ago

donlk commented 2 weeks ago

What is your question?

Hi! I'm trying to build Qt with a prebuilt GCC compiler, having an external sysroot containing libc and relevant libraries (pthread, libm, libdl, etc), meaning that the toolchain itself does not have these libraries inside.

So I defined a toolchain profile with a sysroot:

...
[buildenv]
PATH=+(path){{toolchain_path}}/bin
LD_LIBRARY_PATH=+(path){{toolchain_path}}/lib
C_INCLUDE_PATH=+(path){{sysroot}}/usr/include
CC={{toolchain_path}}/bin/{{cc_compiler}}
CXX={{toolchain_path}}/bin/{{cxx_compiler}}
LD={{toolchain_path}}/bin/ld
AR={{toolchain_path}}/bin/ar
AS={{toolchain_path}}/bin/as
NM={{toolchain_path}}/bin/nm
RANLIB={{toolchain_path}}/bin/ranlib
STRIP={{toolchain_path}}/bin/strip
LDFLAGS=-Wl,-rpath-link {{sysroot}}/lib

[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=9
os=Linux

[conf]
tools.build:sysroot={{sysroot}}
tools.build:sharedlinkflags=["-Wl,-rpath-link {{sysroot}}/lib"]

So far every dependency built successfully, except freetype:

[2/4] Compiling C object libfreetype.a.p/src_bzip2_ftbzip2.c.o
FAILED: libfreetype.a.p/src_bzip2_ftbzip2.c.o
<toolchain_path>/gcc-9.3.0-x86_64/bin/gcc -Ilibfreetype.a.p -I. -I../src -I../src/include -I<sysroot_path>/<home>/conan/home/p/b/zlib337c8139e577f/p/include
...
 -MD -MQ libfreetype.a.p/src_bzip2_ftbzip2.c.o -MF libfreetype.a.p/src_bzip2_ftbzip2.c.o.d -o libfreetype.a.p/src_bzip2_ftbzip2.c.o -c ../src/src/bzip2/ftbzip2.c
../src/src/bzip2/ftbzip2.c:46:10: fatal error: bzlib.h: No such file or directory

The problem is this line (replaced the hard-coded paths with a reference):

-I<sysroot_path>/<home>/conan/home/p/b/zlib337c8139e577f/p/include

The sysroot path is directly prepended to all dependent includes, zlib included, making the zlib header lookup messed up. I've done some research and found a relevant official meson issue. It says:

Now the issues is, that pkgconf PREFIXES every path in the *.pc files inside dependencies with the sysroot defined in sys_root. However the paths defined pc files in the folder dependencies MUST not be prefixed. Else the #include and linking will fail.

Here's the pc file for zlib: build-release/conan/zlib.pc:

prefix=<home>/conan/home/p/b/zlib337c8139e577f/p
libdir=${prefix}/lib
includedir=${prefix}/include
bindir=${prefix}/bin

Name: zlib
Description: Conan package: zlib
Version: 1.3.1
Libs: -L"${libdir}" -lz
Cflags: -I"${includedir}"

I've tried nullifying the PKG_CONFIG_SYSROOT_DIR variable via [buildenv] in my profile to force pkgconfig to disregard it, to no avail. Any ideas? This is a very basic cross-compile issue for conan -> meson, it should be straightforward.

Have you read the CONTRIBUTING guide?

donlk commented 2 weeks ago

Another relvevant issue: https://github.com/pkgconf/pkgconf/issues/213

franramirez688 commented 2 weeks ago

Hi @donlk

Thanks a lot for reporting this! Yes, you're completely right. A way to work around this could be:

$ conan [YOUR COMMAND] -c "tools.meson.mesontoolchain:extra_machine_files=['/path/to/file/sys_root_empty.ini']"

Where that sys_root_empty.ini looks like:

[properties]
sys_root = ''

Let me know if it worked or if we need to look into it more.