conan-io / conan

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

[bug] Bazel Toochain generator cannot access custom tools.google.bazel:bazelrc_path #15750

Open sandeshhardikar opened 8 months ago

sandeshhardikar commented 8 months ago

Environment details

Steps to reproduce

  1. Define a custom toolchain variable in a compiler package recipe in package_info method (self.conf_info.append("tools.google.bazel:bazelrc_path", bazel_toolchain_file_path))
  2. I tried to print print("Rc paths", rc_paths) , but it returns a empty list .

From the comments I understand that you intend to use only 1 toolchain , but the user toolchain should have precedence over toolchain generated ?

Logs

No response

franramirez688 commented 8 months ago

Hi @sandeshhardikar

Thanks for reporting the issue.

Are you consuming the package recipe as a normal requirement or a tool requirement? This mechanism only takes effect over tool requirements (you can check this piece of documentation).

A simple example having a tool requirement and a recipe acting as a consumer:

tool_a.py

class myToolRecipe(ConanFile):
    name = "tool_a"
    version = "1.0.0"
    # ...

    def package_info(self):
        # ....
        self.conf_info.append("tools.google.bazel:bazelrc_path", bazel_toolchain_file_path) 

Consumer recipe conanfile.py:

class ConsumerConan(ConanFile):

    # ....

    def build_requirements(self):
        self.tool_requires("tool_a/1.0.0")

    def build(self):
        bazel = Bazel(self)
        bazel.build()

Executing the build() step now, you'll be able to see something like:

consumer/1.0: RUN: bazel --bazelrc=/Users/xxxxx/.conan2/p/b/xxxxxxx/b/conan/conan_bzl.rc --bazelrc=[bazel_toolchain_file_path] build --config=conan-config //...

Let me know if it works also on your side

sandeshhardikar commented 8 months ago

Hi @franramirez688 ,

Thanks for answering.

I have tried it before on conan 2.x and it works petty fine 😊 . As you can see in the environment details the problem I face is with Conan 1.63.0 .

franramirez688 commented 8 months ago

@sandeshhardikar But is it failing with Conan 1.63.0 on your side? I mean, my little example works with both Conan 1.x and 2.x, is it not your case?

sandeshhardikar commented 8 months ago

@franramirez688 : No , it doesnt work on conan 1.63.0 when running using conan install + conan build

  1. conan 2.0 - works with both conan create and conan install + conan build
  2. conan 1.63.0 - works when building with conan create
  3. conan 1.63.0 - Does not work when building with conan install + conan build

Also i never get this build command output consumer/1.0: RUN: bazel --bazelrc=/Users/xxxxx/.conan2/p/b/xxxxxxx/b/conan/conan_bzl.rc --bazelrc=[bazel_toolchain_file_path] build --config=conan-config //... in conan 1.63.0

Let me know if you have further questions

franramirez688 commented 8 months ago

Hi @sandeshhardikar

I'd need to know how looks your dependency and consumer recipes to understand what's happening there. Do you have a simple example to reproduce it on my side?

sandeshhardikar commented 8 months ago

@franramirez688

I used the same recipes given by you in the comment .

I just built it using conan install + conan build

# `.` is the path to ConsumerConan recipe
conan install . -if build
cd build
conan build ..
franramirez688 commented 8 months ago

Hi @sandeshhardikar

Yes, but it's still working as expected 😓 In Conan 1.x, the conan build command does not have the conf information due to some implementation details and certain limitations. The conan create one is calling the generate(), build(), etc., but this one is correctly propagating all that conf information. This behaviour changed in Conan 2.x, and the conan build now has all that context, so that's why works for both.

sandeshhardikar commented 8 months ago

Hi @franramirez688 ,

Thanks for looking into this again

In Conan 1.x, the conan build command does not have the conf information due to some implementation details and certain limitations.

Are there plans to fix this ?