Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt module: look for qt tools only on build machine #14381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

QSchulz
Copy link

@QSchulz QSchulz commented Mar 18, 2025

Qt tools may be needed at build time, let's make their detection based on the build machine rather than the host machine as currently done.

This incidentally fixes cross-compilation search for moc, rcc, uic and lrelease Qt tools because they are installed in libexec dir and that path is somehow not properly looked for otherwise.

Before:

Detecting Qt6 tools
Run-time dependency qt6 (modules: Core) found: YES 6.8.1 (pkg-config) Program /usr/bin/moc found: NO
Program /usr/lib/qt6/libexec/moc found: NO
Program moc6 found: NO
Program moc-qt6 found: NO
Program moc found: NO

After:

Detecting Qt6 tools
Found pkg-config: YES (/home/qschulz/work/upstream/buildroot/output/host/bin/pkg-config) 2.3.0
Build-time dependency qt6 (modules: Core) found: YES 6.8.1 (pkg-config)
Program /home/qschulz/work/upstream/buildroot/output/host/bin/moc found: NO
Program /home/qschulz/work/upstream/buildroot/output/host/libexec/moc found: YES 6.8.1 6.8.1 (/home/qschulz/work/upstream/buildroot/output/host/libexec/moc)

Cc @rossburton who suggested the fix in #13018. I am not entirely sure this is enough to fix #13018 hence why I omitted it in the commit log. Cc @cordlandwehr for awareness.

Cc @pinchartl and @kbingham maintainers of https://libcamera.org/ for which this patch is needed.

This was written for building the qcam (qt6-based) test application of libcamera in Buildroot 2025.02 where the build machine sysroot (provided by Buildroot) differs from the build distribution. I have not tested this patch in any other context.

Qt tools may be needed at build time, let's make their detection based
on the build machine rather than the host machine as currently done.

This incidentally fixes cross-compilation search for moc, rcc, uic and
lrelease Qt tools because they are installed in libexec dir and that
path is somehow not properly looked for otherwise.

Before:

"""
Detecting Qt6 tools
Run-time dependency qt6 (modules: Core) found: YES 6.8.1 (pkg-config)
Program /usr/bin/moc found: NO
Program /usr/lib/qt6/libexec/moc found: NO
Program moc6 found: NO
Program moc-qt6 found: NO
Program moc found: NO
"""

After:

"""
Detecting Qt6 tools
Found pkg-config: YES (/home/qschulz/work/upstream/buildroot/output/host/bin/pkg-config) 2.3.0
Build-time dependency qt6 (modules: Core) found: YES 6.8.1 (pkg-config)
Program /home/qschulz/work/upstream/buildroot/output/host/bin/moc found: NO
Program /home/qschulz/work/upstream/buildroot/output/host/libexec/moc found: YES 6.8.1 6.8.1 (/home/qschulz/work/upstream/buildroot/output/host/libexec/moc)
"""

Suggested-by: Ross Burton <[email protected]>
Signed-off-by: Quentin Schulz <[email protected]>
@QSchulz QSchulz requested a review from jpakkane as a code owner March 18, 2025 14:45
@@ -270,6 +270,9 @@ def _detect_tools(self, state: ModuleState, method: str, required: bool = True)
self._tools_detected = True
mlog.log(f'Detecting Qt{self.qt_version} tools')
kwargs = {'required': required, 'modules': 'Core', 'method': method}
# Tools are for compile-time steps, so force native check for
# compatibility with cross-compile scenarios
kwargs["native"] = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is potentially awkward if e.g. the tools can emit output which is platform-specific or Qt version-specific. In particular I'm worried about moc (as the other tools handle resource files in ways where this shouldn't really matter, or for translations, cannot really matter).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to understand how this differs from the current state? Whatever is found by meson will be used, we already have some special handling for different qt versions (e.g. qt5+ seems to use --version, while qt4 uses -v if I read compilers_detect properly?), so that likely won't change anything there would it?

There's also some oddities handled in _detect_tools based on the version returned by compilers_detect.

What are you suggesting we do here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When build Qt6, buildroot compiles two sets of packages. First, Qt6 is compiled for the buildroot host (which is the build machine, in meson terms). This creates pkgconfig files that are installed in host/lib/pkgconfig/ (all relative paths here are relative to the buildroot root build directory). In particular, host/lib/pkgconfig/Qt6Core.pc contains

prefix=host
libexecdir=${prefix}/libexec

That is the location where buildroot installs the Qt6 host compilation tools (moc, rcc, ...).

Then, buildroot cross-compiles Qt6 for the target (which is the host in meson terms). This creates pkgconfig files that are installed in host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/pkgconfig/. Those are what meson needs to pick to find the Qt6 headers and libraries for cross-compilation. Those packages do not install the build tools. Looking at the same Qt6Core.pc for the target package (host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/pkgconfig/Qt6Core.pc), we see

prefix=/usr
libexecdir=${prefix}/lib/qt6/libexec

Does meson have the ability to use different pkg-config libdirs, one for build tools and one for host (in meson terms) headers and libraries ?

Copy link
Author

@QSchulz QSchulz Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does meson have the ability to use different pkg-config libdirs, one for build tools and one for host (in meson terms) headers and libraries ?

If I'm not mistaken, yes. c.f. https://mesonbuild.com/Builtin-options.html#specifying-options-per-machine

build.pkg_config_path controls the paths pkg-config will search for native: true (build machine) dependencies.

which seems to be used by Buildroot already, c.f. https://git.busybox.net/buildroot/tree/package/pkg-meson.mk#n169

$$(MESON) setup [...] -Dbuild.pkg_config_path=$$(HOST_DIR)/lib/pkgconfig

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding build.pkg_config_path = br_host_dir / 'lib/pkgconfig' to the [built-in options] section of the cross-file I used to build libcamera helps finding the Qt build tools, but meson then picks incorrect include paths for the QtCore and QtGui headers. I haven't investigated why, it could be a bad interaction between pkg_config_libdir and pkg_config_path.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @eli-schwartz that picking the native tools is dangerous.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding build.pkg_config_path = br_host_dir / 'lib/pkgconfig' to the [built-in options] [...] helps finding the Qt build tools, but meson then picks incorrect include paths for the QtCore and QtGui headers.

Can you please provide logs, I don't understand what you're talking about. Which incorrect include paths are you talking about? In which context?

I agree with @eli-schwartz that picking the native tools is dangerous.

With regard to what? I'm not familiar with either Qt or meson so I'm probably missing something here but I'm not seeing arguments in either your answer or eli's so I cannot discuss them or look for a better implementation as I simply do not understand what the issue is (I am not saying this patch is the answer :) ). So please elaborate on what your concerns are :) Thanks!

@rhelmot
Copy link

rhelmot commented Mar 24, 2025

Data point: applying this patch fixes my cross compilation woes. I'm a distro maintainer at NixOS, where we do a lot of cross compiling, and this patch enables compiling appstream-qt, a package that uses qt6 moc so far as I can tell, from x86_64-linux to x86_64-freebsd. I am by no means a meson or qt expert, so feel free to ask questions, but I hope this patch does land :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Finding Qt6 in Cross-Compilation Setup
5 participants