conan icon indicating copy to clipboard operation
conan copied to clipboard

[question] How to separate generator files by requirements and tool requirements

Open prince-chrismc opened this issue 3 years ago • 5 comments

In https://github.com/conan-io/conan-center-index/pull/13612

We need to do some hackery in the build script to avoid both the dependencies and build requirements (which overlap) PkgConfigDeps being in the same folder.

@jwillikers implemented two different solutions

  • one with PkgConfigDeps.build_context_suffix and patching the Meson build script to use the new name.
  • one with manually copying the files to a seperate folder

Ideally there would be a generator folder for each for the advance case where we need to seperate them.


I'll get an error if I don't set the build_context_suffix for the wayland package because this library requires the wayland-client library from the wayland package as a regular requires while simultaneously requiring the wayland-scanner tool from the wayland package as a tool_requires.

If we were able to place the build-context pkg-config files in a separate directory from the others, this would avoid naming conflicts and the necessary patching to find the tool_requires dependencies. Meson would be able to handle this gracefully just by setting the standard project option build.pkg_config_path to a value including the directory for the build-context pkg-config files.

Originally posted by @jwillikers in https://github.com/conan-io/conan-center-index/pull/13612#discussion_r999896514

prince-chrismc avatar Oct 20 '22 05:10 prince-chrismc

I'd like to understand one thing: is the wayland that is used via a tool_require some executable that must be used in the build, or is it a library to link with?

Because in that PR I see:

if self._has_build_profile and self.options.get_safe("with_wayland"):
            self.tool_requires("wayland/1.21.0")
            self.tool_requires("wayland-protocols/1.27")

But the with_wayland option is not removed from package_id(), so it means that it is relevant to create a different binary, not just a tool that is necessary? I don't know much about wayland...

memsharded avatar Oct 20 '22 07:10 memsharded

@memsharded It's used as both a regular requires and a tool_requires in this case. It provides both a library and a tool known as wayland-scanner that generates source code from XML files.

jwillikers avatar Oct 20 '22 11:10 jwillikers

It's worth noting that several projects locate the wayland-scanner utility through its pkg-config file, including the wayland package itself.

There's also an important problem with the current build_context_suffix. It doesn't automatically provide the necessary pkg-config files for dependencies in the build context, so it's actually mixing pkg-config files from the build and host contexts which is concerning.

To illustrate, the wayland-scanner component requires libxml2::libxml2 and expat::expat. The associated pkg-config names are listed in the pkg-config file generated for wayland-scanner. The build context version of wayland-scanner still contains the pkg-config names for expat and libxml2 in the host context.

When attempting to use a separate build context directory for the pkg-config files in the build context, I think it's necessary to include all the required pkg-config files there so that pkgconf doesn't fail to find the dependency when the dependency is required in the build context and set as required in Meson.

jwillikers avatar Oct 21 '22 16:10 jwillikers

Update: It looks like updates for the Flex recipe are facing a similar conundrum, but regarding supplied CMake modules: conan-io/conan-center-index#14013

jwillikers avatar Dec 14 '22 22:12 jwillikers

This couldn't be prioritized into 1.X, but I am moving it to 2.X, because it will get more attention there.

I think this is doable by introducing a PkgConfigDeps.build_prefix, lets give it a try.

memsharded avatar Feb 12 '24 13:02 memsharded

Implemented in https://github.com/conan-io/conan/pull/15813 for next 2.2

memsharded avatar Mar 06 '24 21:03 memsharded