Skip to content

Proof of concept llvm-toolchain#221

Draft
furtib wants to merge 3 commits intoEricsson:mainfrom
furtib:bazel-llvm-toolchain
Draft

Proof of concept llvm-toolchain#221
furtib wants to merge 3 commits intoEricsson:mainfrom
furtib:bazel-llvm-toolchain

Conversation

@furtib
Copy link
Copy Markdown
Contributor

@furtib furtib commented May 1, 2026

Why:
We want Bazel to handle all dependencies, including the LLVM toolchain.

What:

  • Added the LLVM toolchain as a dependency
  • Modified the monolithic/single job codechecker rule to use the provided binaries by adding the folder containing them to the PATH

Addresses:
none

Note:
Well that broke spectacularly.....
Issues:

  • Each project, including the rule set, will be required to also import the LLVM toolchain (the LLVM toolchain does not allow dependencies to download it) -> This breaks Foss tests and external unit tests,
  • Couple legacy tests are failing, will look into it when I have time, some fails due to clang taking precedence over gcc, changing the compile_commands.json content

"llvm_toolchain_llvm" contains every binary, not just clang. I might be mistaken in how I import the toolchain, but I believe we need this one for sure.

@furtib furtib marked this pull request as draft May 1, 2026 07:47
@furtib furtib requested review from Szelethus and nettle and removed request for nettle May 1, 2026 07:47
@furtib furtib added the question Further information is requested label May 1, 2026
@furtib furtib self-assigned this May 1, 2026
@furtib furtib requested a review from nettle May 1, 2026 07:47
Copy link
Copy Markdown
Collaborator

@nettle nettle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @furtib! This is really interesting!
So... as you mentioned we cannot use this approach at least explicitly because C/C++ rules are trying to use this LLVM toolchain :)
We should think how to move forward

Comment thread MODULE.bazel Outdated
Comment thread src/codechecker.bzl Outdated
Comment on lines +103 to +108
clang_executable = cc_toolchain.compiler_executable
if hasattr(clang_executable, "dirname"):
wrapper_bin_dir = clang_executable.dirname
else:
wrapper_bin_dir = "/".join(clang_executable.split("/")[:-1])
real_llvm_bin_dir = wrapper_bin_dir.replace("llvm_toolchain", "llvm_toolchain_llvm")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont understand this part yet :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No wonder I for sure made this wrong.
My goal was to have the directory containing the LLVM libraries in PATH.
The documentation for the toolchain did not hold my hand at all on how this should be done.
I'm looking at their tests right now to figure out how they did it.

@furtib
Copy link
Copy Markdown
Contributor Author

furtib commented May 4, 2026

Well, I made some adjustments, mainly to how the toolchain is recognized.

The new idea is to have an optional parameter where users can provide their llvm_toolchain bin directory as input, and add that to PATH. (This is much better than the one I did before, but it does require more setup from users.)

Does this approach seem reasonable?
I do recognize that defining the llvm_toolchain for each target is not the most ergonomic, but it is the most flexible way. We have seen similar methods in aspect lint. This way, we even support custom LLVM rules.

I believe this would also allow users to de-prioritize the LLVM toolchain in the selection order of C++ toolchains(?).
I'm not sure.

format_test(
    name = "format_test",
    starlark = "@buildifier_prebuilt//:buildifier", # <- this line
	...
)

What still needs to be done:

  • For a patch like this to land, we would need to change our testing. (The tests could have their own MODULE.bazel, an example is the llvm_toolchain repo) This is necessary since llvm_toolchain does not allow itself to be a transitive dependency (due to its size). -> This would fix foss tests, and external tests (these are the ones that fail)

@furtib furtib force-pushed the bazel-llvm-toolchain branch from eeb6015 to 38fe9bc Compare May 4, 2026 11:48
@furtib
Copy link
Copy Markdown
Contributor Author

furtib commented May 4, 2026

To make it a bit more serious, I fixed the tests.
It does make the patch very messy :/

The highlights:

  • I copied the testing solution of the llvm_toolchain, so:
    • Tests area separate bazel project, with its own MODULE.bazel. (I did have to modify every single test to accompany this :( )
  • I modified the codechecker_pass target in legacy tests to show how users would use the llvm_toolchain. (This is just for demonstration)

@furtib furtib force-pushed the bazel-llvm-toolchain branch 5 times, most recently from f5e0868 to 427fdec Compare May 4, 2026 12:18
@furtib furtib force-pushed the bazel-llvm-toolchain branch from 427fdec to 02cf60e Compare May 4, 2026 12:22
@furtib furtib requested a review from nettle May 4, 2026 14:05
@nettle
Copy link
Copy Markdown
Collaborator

nettle commented May 4, 2026

The new idea is to have an optional parameter where users can provide their llvm_toolchain bin directory as input, and add that to PATH. (This is much better than the one I did before, but it does require more setup from users.)

Does this approach seem reasonable? I do recognize that defining the llvm_toolchain for each target is not the most ergonomic, but it is the most flexible way. We have seen similar methods in aspect lint. This way, we even support custom LLVM rules.

I believe this would also allow users to de-prioritize the LLVM toolchain in the selection order of C++ toolchains(?). I'm not sure.

Yes, this might be used. Basically this way we can provide path to particular binaries.
And I think this should be at least an option.
However, as I can understand, as soon as we use LLVM toolchain the whole package may want to use it for cc_binary, cc_libary etc. In some cases this is not the scenario users may want.

What still needs to be done:

  • For a patch like this to land, we would need to change our testing. (The tests could have their own MODULE.bazel, an example is the llvm_toolchain repo) This is necessary since llvm_toolchain does not allow itself to be a transitive dependency (due to its size). -> This would fix foss tests, and external tests (these are the ones that fail)

I dont think creating more packages inside packages is a good idea. At least it is highly discouraged in Bazel.
Besides, what is the purpose?
To be honest I did not get "llvm_toolchain does not allow itself to be a transitive dependency" etc.
I think we need a meeting where you explain.

@nettle
Copy link
Copy Markdown
Collaborator

nettle commented May 4, 2026

To make it a bit more serious, I fixed the tests. It does make the patch very messy :/

Well, the recent change made it impossible to review :)
I guess we should probably drop this...

The highlights:

  • I copied the testing solution of the llvm_toolchain, so:

    • Tests area separate bazel project, with its own MODULE.bazel. (I did have to modify every single test to accompany this :( )

We should definitely avoid packages inside packages.
In general the idea of multiple packages is not good and often an indication of bad design.
I saw projects with similar mistakes - later it took much efforts to fix them.

  • I modified the codechecker_pass target in legacy tests to show how users would use the llvm_toolchain. (This is just for demonstration)

Yes, I got the idea, Thanks!

@furtib furtib force-pushed the bazel-llvm-toolchain branch 2 times, most recently from 0645e58 to 2f6a06b Compare May 5, 2026 08:07
@furtib furtib force-pushed the bazel-llvm-toolchain branch from 2f6a06b to 7b923c5 Compare May 5, 2026 08:28
@furtib
Copy link
Copy Markdown
Contributor Author

furtib commented May 5, 2026

Well, the recent change made it impossible to review :)

Sorry about that, I reverted those changes

To be honest I did not get "llvm_toolchain does not allow itself to be a transitive dependency" etc.

This is the offending line:
https://github.com/bazel-contrib/toolchains_llvm/blob/e15a648c23a6305c58f2cb54486ce99fe331696e/toolchain/extensions/llvm.bzl#L55

Not sure what an acceptable way to handle this is.
Lets discuss it in details in a meeting.

(I did make some miscellaneous changes, compared the issue of transitive dependencies it is not important)

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

Labels

question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants