conan-io / conan

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

[question] Cannot use cpython as a downstream dependency #16927

Closed Todiq closed 2 weeks ago

Todiq commented 2 months ago

What is your question?

Hello,

I am not really sure in which repo to create this ticket, since I don't know if it comes from a recipe's misuse or a conan client misuse (or something else).

I have a library alpha and a library beta that depends on it. Both need to link with boost python. As boost python is not set to automatically gather cpython, I would like to get it through the conanfile, rather than using the system one.

Here is an example : https://github.com/Todiq/test_conan

You juste have to run python build.py. I only tested it on Windows. \ \ While the build of alpha passes, it fails on beta:

CMake Warning (dev) at C:/Program Files/Microsoft Visual Studio/2022/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
  The package name passed to `find_package_handle_standard_args` (Python3)
  does not match the name of the calling package (Python).  This can lead to
  problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  C:/Program Files/Microsoft Visual Studio/2022/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindPython/Support.cmake:3867 (find_package_handle_standard_args)
  C:/Program Files/Microsoft Visual Studio/2022/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindPython3.cmake:545 (include)
  D:/conan/p/cpythaac989ed1ef63/p/bin/libs/cmake/use_conan_python.cmake:14 (include)
  build/windows-msvc/generators/FindPython.cmake:38 (include)
  CMakeLists.txt:24 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found Python3: D:/conan/p/cpythaac989ed1ef63/p/bin/libs/cmake/../../python.exe (found version "3.9.19") found components: Interpreter
-- Configuring done (1.4s)
CMake Error at betaimpl/CMakeLists.txt:10 (target_link_libraries):
  Target "betaimpl" links to:

    Python::Python

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

-- Generating done (0.0s)
CMake Generate step failed.  Build files cannot be regenerated correctly.

ERROR: conanfile.py (test_beta/1.0): Error in build() method, line 52
        cmake.configure()
        ConanException: Error 1 while executing

\ \ \ Replacing find_package(Python COMPONENTS Development QUIET) with find_package(Python3 COMPONENTS Development QUIET) in beta's cmake removes the initial warning, but does not fix the issue (no warning in alpha though). \ \ In beta's recipe, I tried using self.requires("cpython/3.9.19", override=True) instead of the regular self.requires("cpython/3.9.19") as well, but that would not fix the issue either. \ \ Am I missing something? Thanks in advance for your help!

Have you read the CONTRIBUTING guide?

memsharded commented 1 month ago

Thanks for your report @Todiq

I am trying to reproduce with your repo code, but my build is failing at an earlier stage, while building "boost":

boost/1.85.0: RUN: "C:/Users/memsharded/Envs/conan2_310/Scripts/python.exe" -c "from __future__ import print_function; import sys; print('{}.{}'.format(sys.version_info[0], sys.version_info[1]))"

boost/1.85.0: WARN: Boost component 'numpy' is missing libraries. Try building boost with '-o boost:without_numpy'. (Option is not guaranteed to exist)
ERROR: boost/1.85.0: Error in package_info() method, line 1997
        raise ConanException(f"These libraries were expected to be built, but were not built: {non_built}")
        ConanException: These libraries were expected to be built, but were not built: {'boost_numpy310'}

No idea why this is happening, I'd need to investigate

Todiq commented 1 month ago

@memsharded,

I am using python 3.9.13 on my side, but I don’t think that will differ much from your version

Boost (recipe?) expects to have numpy installed (of course, I know you’re not blind).

The only workaround I found so far for this is to install it in the (virtual) environment. But here’s the catch: I never made it work with a version > 1.26.4. Meaning that starting from numpy version 2.0.0 and upwards, I would get the same error as yours (if my memory is correct). Could you please try with 1.26.4?

Todiq commented 1 month ago

You error looks like the one mentionned here: https://github.com/conan-io/conan/issues/11241

Todiq commented 1 month ago

@memsharded @valgur

Do you think it might be related to https://github.com/conan-io/conan/issues/16952 ?

Todiq commented 1 month ago

Hi @memsharded,

Would you mind having a look again when you have some time please? I know you must be very busy. Thanks in advance.

Todiq commented 1 month ago

@memsharded,

Do you think that ticket would better fit in the conan-center repo?

Todiq commented 1 month ago

I added more precise instructions to reproduce here: https://github.com/conan-io/conan-center-index/issues/25463

Todiq commented 2 weeks ago

Fixed thanks to https://github.com/conan-io/conan-center-index/issues/25463

memsharded commented 2 weeks ago

I am very sorry about not being able to track this properly and follow up. Indeed it is very challenging sometimes, specially when it involves too recipes in ConanCenter (issues that can be isolated to the Conan client are easier to manage, so they can be prioritized differently too sometimes).

Thanks very much for your feedback and your follow ups on conan-center-index too.