conan-io / conan

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

[question] Install a binary package without matching the compiler version #16556

Closed Ahmed-Biad-2001 closed 2 days ago

Ahmed-Biad-2001 commented 3 days ago

What is your question?

I am trying to install a specific binary package, using conan install . --build=none, but I noticed the package ID it chooses is different than the one I want, so it fails.

By running conan graph explain . --build=none , I notice that it doesn't fetch the binary because of a difference in compiler version in my profile.

Is there a way to tell it to not match the compiler version?

======== Closest binaries ========
libtool/2.4.7
  libtool/2.4.7#08316dad5c72c541ed21e039e4cf217b%1702300906.107 (2023-12-11 13:21:46 UTC)
    libtool/2.4.7#08316dad5c72c541ed21e039e4cf217b:b647c43bfefae3f830561ca202b6cfd935b56205
      remote: conancenter
      settings: Linux, x86_64, Release, gcc, 11
      options: fPIC=True, shared=False
      diff
        settings
          expected: compiler.version=14
          existing: compiler.version=11
        explanation: This binary was built with different settings.

Conan version 2.4.1 My default profile:

[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=14
os=Linux

conanfile.py:

from conan import ConanFile
from conan.tools.cmake import cmake_layout

class MyCmakeTest1Recipe(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "CMakeToolchain", "CMakeDeps"
    default_options = { "sdl/*:shared" : True }

    def requirements(self):
        self.requires("sdl/2.30.4")

    def layout(self):
        cmake_layout(self)

Have you read the CONTRIBUTING guide?

RubenRBS commented 3 days ago

Hi @Ahmed-Biad-2001 thanks a lot for your question!

When you control enough variables of your setup that defining custom compatibility rules makes sense, conan provides the compatibility extension points, in the form of the compatibility.py plugin and the compatibility() method in recipes (Docs here)

With those, you'll be able to define custom rules for when and which kind of compatible packages could be fetch instead of the requested ones. By default, conan implements compatibility over the cppstd setting, and the linked documentation (and its references) also has examples on adding other fields as part of the compatibility checks. Please do let us know if you need further help, we're happy to help

PD: Your conan install . --build=none command has a syntax error, you're probably looking for --build=never :)

Ahmed-Biad-2001 commented 3 days ago

Hello @RubenRBS, thanks for the clarifications. Though I'm still having trouble to make it work.

Basically I'm returning a setting that is the same than SDL, but I get the same error. What did I miss?

======== Closest binaries ========
libtool/2.4.7
  libtool/2.4.7#08316dad5c72c541ed21e039e4cf217b%1702300906.107 (2023-12-11 13:21:46 UTC)
    libtool/2.4.7#08316dad5c72c541ed21e039e4cf217b:b647c43bfefae3f830561ca202b6cfd935b56205
      remote: conancenter
      settings: Linux, x86_64, Release, gcc, 11
      options: fPIC=True, shared=False
      diff
        settings
          expected: compiler.version=14
          existing: compiler.version=11
        explanation: This binary was built with different settings.

conanfile.py

    def compatibility(self):
        # SDL 2 compatibility
        return [{"settings": [('compiler.version', '11'), ('compiler','gcc')] }]
memsharded commented 2 days ago

As a side hint: it is possible to directly specify the compiler.version independently for each dependency, so you can do in you profile:

[settings]
compiler=gcc
compiler.version=14
libtool/*:compiler.version=11

And this will bring that binary, but still define compiler.version=14 for yourself and other binaries. It is a pattern, so you can define also compiler.version=11 for all dependencies and &:compiler.version=14 just for your "consumer", the & is a placeholder that mean the current consumer of dependencies.

Also, for production environments it is recommended to build the packages from source with your desired settings and store those binaries in your own server. Read for example https://docs.conan.io/2/devops/using_conancenter.html