-
Notifications
You must be signed in to change notification settings - Fork 795
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
[bazel] Define rules-based CC lowRISC toolchain #25810
Conversation
a0115cd
to
ec562a7
Compare
edd9495
to
728d95e
Compare
728d95e
to
290837a
Compare
Ah, English Breakfast is broken because it doesn't use bitmanip and I took away the feature for enabling that. |
Regarding the problem with actions vs tools, would it make sense to define custom actions using |
290837a
to
1b1dbf6
Compare
There was a new feature added to CRT after I started this work: lowRISC/crt#41 I'll need to port those flags too |
Hmm, that looks like it could work actually. I'll take a look at this. |
af8bb67
to
4dbbc3c
Compare
I tried out the The built-in actions expose their names through For these situations in our repo where we know we want a specific tool like |
I've also added the |
b046393
to
3e43cb4
Compare
Previously we were accessing the lowRISC toolchain indirectly via CRT, but this isn't possible with Bzlmod. We need to pull the repo in directly. Signed-off-by: James Wainwright <james.wainwright@lowrisc.org>
1eccfe1
to
d661fa2
Compare
@nbdd0121 @pamaury I have changed the code again to use The OTBN toolchain still needs specific In theory this will allow us to do things like introduce a CHERIoT toolchain as the |
d661fa2
to
2b0b66d
Compare
Thanks @jwnrt Regarding OTBN, I think you new code is fine for now. Maybe we can revisit it later with either a custom toolchain or by adding custom actions for the missing tools if necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but I would suggest to use a constant for the objdump
action.
2b0b66d
to
568a89b
Compare
Bazel is moving towards deprecating the `tool_path` style of CC toolchain which allowed executables to be taken using the `*_executable` parameters. The new method is `cc_common.get_tool_for_action` which works with both the old and new toolchain style. This commit changes all usages except for `objdump` which has no associated action. A future commit will create a custom objdump action for our toolchain and change this usage then. The OTBN toolchain actually needs exact tools. Instead of pulling these from the `cc_toolchain` it makes more sense to access the binaries directly from our toolchain repo. Signed-off-by: James Wainwright <james.wainwright@lowrisc.org>
Matches the arguments used in `//third_party/coremark/top_earlgrey`. Allows the feature-per-warning method from CRT to be replaced with one set of warnings which is easier to manage. Signed-off-by: James Wainwright <james.wainwright@lowrisc.org>
This uses the new rules-based toolchain feature of `rules_cc` to define the lowRISC toolchain with the same flags that the CRT toolchain had. There are two differences: 1. The CRT toolchain does not have the `guards` feature enabled by default, we enable it in `.bazelrc`. This new one is enabled automatically. 2. The CRT toolchain has `-Wpedantic` enabled by default, but we disable it in `.bazelrc`. This new one has it disabled by default. Signed-off-by: James Wainwright <james.wainwright@lowrisc.org>
568a89b
to
794cedd
Compare
This removes the dependency on CRT and registers the new rules-based toolchain instead. Since `guards` is now enabled by default and `pedantic` is now disabled by default, we can remove those configurations from `.bazelrc`. The configuration to disable `guards` is still present. Without CRT, we also don't need to manually load the following repos into the airgapped environment: * `@python3_toolchains` * `@ninja_1.11.0_linux` * `@cmake-3.23.2-linux-x86_64` We also now need to switch how we access objdump in our disassembly rule to use the actions-based method. See previous commits. Signed-off-by: James Wainwright <james.wainwright@lowrisc.org>
Signed-off-by: James Wainwright <james.wainwright@lowrisc.org>
794cedd
to
c145262
Compare
Summary
This PR defines a lowRISC toolchain configuration using the new rules added to
rules_cc
in version 0.0.10 and supersedes the rules from CRT. The actual toolchain and its flags should be identical.This removes the final dependency that needed to be migrated to Bzlmod.
Overview
The RISC-V C/C++ compiler we're using (the lowRISC toolchain) is currently configured for Bazel in the CRT repo. The correct binaries and flags are bound together in such a way that Bazel can use them to compile, assemble, link, etc.
The rules in CRT are much easier to use than the old way of configuring toolchains in Bazel. The Pigweed project similarly implemented their own rules for configuring toolchains and got them upstreamed into the official
rules_cc
: https://pigweed.dev/docs/blog/06-better-cpp-toolchains.htmlThese new rules are very similar to the rules from CRT. This PR uses the new rules to configure the lowRISC toolchain within the OpenTitan repository.
Benefits
Drawbacks
The new rules-based toolchains have a slightly different
CCToolchainInfo
provider to the previous ones. Tools are now associated with actions rather than as files. Bazel seems to be moving in the direction of deprecating the files-based associations, so it's a good thing for us to migrate, however there is a chance that some things will not yet be supported.What this means concretely is that you cannot access tools from the
cc_toolchain
object using parameters likeld_executable
andar_executable
. We were using this feature in some of our rules, and some dependencies likerules_foreign_cc
use it too.Bazel now wants you to use
cc_common.get_tool_for_action
however this isn't a 1:1 replacement. You can only access tools associated with the CC actions Bazel uses (compiling, linking, etc). For some reason there's no action forobjdump
even though that tool can be part of the CC toolchain.I have worked around this by accessing tools directly from the
cc_toolchain
's data files. This could be considered a hack, but I don't think there are any issues with doing this.See bazelbuild/rules_cc#297
edit: see conversations below. We are now using
get_tool_for_action
for everything except the OTBN toolchain which actually needs specifically RISCV32 tools. That toolchain now loads binaries directly from the lowrisc toolchain repository which is more correct.Testing
The toolchain should be configured the same as from CRT. I've checked that the mask ROM has the same hash when compiled before and after this PR:
The flags that CRT adds are spread across these three files:
Compare to the flags added in this version: