conan icon indicating copy to clipboard operation
conan copied to clipboard

Make 'Any' working with missing setting value

Open NingyuShi opened this issue 10 years ago • 10 comments

I want to make a package for bazel as part of build tool. Since I need to build from source, I have to add compiler to the package settings. However once it's build, it shouldn't need the compiler settings to be used. But when I try to use it as an requirement in another package (which is a rule/config only package), it keep asking for 'compiler' settings to be provided, otherwise it refuses to build.

I put these in the bazel recipe,

    def conan_info(self):
        self.info.settings.compiler = "Any"
        self.info.settings.compiler.version = ["Any"]

but it still complains about

ERROR: bazel/0.4.0@test/test: 'settings.compiler.libcxx' value not defined

when compiling the package depends on it. Is it possible to make the 'Any' working with missing values?

NingyuShi avatar Nov 21 '16 15:11 NingyuShi

Might be possible, I have to try a few things first to be sure.

Quick question, I guess that your version should be version = "Any" without the brackets? And also missing a settings.compiler.libcxx = "Any" ?

memsharded avatar Nov 27 '16 23:11 memsharded

I'll try your suggestion and report back to you soon.

NingyuShi avatar Nov 28 '16 17:11 NingyuShi

I think that it will fail, there is something to fix in conan, but just to make sure. Thanks!

memsharded avatar Nov 28 '16 17:11 memsharded

I am checking this. Would like to note that there are two very simple workarounds:

  • Just provide the settings to the package, even if they are not being used.
  • Create a "profile" that stores those settings, and make it transparent, just call conan install --profile=tool, and it will be valid both for building the tool from sources, and to install it.

Checking the source code, it doesn't seem easy to bypass the settings validation (the stage that is raising the Error because the settings are not given a value), because of the 2 steps conan flow, one to resolve the dependency tree (using the settings), one to get the binaries (build or retrieve). So you need the settings to compute the binary hash ID, so it doesn't know that it doesn't need the settings because it has only 1 binary irrespective of the settings.

So, maybe an idea would be that the main issue is that such settings might not be real settings. The core idea behind the settings is that different settings produce different binaries. Some constraints might be imposed in conan_info(), but maybe if conan_info() is completely removing some settings, then such settings are not real settings. So if building a binary executable, maybe the only setting is the OS, and the rest are directly hardcoded in the package recipe build() method. It is also possible to parameterize things with options, that admit a default value, and can be also "erased" in conan_info(). Would this be a viable approach?

memsharded avatar Nov 30 '16 21:11 memsharded

Exactly why do you need the compiler setting to build you package? Are you using some helper (like CMake or ConfigureEnvironment) that crashes without it? If the compiler is not a real setting I thing the way to go is use an option, not a setting.

lasote avatar Dec 01 '16 09:12 lasote

@lasote The package is a header only package, but there are testing binaries need to be built with compiler settings. Also the package depends on other packages of libraries, which during building need compiler setting to find correct match. I use a customized helper which during build need compiler settings.

I agree with @memsharded the setting is not real setting which impact final package artifacts, it's only used during build() as verification (don't want to ship without building test). However, these settings cannot be replaced with options since other packages honor them.

NingyuShi avatar Dec 01 '16 16:12 NingyuShi

Quick question: What do you mean that the settings cannot be replaced with options, since other packages honor them? Typically a header only library has no settings at all, but it can depend on other packages (even static or shared libraries) that use settings to be built. The declared settings for all packages don't necessarily need to be the same.

With this new information, I think that it is not totally wrong to require the package to be provided with compiler and version information through settings. Being it a header-only or a compiled one is something that should be precisely abstracted away by the package manager. You install such a library, and you will be building with such compiler and such version. If the library is header-only or static/shared is implementation details that you might even not know, or possibly can even change during development and convert a header-only to compiled one due to excessive build times. A good example is Boost, which support an option called header_only. In that case the settings will be discarded, in order to provide just one package. Also, it might be not the most usual approach, but a use case is that of generated headers, different for each OS/compiler. It might be a header-only package, but with different implementation details depending on the OS and compiler.

The purpose of conan_info() is basically that one, to be able to clear input requirements to map them to the real artifacts being generated, but being totally abstracted from the consumer user. Does this make sense?

memsharded avatar Dec 01 '16 18:12 memsharded

@memsharded I think setting required to build the package and the setting required to use the package are two different thing, even though a lot of time they are correlated. Say I want to release a CMake package, during building process, I do need to provide compiler settings, but once it's built, the package does not any compiler setting to be used, so it can be consumed by a python package which does not have any compiler setting. In this case, how do I clean the setting requirements in conan_info(), so that even in the python package I don't have compiler as an input setting, conan still be able to match the binary package of CMake?

NingyuShi avatar Dec 01 '16 18:12 NingyuShi

Quick question, What about split the library in two packages? One the header only without settings and another one for the tools. It makes sense?

lasote avatar Dec 02 '16 08:12 lasote

This was addressed some time ago, the approach is:

  • Declare settings you need to build() the package
  • Remove totally unnecessary settings in configure()
  • Remove the settings in package_id() method

Something like:

class Pkg(ConanFile):
      settings = "os", "compiler", "arch", "build_type"

      def configure(self):
           del self.settings.compiler.libcxx  #for example, for pure C code
      def build(self):
            # you can build here using the settings as input
      def package_id(self):
            self.info.header_only()  #this removes all config info => only 1 final binary package

So I think this issue can now be closed, but please comment or reopen if necessary. Thanks!

memsharded avatar Dec 14 '17 13:12 memsharded