conan icon indicating copy to clipboard operation
conan copied to clipboard

[question] Conan + Meson + sysroot issue

Open donlk opened this issue 1 year ago • 27 comments

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?

  • [x] I've read the CONTRIBUTING guide

donlk avatar Jun 12 '24 13:06 donlk

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

donlk avatar Jun 12 '24 16:06 donlk

Hi @donlk

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

  • Add an extra machine file to override the sys_root Meson property:
$ 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.

franramirez688 avatar Jun 18 '24 11:06 franramirez688

Works perfectly. Thank you!

donlk avatar Jul 04 '24 14:07 donlk

That's great! 👏

franramirez688 avatar Jul 04 '24 20:07 franramirez688

@franramirez688 While this solution works for Conan packages built with conan create, projects developed using conan install will need to manually add the extra flag to add this ini file as part of the configure step, which is unfortunate.

Both of the linked issues in this thread are relevant, but closed. I think we should try to make sure that Meson and pkgconf are still aware that this is a problem and track open related upstream issues to be sure it gets fixed.

jwillikers avatar Jul 16 '24 15:07 jwillikers

For future reference, here's how I removed the sys_root line from the cross file in the generate method.

    def generate(self):
        # Remove the troublesome sys_root parameter from the Meson cross file.
        # It causes pkgconf to prepend the sysroot to the absolute path to the package in the Conan cache.
        if cross_building(self):
            with open(os.path.join(self.generators_folder, "conan_meson_cross.ini"), "r") as f:
                lines = f.readlines()
            with open(os.path.join(self.generators_folder, "conan_meson_cross.ini"), "w") as f:
                for line in lines:
                    if "sys_root = '" not in line:
                        f.write(line)

jwillikers avatar Jul 16 '24 16:07 jwillikers

projects developed using conan install will need to manually add the extra flag to add this ini file as part of the configure step, which is unfortunate.

That is weird, conan install accepts profile and config attributes as well, in theory it should work, right? Either via -c or in the profile itself. Either of these failed?

donlk avatar Jul 16 '24 16:07 donlk

@jwillikers I don't get what you mean. So, why is it not working using the conan install? Could you show me an example?

franramirez688 avatar Jul 19 '24 15:07 franramirez688

conan create run's the Meson configure step, where it adds the extra --cross-file parameter automatically, i.e. meson setup build-debug --cross-file build-debug/conan/conan_meson_cross.ini --cross-file ~/.conan2/toolchains/sys_root_empty.ini.

That's all good and dandy, until you are developing a Meson project locally. Developers use conan install followed by the meson commands to configure and build the project. When cross-compiling such a project, developers now have to go from running meson setup build-debug --cross-file build-debug/conan/conan_meson_cross.ini to instead running meson setup build-debug --cross-file build-debug/conan/conan_meson_cross.ini --cross-file ~/.conan2/toolchains/sys_root_empty.ini, which is not convenient.

Also, for reference, I found PR pkgconf/pkgconf#280 that appears to address this issue and is still open at this time.

jwillikers avatar Jul 19 '24 18:07 jwillikers

A way to work around this could be:

* Add an extra machine file to override the `sys_root` Meson property:
$ 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.

This doesn't work (anymore) for me. Not even when I add the following line to the recipe of the cross-compiled package (fontconfig in my case):

tc.properties["sys_root"] = ""

With this line the sys_root property in the generated cross-file becomes empty but still the sys-root is prepended to all include paths:

freetype/2.13.2: Meson configure cmd: meson setup --cross-file "/home/wdobbe/.conan2/p/b/freet6b9a8b9ee6f3a/b/build-release/conan/conan_meson_cross.ini" --cross-file "/home/wdobbe/.conan2/meson_sys_root_empty.ini" "/home/wdobbe/.conan2/p/b/freet6b9a8b9ee6f3a/b/build-release" "/home/wdobbe/.conan2/p/b/freet6b9a8b9ee6f3a/b/src" --prefix=/
freetype/2.13.2: RUN: meson setup --cross-file "/home/wdobbe/.conan2/p/b/freet6b9a8b9ee6f3a/b/build-release/conan/conan_meson_cross.ini" --cross-file "/home/wdobbe/.conan2/meson_sys_root_empty.ini" "/home/wdobbe/.conan2/p/b/freet6b9a8b9ee6f3a/b/build-release" "/home/wdobbe/.conan2/p/b/freet6b9a8b9ee6f3a/b/src" --prefix=/
WARNING: Unknown CPU family cortexa9hf-neon, please report this at https://github.com/mesonbuild/meson/issues/new
The Meson build system
Version: 1.3.2
Source dir: /home/wdobbe/.conan2/p/b/freet6b9a8b9ee6f3a/b/src
Build dir: /home/wdobbe/.conan2/p/b/freet6b9a8b9ee6f3a/b/build-release
Build type: cross build
Project name: freetype2
Project version: 2.13.2
C compiler for the host machine: arm-poky-linux-gnueabi-gcc (gcc 9.2.0 "arm-poky-linux-gnueabi-gcc (GCC) 9.2.0")
C linker for the host machine: arm-poky-linux-gnueabi-gcc ld.bfd 2.32.0.20190204
C compiler for the build machine: cc (gcc 7.5.0 "cc (SUSE Linux) 7.5.0")
C linker for the build machine: cc ld.bfd 2.41.0.20230908-150100
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: cortexa9hf-neon
Host machine cpu: cortexa9hf-neon
Target machine cpu family: cortexa9hf-neon
Target machine cpu: cortexa9hf-neon
Program python3 found: YES (/usr/local/python39env/bin/python3)
Has header "unistd.h" : YES 
Has header "fcntl.h" : YES 
Has header "sys/mman.h" : YES 
Found pkg-config: YES (/home/wdobbe/.conan2/p/b/pkgco6b2707c42a451/p/bin/pkgconf) 2.1.0
Run-time dependency zlib found: YES 1.2.13
Run-time dependency bzip2 found: YES 1.0.8
Run-time dependency libpng found: YES 1.6.42
Dependency harfbuzz skipped: feature harfbuzz disabled
Run-time dependency libbrotlidec found: YES 1.1.0
Build targets in project: 5

freetype2 2.13.2

  Operating System
    OS         : linux

  Used Libraries
    Zlib       : system
    Bzip2      : yes
    Png        : yes
    Harfbuzz   : no
    Brotli     : yes

  User defined options
    Cross files: /home/wdobbe/.conan2/p/b/freet6b9a8b9ee6f3a/b/build-release/conan/conan_meson_cross.ini
                 /home/wdobbe/.conan2/meson_sys_root_empty.ini
    prefix     : /

Found ninja-1.12.1 at /home/wdobbe/.conan2/p/b/ninjabf76fb6402bba/p/bin/ninja
                                                                                                                                                                                                                  
freetype/2.13.2: Meson build cmd: meson compile -C "/home/wdobbe/.conan2/p/b/freet6b9a8b9ee6f3a/b/build-release" -j64
freetype/2.13.2: RUN: meson compile -C "/home/wdobbe/.conan2/p/b/freet6b9a8b9ee6f3a/b/build-release" -j64
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /home/wdobbe/.conan2/p/b/ninjabf76fb6402bba/p/bin/ninja -j 64
[18/46] Compiling C object libfreetype.a.p/src_sfnt_sfnt.c.o
FAILED: libfreetype.a.p/src_sfnt_sfnt.c.o 
arm-poky-linux-gnueabi-gcc -Ilibfreetype.a.p -I. -I../src -I../src/include -I/home/wdobbe/.conan2/p/b/swpt_fb08c05e04578/p/sysroots/cortexa9hf-neon-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/zlib7dbebab8830af/p/include -I/home/wdobbe/.conan2/p/b/swpt_fb08c05e04578/p/sysroots/cortexa9hf-neon-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/bzip2e92281329ac89/p/include -I/home/wdobbe/.conan2/p/b/swpt_fb08c05e04578/p/sysroots/cortexa9hf-neon-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/libpne0671a1ce0e00/p/include -I/home/wdobbe/.conan2/p/b/swpt_fb08c05e04578/p/sysroots/cortexa9hf-neon-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/brotl76641bb1988e1/p/include -I/home/wdobbe/.conan2/p/b/swpt_fb08c05e04578/p/sysroots/cortexa9hf-neon-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/brotl76641bb1988e1/p/include/brotli -fvisibility=hidden -fdiagnostics-color=always -DNDEBUG -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O3 -marm -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -fstack-protector-strong -Wformat -Wformat-security -Werror=format-security --sysroot=/home/wdobbe/.conan2/p/b/swpt_fb08c05e04578/p/sysroots/cortexa9hf-neon-poky-linux-gnueabi -O2 -pipe -feliminate-unused-debug-types -marm -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/home/wdobbe/.conan2/p/b/swpt_fb08c05e04578/p/sysroots/cortexa9hf-neon-poky-linux-gnueabi -O2 -feliminate-unused-debug-types --sysroot=/home/wdobbe/.conan2/p/b/swpt_fb08c05e04578/p/sysroots/cortexa9hf-neon-poky-linux-gnueabi -fPIC '-DFT_CONFIG_MODULES_H=<ftmodule.h>' -DFT2_BUILD_LIBRARY=1 '-DFT_CONFIG_OPTIONS_H=<ftoption.h>' '-DFT_CONFIG_CONFIG_H=<ftconfig.h>' -MD -MQ libfreetype.a.p/src_sfnt_sfnt.c.o -MF libfreetype.a.p/src_sfnt_sfnt.c.o.d -o libfreetype.a.p/src_sfnt_sfnt.c.o -c ../src/src/sfnt/sfnt.c
In file included from ../src/src/sfnt/sfnt.c:25:
../src/src/sfnt/sfwoff2.c:27:10: fatal error: brotli/decode.h: No such file or directory
   27 | #include <brotli/decode.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
[45/46] Compiling C object libfreetype.a.p/src_truetype_truetype.c.o
ninja: build stopped: subcommand failed.

freetype/2.13.2: ERROR: 
Package 'a801309751333469de9145f28887e6fc7fe500a8' build failed
freetype/2.13.2: WARN: Build folder /home/wdobbe/.conan2/p/b/freet6b9a8b9ee6f3a/b/build-release
ERROR: freetype/2.13.2: Error in build() method, line 114
        meson.build()
        ConanException: Error 1 while executing

wdobbe avatar Sep 12 '24 17:09 wdobbe

Hi @wdobbe

Thanks for the feedback.

Could you please clarify if this is a regression, it worked in previous Conan 2.6 and now in 2.7 is broken? It would be worth to create a new ticket with the details to reproduce

memsharded avatar Sep 12 '24 17:09 memsharded

Hi @memsharded

While trying to add cross-compile support for the Qt6 CCI recipe I ran into the same problem as reported in this issue: for all dependencies that use meson as build system the sys-root path is prepended to the include path. So -I/home/wdobbe/.conan2/p/b/zlib134522c449e8d/p/include becomes -I/home/wdobbe/.conan2/p/b/swpt_fb08c05e04578/p/sysroots/cortexa9hf-neon-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/zlib134522c449e8d/p/include

This is not a regression of Conan, it also happens with for example Conan 2.4. From the discussion above it seems to be a pkgconf problem.

What is a kind of 'regression' is that the workaround suggested above (add an extra meson machine file to override the sys_root property) does not work anymore.

So currently I am stuck trying to cross-compile for example freetype that is a dependency for Qt6. I am now trying to debug Meson to see if I can find another workaround but I am not very familiar with Meson.

I might create a new issue for this later.

wdobbe avatar Sep 13 '24 11:09 wdobbe

What is a kind of 'regression' is that the workaround suggested above (add an extra meson machine file to override the sys_root property) does not work anymore.

If you file a new ticket, it would be useful to know in which previous version this was working and when it stopped working. Thanks!

memsharded avatar Sep 13 '24 13:09 memsharded

If anyone encounters the same problem: cause was that the toolchain I used exported environment variable PKG_CONFIG_SYSROOT_DIR. This causes pkg-config to prepend the sys-root path to any include path. After removing the PKG_CONFIG_SYSROOT_DIR from the toolchain problem disappeared.

wdobbe avatar Sep 16 '24 17:09 wdobbe

if anyone has this issue and this can help you: I had the same isse when, based on the doc example of "Creating a Conan package for a toolchain", I needed to create in my case an armv4t toolchain that requires set the tools.build:sysroot path. When trying to compile FreeType 2.13 which uses Meson it failed with the described issue of concatenation of sysroot in each include path of dependencies. My approach to fix that was implement the workaround in the arm-toolchain recipe:

    def package_info(self):
        toolchain, _ = self._get_toolchain(self.settings_target.arch)
        toolchain_path = os.path.join(self.package_folder, toolchain)

        self.cpp_info.bindirs.append(os.path.join(toolchain_path, "bin"))

        sysroot = os.path.join(toolchain_path, "sysroot")
        self.conf_info.define("tools.build:sysroot", sysroot)

        self.conf_info.define("tools.build:compiler_executables", {
            "c":   f"{toolchain}-gcc",
            "cpp": f"{toolchain}-g++",
            "asm": f"{toolchain}-as"
        })

        sys_root_path = os.path.join(self.package_folder, "sys_root_empty.ini")
        with open(sys_root_path, "w") as f:
            f.write("[properties]\n")
            f.write("sys_root = ''\n")
        self.conf_info.define("tools.meson.mesontoolchain:extra_machine_files", [sys_root_path])

However, since we are creating a file that will be consumed by Meson, probably we should create this file during the generate() method instead of package_info().

I'm leaving this note here as an idea in case it helps anyone else.

amachado-pie avatar Mar 26 '25 22:03 amachado-pie

I had the same issue when compiling glib/2.78.3 from the conan center with our custom arm toolchain. The above fix using tools.meson.mesontoolchain:extra_machine_files works fine. @memsharded, since you asked above, the issue started with conan 2.4.0. It didn't happen with 2.3.2.

JKniep avatar May 23 '25 09:05 JKniep

This has been re-closed by https://github.com/conan-io/conan/pull/19229, that removes the sysroot as Meson property, and leaves it as a flag only, it will be in next 2.23

memsharded avatar Nov 17 '25 16:11 memsharded

Hi @memsharded , I applied the fix from PR #19229 in my local conan 2.22.2 installation (file conan/tools/meson/toolchain.py). However cross-compilation of for example freetype still fails because the toolchain sysroot path is included before every include path, see log below. Meson version I use is 1.9.1.

Is there more I should change to get packages that use meson working again?

-------- Installing package freetype/2.13.2 (60 of 79) --------
freetype/2.13.2: Building from source
freetype/2.13.2: Package freetype/2.13.2:58c1e99bd1c5931b9624c02ded74be43a6853c65
freetype/2.13.2: settings: os=Linux os.distro=Yocto arch=armv5 compiler=gcc compiler.version=11 build_type=Release
freetype/2.13.2: options: fPIC=True shared=False subpixel=False with_brotli=True with_bzip2=True with_png=True with_zlib=True
freetype/2.13.2: requires: libpng/1.6.Z zlib/1.2.Z bzip2/1.0.Z brotli/1.1.Z
freetype/2.13.2: Copying sources to build folder
freetype/2.13.2: Building your package in /home/wdobbe/.conan2/p/b/freeta55865912f2e5/b
freetype/2.13.2: Calling generate()
freetype/2.13.2: Generators folder: /home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/build-release/conan
freetype/2.13.2: MesonToolchain generated: conan_meson_cross.ini
freetype/2.13.2: Generating aggregated env files
freetype/2.13.2: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
freetype/2.13.2: Calling build()
freetype/2.13.2: Apply patch (portability): meson: Use the standard dependency mechanism to find bzip2
freetype/2.13.2: Apply patch (portability): meson: define DLL_EXPORT for shared library only
freetype/2.13.2: Meson configure cmd: meson setup --cross-file "/home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/build-release/conan/conan_meson_cross.ini" --cross-file "/home/wdobbe/.conan2/meson_sys_root_empty.ini" "/home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/build-release" "/home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/src" --prefix=/
freetype/2.13.2: RUN: meson setup --cross-file "/home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/build-release/conan/conan_meson_cross.ini" --cross-file "/home/wdobbe/.conan2/meson_sys_root_empty.ini" "/home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/build-release" "/home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/src" --prefix=/
WARNING: Unknown CPU family armv5, please report this at https://github.com/mesonbuild/meson/issues/new
The Meson build system
Version: 1.9.1
Source dir: /home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/src
Build dir: /home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/build-release
Build type: cross build
Project name: freetype2
Project version: 2.13.2
C compiler for the host machine: arm-poky-linux-gnueabi-gcc (gcc 11.4.0 "arm-poky-linux-gnueabi-gcc (GCC) 11.4.0")
C linker for the host machine: arm-poky-linux-gnueabi-gcc ld.bfd 2.38.20220708
C compiler for the build machine: ccache cc (gcc 15.1.1 "cc (SUSE Linux) 15.1.1 20250714")
C linker for the build machine: cc ld.bfd 2.43.1.20241209-160000
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: armv5
Host machine cpu: armv5
Target machine cpu family: armv5
Target machine cpu: armv5
Program python3 found: YES (/usr/bin/python3)
Has header "unistd.h" : YES 
Has header "fcntl.h" : YES 
Has header "sys/mman.h" : YES 
Found pkg-config: YES (/home/wdobbe/.conan2/p/b/pkgcoa56beaf11eae8/p/bin/pkgconf) 2.2.0
Run-time dependency zlib found: YES 1.2.13
Run-time dependency bzip2 found: YES 1.0.8
Run-time dependency libpng found: YES 1.6.48
Dependency harfbuzz skipped: feature harfbuzz disabled
Run-time dependency libbrotlidec found: YES 1.1.0
Build targets in project: 5

freetype2 2.13.2

  Operating System
    OS         : linux

  Used Libraries
    Zlib       : system
    Bzip2      : yes
    Png        : yes
    Harfbuzz   : no
    Brotli     : yes

  User defined options
    Cross files: /home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/build-release/conan/conan_meson_cross.ini
                 /home/wdobbe/.conan2/meson_sys_root_empty.ini
    prefix     : /

Found ninja-1.12.1 at /home/wdobbe/.conan2/p/b/ninja66613adddac1d/p/bin/ninja

freetype/2.13.2: Meson build cmd: meson compile -C "/home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/build-release" -j12
freetype/2.13.2: RUN: meson compile -C "/home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/build-release" -j12
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /home/wdobbe/.conan2/p/b/ninja66613adddac1d/p/bin/ninja -j 12
[4/46] Compiling C object libfreetype.a.p/src_sfnt_sfnt.c.o
FAILED: libfreetype.a.p/src_sfnt_sfnt.c.o 
arm-poky-linux-gnueabi-gcc -Ilibfreetype.a.p -I. -I../src -I../src/include -I/home/wdobbe/.conan2/p/b/swpt_cc1009408cc25/p/sysroots/armv5e-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/zlibc91ce6c5cb5de/p/include -I/home/wdobbe/.conan2/p/b/swpt_cc1009408cc25/p/sysroots/armv5e-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/bzip2b48278f578efd/p/include -I/home/wdobbe/.conan2/p/b/swpt_cc1009408cc25/p/sysroots/armv5e-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/libpn9857dc4c0176e/p/include -I/home/wdobbe/.conan2/p/b/swpt_cc1009408cc25/p/sysroots/armv5e-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/brotla4db9ad20478a/p/include -fvisibility=hidden -fdiagnostics-color=always -DNDEBUG -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O3 -march=armv5te -marm -fstack-protector-strong -O2 -Wformat -Wformat-security -Werror=format-security --sysroot=/home/wdobbe/.conan2/p/b/swpt_cc1009408cc25/p/sysroots/armv5e-poky-linux-gnueabi -O2 -pipe -g -feliminate-unused-debug-types -march=armv5te -marm -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/home/wdobbe/.conan2/p/b/swpt_cc1009408cc25/p/sysroots/armv5e-poky-linux-gnueabi -O2 -g -feliminate-unused-debug-types --sysroot=/home/wdobbe/.conan2/p/b/swpt_cc1009408cc25/p/sysroots/armv5e-poky-linux-gnueabi -fPIC '-DFT_CONFIG_MODULES_H=<ftmodule.h>' -DFT2_BUILD_LIBRARY=1 '-DFT_CONFIG_OPTIONS_H=<ftoption.h>' '-DFT_CONFIG_CONFIG_H=<ftconfig.h>' -MD -MQ libfreetype.a.p/src_sfnt_sfnt.c.o -MF libfreetype.a.p/src_sfnt_sfnt.c.o.d -o libfreetype.a.p/src_sfnt_sfnt.c.o -c ../src/src/sfnt/sfnt.c
In file included from ../src/src/sfnt/sfnt.c:21:
../src/src/sfnt/pngshim.c:31:10: fatal error: png.h: No such file or directory
   31 | #include <png.h>
      |          ^~~~~~~
compilation terminated.
[15/46] Compiling C object libfreetype.a.p/src_truetype_truetype.c.o
ninja: build stopped: subcommand failed.

freetype/2.13.2: ERROR: 
Package '58c1e99bd1c5931b9624c02ded74be43a6853c65' build failed
freetype/2.13.2: WARN: Build folder /home/wdobbe/.conan2/p/b/freeta55865912f2e5/b/build-release
ERROR: freetype/2.13.2: Error in build() method, line 113
        meson.build()
        ConanException: Error 1 while executing

wdobbe avatar Nov 19 '25 12:11 wdobbe

PS: I also had to patch the libselinux conan recipe because file libselinux-3.6/Makefile does: PCRE_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(PCRE_MODULE))

which results in: -I/home/wdobbe/.conan2/p/b/swpt_cc1009408cc25/p/sysroots/armv5e-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/pcre2ef98e3884232e/p/include -DPCRE2_STATIC -I/home/wdobbe/.conan2/p/b/swpt_cc1009408cc25/p/sysroots/armv5e-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/zlibc91ce6c5cb5de/p/include -I/home/wdobbe/.conan2/p/b/swpt_cc1009408cc25/p/sysroots/armv5e-poky-linux-gnueabi/home/wdobbe/.conan2/p/b/bzip2b48278f578efd/p/include

Issue #15795 seems to report this already.

wdobbe avatar Nov 19 '25 20:11 wdobbe

In order to cross-compile all dependencies for qt/6.7.3 I had to patch the following Conan recipes:

  • freetype
  • fontconfig
  • glib
  • harfbuzz
  • libselinux

For the packages that are built with Meson I run (as a temporary fix) a sed command to correct the include and link paths after the Meson configure step:

def build(self):
        self._patch_sources()
        meson = Meson(self)
        meson.configure()
        if cross_building(self) and not os.path.exists(os.path.join(self.build_folder, "original")):
            mkdir(self, os.path.join(self.build_folder, "original"))
            copy(self, pattern="build.ninja", dst=os.path.join(self.build_folder, "original"), src=self.build_folder)
            self.run(command="sed -i -e 's#-\([IL]\)/home/[^ ]\+\(/home/[^ ]\+\)[[:space:]]#-\\1\\2 #g' build.ninja", cwd=self.build_folder, scope="build")
        meson.build()

Wouldn't it be better to fix the root of the problem in pkgconfig, if necessary with a code patch?

wdobbe avatar Nov 20 '25 13:11 wdobbe

If you set environment variable PKG_CONFIG_FDO_SYSROOT_RULES=1 before invoking pkgconf it seems to return the correct path regardless whether PKG_CONFIG_SYSROOT_DIR is set or not. Next week I'll try if setting that variable somewhere in the Conan Meson files will fix the above problems.

wdobbe avatar Nov 20 '25 19:11 wdobbe

I'm continuing to see issues cross compiling with Meson. What I expect to happen is:

  1. Meson looks for locally installed conan packages first (ie *.pc files in the generators folder)
  2. If 1. fails, look for packages in the supplied sysroot.

However I cannot find a combination of flags that allows this. What I'm seeing is:

Conan 2.22.2 default behaviour (sys_root is set in the conan_meson_cross.ini) file

Compilation fails due to the generators path being appended to the sysroot (as noted in @jcar87 in https://github.com/conan-io/conan/pull/19229#issuecomment-3541140060)

With the machine file workaround (or just removing the sys_root property)

Meson setup fails because it no longer looks in the supplied sysroot

Setting sys_root and pkg_config_libdir (As suggested in https://github.com/mesonbuild/meson/issues/7799)

Same as Conan 2.22.2 default

Clearing sys_root and setting pkg_config_libdir to list of pkgconfig paths

pkgconf finds system libs resulting in linking/architecture mismatch (as per https://github.com/mesonbuild/meson/issues/7799)

Using neither sys_root or pkg_config_libdir and specifiying both paths in pkg_config_path

As above.

I'm at a bit of a loss.

For reference, I'm trying to build Weston

planetmarshall avatar Nov 21 '25 00:11 planetmarshall

Using neither sys_root or pkg_config_libdir and specifiying both paths in pkg_config_path

Having said that - I think this is the closest to the behaviour I would expect, at least according to the logs:

env[PKG_CONFIG_PATH]: /home/andrew/projects/weston/conan:/home/andrew/projects/armv7-clang-llvmorg-21.1.4-linux/sysroots/armv7at2hf-neon-rdk-linux-gnueabi/usr/lib/pkgconfig
env[PKG_CONFIG]: /home/andrew/.conan2/p/pkgcoa6060d80b51cc/p/bin/pkgconf
-----------
Called: `/home/andrew/.conan2/p/pkgcoa6060d80b51cc/p/bin/pkgconf --libs wayland-server` -> 0
stdout:
-L/home/andrew/.conan2/p/b/waylab9f56735caae9/p/lib -lwayland-server -lpthread -lm -lrt

The build system still using system libs in places looks to be an unrelated issue.

planetmarshall avatar Nov 21 '25 00:11 planetmarshall

The build system still using system libs in places looks to be an unrelated issue.

Nope, it is related.

The problem now is that although adding the search paths to pkg_config_path fixes the search order and prevents pkgconf from searching the build system sysroot, the *pc files in the host sysroot return something like:

env[PKG_CONFIG_ALLOW_SYSTEM_LIBS]: 1
env[PKG_CONFIG_PATH]: /home/andrew/projects/weston/conan:/home/andrew/projects/sky/rdk/kirkstone-armv7-clang-llvmorg-21.1.4-linux/sysroots/armv7at2hf-neon-rdk-linux-g
nueabi/usr/lib/pkgconfig
env[PKG_CONFIG]: /home/andrew/.conan2/p/pkgcoa6060d80b51cc/p/bin/pkgconf
-----------
Called: `/home/andrew/.conan2/p/pkgcoa6060d80b51cc/p/bin/pkgconf --libs pango` -> 0
stdout:
-L/usr/lib -lpango-1.0 -lharfbuzz -lgobject-2.0 -lglib-2.0

Without the PKG_CONFIG_SYSROOT_DIR, the sysroot is not prepended to the paths returned by the *.pc files inside the host sysroot. So what I want is:

  1. Find *.pc files inside the conan generators folder first. Paths returned by these files should be used as is.
  2. Find *.pc files inside the host sysroot. Paths returned by these files should have the sysroot prepended.
  3. Do not look for any *.pc files in the build sysroot.

planetmarshall avatar Nov 21 '25 01:11 planetmarshall

Currently many packages in CCI including Qt (tool_)require pkgconf/2.1.0 or even older versions. When I used pkgconf/2.5.1 all my cross-compiling issues disappeared and I could finally cross-compile Qt (although not the Qt recipe currently in CCI master).

Note that overriding pkgconf in my top level recipe was not enough, see CCI issue #19310.

wdobbe avatar Nov 25 '25 17:11 wdobbe

Please see https://github.com/conan-io/conan/issues/19311#issuecomment-3580529962 for the most robust solution we have found.

Note that COnan 2.23 has reverted the behaviour and no longer passes a sysroot to meson as variable that is then passed to pkg-config.

@wdobbe we don't know what may have changed in newer versions of pkgconf - however we still need to account for a "system" (out of conan) pkgconf for all of the xxxx/system recipes in Conan Center.

jcar87 avatar Nov 26 '25 10:11 jcar87

I'd guess that this is what changed: https://github.com/pkgconf/pkgconf/commit/3611b056fbb38bf3ce849e74c7361d0de9ef2049

jwillikers avatar Nov 27 '25 02:11 jwillikers