Implementation code of bazel c++

Skip to first unread message


Jul 5, 2022, 8:28:22 AMJul 5
to bazel-discuss
Hi I'm new to bazel and I read the documentation about bazel. Now I know the rules of bazel. 

But I rarely see articles that analyze the source code. I tried to look at the source code. Bazel is implemented by java. I read the implementation of bazel compiling c++, but I am not sure if I have found the right place.

I read the code below. 

I know that bazel generates params by parsing the rules and then compiles by gcc. Can anyone tell me the approximate code path and reading order, any advice is greatly appreciated

Son Luong Ngoc

Jul 5, 2022, 11:20:52 PMJul 5
to bazel-discuss
Hi there!

This is a super interesting question to me.
It's true that there are not a lot of educational content about Bazel available,
there are even less technical deep dive content in the wild.
Good thing is that the source code is out in the open for us to explore.

I think most actions in matured bazel rules are attached with a mnemonic, which is an alias to easily identify that action type.
In general, I find it very easy to work backward from where the mnemonic was declared in a rule set back to the rule's definition.

So in this particular CPP rule set, you can grep for "mnemonic" to find where and how the actions you care about get constructed.
For example: This SourceGraph search would be a good place to start.
Some of the interesting classes include: 

Some of the higher level constructs that you might want to go through first:
- src/main/java/com/google/devtools/build/lib/actions/
- src/main/java/com/google/devtools/build/lib/actions/

I would encourage you to take a simple CPP example from 
and try running `bazel aquery //...` to explore the final constructed command line for each action.

Hope it helps :)
Son Luong.


Jul 6, 2022, 2:29:25 AMJul 6
to bazel-discuss
Hi Son, thanks a lot for your help!

I think there is too little analysis on bazel source code, and some implementations still need to be customized. I don't know how the bazel community is maintained, or where do people start to look at the source code, to maintain and be able to deal with problems.

bazel is a very good tool, I will learn and share some articles next, thank you again for your help!
Reply all
Reply to author
0 new messages