bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.2k stars 4.06k forks source link

Ability to query/cquery dependencies on repository rules when registering a toolchain. #22737

Open jsun-splunk opened 4 months ago

jsun-splunk commented 4 months ago

Description of the feature request:

It would be useful to have the ability to query what repository rules are depending on when registering a toolchain. See the example scenario in the next section.

Which category does this issue belong to?

C++ Rules

What underlying problem are you trying to solve with this feature?

Consider the following scenario:

I have 2 repository rules to declare my cpp hermetic toolchain on macos.

repo_rule_1() declares a toolchain configuration with the following rules:

the tool_paths in CcToolchainConfigInfopoints files under a relative ./bin directory in the same package. the ./bin directory is symlinked inrepo_rule_1()to the real bin directory under a second, different repository. Let's call this second onerepo_rule_2()`.

repo_rule_2() is where all the actual toolchain binaries are. e.g. libtool, clang, etc. With filegroups() pointing to required tools/files.

the toolchain works when I run it on macos. However, when running the toolchain on windows or linux, it downloads both repositories (repo_rule_1() and repo_rule_2()) before toolchain resolution even happens. The expectation is that it should only download the repo defined in repo_rule_1(), perform toolchain resolution and if it resolves to the toolchain config in repo_rule_1() then download the repo defined in repo_rule_2(). Otherwise, the second repo should never get downloaded.

Currently, I have not been able to figure out a way to troubleshoot what is dependent on repo_rule_2() that cause it to be downloaded. None of the query/cquery I have tried seems to be able to tell me this information. The cquery results only tell me the dependency on the final toolchain after toolchain resolution.

I don't understand enough about bazel internally to know how such a query would work or if it's even possible. But without being about to do this, it is like finding a needle in a haystack to resolve this.

Looking for ideas and suggestions.

Which operating system are you running Bazel on?

macos, linux, windows

What is the output of bazel info release?

release 7.1.2

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No

Any other information, logs, or outputs that you want to share?

No response

comius commented 4 months ago

Hey, although the problem is coming from C++ rules, this seems to involve 2 other teams. Configurability team because of queries and toolchains, and OSS team because of repositories.

meteorcloudy commented 4 months ago

@jsun-splunk It'll be very helpful if you can provide a reproducible case.