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

[question] Usefulness of platform_requires #17567

Open
1 task done
jasal82 opened this issue Jan 13, 2025 · 2 comments
Open
1 task done

[question] Usefulness of platform_requires #17567

jasal82 opened this issue Jan 13, 2025 · 2 comments
Assignees

Comments

@jasal82
Copy link
Contributor

jasal82 commented Jan 13, 2025

What is your question?

I don't understand the platform_requires feature or rather what use-cases it was designed for. As far as I understood it just removes the listed requirements from the dependency graph. However, it is not clear to me what problem this is supposed to solve, it rather generates new ones. Most consumers have a find_package for the corresponding libraries in their CMakeLists, but as far as I can see, it would not be able to find a library in CONFIG mode in the case of a platform_requires, as no config file is generated for the library. The standard find module of CMake (if one exists) could possibly find the library in the sysroot in MODULE mode, but this is not a universal solution, because there could also be other requirements in the graph that depend on this library. These could not retrieve any meta information about the library at Conan level, as this is not generated anywhere. Also the default find module name in CMake is not guaranteed to be the same as the one used by the corresponding Conan recipes. Even if the consumer does not do find_package in CMakeLists, but links directly to the lib file, platform_requires is not useful in my opinion, because the CMakeLists would then no longer be Conan-agnostic because you would need two different paths for builds with or without Conan (or maybe with or without platform_requires).

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Jan 15, 2025
@memsharded
Copy link
Member

Hi @jasal82

Thanks for your question.

Most consumers have a find_package for the corresponding libraries in their CMakeLists, but as far as I can see, it would not be able to find a library in CONFIG mode in the case of a platform_requires, as no config file is generated for the library. The standard find module of CMake (if one exists) could possibly find the library in the sysroot in MODULE mode, but this is not a universal solution, because there could also be other requirements in the graph that depend on this library.

The assumptions for platform_requires to work, and that is the intention of their described usage in https://blog.conan.io/2024/02/20/Conan-2-graph-features.html

Note that the system openssl must be available and usable for consumers to link it fully transparently, as Conan will no longer be injecting any information about it to the consumers. Having such a transparent usage will not be possible in many cases, because consumers still need some extra information to locate and use those system installed dependencies. In that case the following [replace_requires] will be the recommended approach:

It basically means that for a platform_requires to work it is necessary:

  • That the dependency exists in the system, and it is fully C/C++ API compatible
  • That the necessary files to consume that dependency, like xxx-config.cmake files or findxxx.cmake modules exist and can be found by the build tool (as Conan will not be providing the path to those)
  • That the interface provided by the system files for that dependency, like the above xxx-config.cmake/findxxx.cmake files is fully compatible with the replaced ones, for example if replacing zlib by zlib-ng, the zlib-ng files must define a ZLIB::ZLIB target too.

This is unlikely to happen transparently in most cases. Still there are some users that control well their system/platform dependencies and the corresponding system .cmake files, and can achieve this. This doesn't mean that they have to condition their CMakeLists.txt (sometimes they do), but it is possible to inject extra paths to locate the .cmake files to use those platform dependencies via presets, toolchains or variables.

This is why the blog post describes that in practice in most situations this will not work transparently, only for [platform_tool_requires], and for typical requires it might need [replace_requires] custom recipes that can adapt/wrap the contents to match the consumers.

I have read the docs and it is true that the Conan docs doesn't clearly define this scope and issues, so let's try to add some clarifications there.

@jasal82
Copy link
Contributor Author

jasal82 commented Jan 15, 2025

Thanks, I guess that answers my question.

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

No branches or pull requests

2 participants