conan-io / conan

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

[question] How to properly use replace_requires? #16399

Open Nekto89 opened 1 month ago

Nekto89 commented 1 month ago

What is your question?

Hi, I have a question regarding replace_requires.

Previously I was changing recipes to be able to use zlib-ng instead of zlib. [replace_requires] should be able to allow me to do this without change of recipes if I understood correctly. But I can't make it work. Is this a problem of recipe that uses zlib, recipe of zlib-ng or conan? Or maybe I'm doing something completely wrong?

conan install -r=conancenter "--requires=crowcpp-crow/1.2.0" -pr:b build_profile -pr:h host_profile --build=missing

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.update=9
compiler.version=192
os=Windows
[options]
crowcpp-crow/*:with_compression=True
crowcpp-crow/*:with_ssl=False
zlib-ng/*:zlib_compat=True
[conf]
tools.cmake.cmaketoolchain:generator=Visual Studio 17 2022

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.update=9
compiler.version=192
os=Windows
[conf]

======== Computing dependency graph ========
Graph root
    cli
Requirements
    asio/1.29.0#52d17a857aa6f978d8c17d7c38eae5ad - Cache
    crowcpp-crow/1.2.0#144d39a4f1ee5436ecfa06ccd5c547f4 - Cache
    zlib-ng/2.1.6#9e56e2ad03e40e7d0b3d22a2274fb37c - Cache
Replaced requires
    zlib/[>=1.2.11 <2]: zlib-ng/2.1.6

======== Computing necessary packages ========
Requirements
    asio/1.29.0#52d17a857aa6f978d8c17d7c38eae5ad:da39a3ee5e6b4b0d3255bfef95601890afd80709#b132a176c32962cb7be826d56fbe242d - Cache
    crowcpp-crow/1.2.0#144d39a4f1ee5436ecfa06ccd5c547f4:208bab9127ec1e26e476b4f3fdeccd1dbc047790#b970240236456bdd009782b4c1bd14e7 - Cache
    zlib-ng/2.1.6#9e56e2ad03e40e7d0b3d22a2274fb37c:a813a49d371fc5b0c1ac8bad0b668beb010b8773#75dbedba30941d7b350f3bfa45517079 - Cache

======== Installing packages ========
asio/1.29.0: Already installed! (1 of 3)
zlib-ng/2.1.6: Already installed! (2 of 3)
crowcpp-crow/1.2.0: Already installed! (3 of 3)
ERROR: crowcpp-crow/1.2.0: required component package 'zlib::' not in dependencies

Have you read the CONTRIBUTING guide?

Nekto89 commented 1 month ago

I just noticed that conan doesn't output replace_requires in log. It is present in my host profile

[replace_requires]
zlib/* : zlib-ng/2.1.6
AbrilRBS commented 1 month ago

Hi @Nekto89 thanks a lot for taking the time to report the issue.

While it's true that this is one great side-effect of the feature, this aspect is not fully realized yet, so some shortcomings are still expected. We are planning on thinking more about this issue to provide solutions for this usage (And it's one of the reasons for which we've stop accepting PRs in CCI that add a with_zlibng option to recipes, the idea is to let users choose via the replace mechanism)

I'll let you know once we have some solid ground to work on, but for now I'll check if there's something to be done in the recipe to support this use-case without too many modifications :)

AbrilRBS commented 1 month ago

I just noticed that conan doesn't output replace_requires in log. It is present in my host profile [replace_requires] zlib/* : zlib-ng/2.1.6

I'm proposing https://github.com/conan-io/conan/pull/16401 for Conan 2.4 next release to fix this issue, thanks for the heads-up :)

jan-guenter commented 4 weeks ago

I'm also trying to use replace_requires to substitute zlib-ng for zlib. The main issue I'm facing is that many recipes like openssl use self.dependencies["zlib"] which then fails with KeyError: "'zlib' not found in the dependency set"

Perhaps a bit naïve, but wouldn't it make sense to alias the dependencies with their original name in the dependencies dict?

memsharded commented 4 weeks ago

I am investigating in https://github.com/conan-io/conan/pull/16443 if it is possible to allow this, or replace_requires requires full referential transparency. Even with this investigation can improve things a bit on the Conan side, there might be other aspects like CMakeLists.txt with a find_package(ZLIB) will hardly work unless the replacement zlib-ng is configured to create the same ZLIB-Config.cmake filename and possible target names.

memsharded commented 2 weeks ago

@RubenRBS has also been investigating the part of the cpp_info.requires, we are doing progress, but still need more research.