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

[bug] tools.cmake.cmaketoolchain:user_toolchain set by build_requires not consistently seen #9571

Closed
puetzk opened this issue Sep 9, 2021 · 4 comments · Fixed by #9573
Closed
Assignees
Milestone

Comments

@puetzk
Copy link

puetzk commented Sep 9, 2021

Environment Details (include every applicable attribute)

  • Operating System+version: Ubuntu 20.04
  • Compiler+version: 9.3.0-17ubuntu1~20.04
  • Conan version: 1.40
  • Python version: 3.8.10

Steps to reproduce (Include if Applicable)

I have a package (represending a Yocto cross-compiler, further wrapped by winegcc) wants to inject custom embedded toolchain's CMAKE_TOOLCHAIN_FILE

def package_info(self):
    ...
    self.conf_info["tools.cmake.cmaketoolchain:user_toolchain"] = os.path.join(self.package_folder,"EmbeddedToolchain.cmake")

Consumers (or really a profiles) would build_require this package target the system described by those settings.

This works if the consumer uses

from conan.tools.cmake import CMakeToolchain
...
def generate(self):
     CMakeToolchain(self).generate()

but not if it uses

     generators = "CMakeToolchain"

the latter does not get the include(/path/to/EmbeddedTollchain.cmake) line in conan_toolchain.cmake (the user_toolchain block is missing).

I think the issue is that _receive_conf called (to integrate the info from build_requires) during write_toolchain, which runs after the self._generator_manager.write_generators, so generates which run via the generators = attribute will not see the effects of any build_requires' conf_info, wheras the same generator invoked from generate() will have these values. This seems like an undesirable inconsistency.

_receive_conf(conanfile)
if hasattr(conanfile, "generate"):
output.highlight("Calling generate()")
mkdir(path)
with chdir(path):
with conanfile_exception_formatter(str(conanfile), "generate"):
conanfile.generate()

self._generator_manager.write_generators(conanfile, conanfile.build_folder,
conanfile.generators_folder, self._output)
logger.info("TOOLCHAIN: Writing toolchain")
write_toolchain(conanfile, conanfile.generators_folder, self._output)

@memsharded
Copy link
Member

Thanks for the report, and the detailed investigation. Indeed a bug, fixed in #9573, and scheduled for next patch release 1.40.1.

Beware that this is quite experimental, there are quite a few unknowns, check the very simple implementation with a few TODOS:

def _receive_conf(conanfile):
    """  collect conf_info from the immediate build_requires, aggregate it and injects/update
    current conf
    """
    # TODO: Open question 1: Only build_requires can define config?
    # TODO: Only direct build_requires?
    # TODO: Is really the best mechanism to define this info? Better than env-vars?
    # Conf only for first level build_requires
    for build_require in conanfile.dependencies.direct_build.values():
        if build_require.conf_info:
            conanfile.conf.compose(build_require.conf_info)

@memsharded memsharded added this to the 1.40.1 milestone Sep 9, 2021
@puetzk
Copy link
Author

puetzk commented Sep 9, 2021

Beware that this is quite experimental, there are quite a few unknowns

Yeah :-). I just figured it was perhaps far enough along that I should try getting one of our cross-compiler/toolchain setups expressed using the new way and see what did/didn't work :-)

@memsharded
Copy link
Member

Great, please try again in a few days, when we release 1.40.1, many thanks for trying the new features! :)

@memsharded
Copy link
Member

Fixed by #9573, to be released in 1.40.1

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

Successfully merging a pull request may close this issue.

2 participants