Skip to content
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

Allow lowrisc_opentitan bazel module to be used as a non-root module by external workspaces. #25979

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

korran
Copy link

@korran korran commented Jan 22, 2025

Example using this repo externally:
https://github.com/korran/opentitan-external-example

~/git/opentitan-external-example$ bazel build @lowrisc_opentitan//sw/host/opentitantool:opentitantool
<snip>
Target @@lowrisc_opentitan+//sw/host/opentitantool:opentitantool up-to-date:
  bazel-bin/external/lowrisc_opentitan+/sw/host/opentitantool/opentitantool
INFO: Elapsed time: 272.707s, Critical Path: 100.69s
INFO: 831 processes: 261 internal, 570 linux-sandbox.
INFO: Build completed successfully, 831 total actions

@a-will
Copy link
Contributor

a-will commented Jan 22, 2025

Thanks for contributing, Kor! This is a topic of interest these days, hehe.

You'll need to sign your git commits to get CI beyond the lint stage. (as in git commit --signoff, where it would append something like Signed-off-by: Kor Nielsen <user@domain> to the end of the commit message)

@jwnrt jwnrt linked an issue Jan 23, 2025 that may be closed by this pull request
Copy link
Contributor

@jwnrt jwnrt left a comment

Choose a reason for hiding this comment

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

This looks good to me, I'm personally fine with merging the MODULE files if it lets us be used as a dependency. Thanks a lot.

Would you mind reformatting MODULE.bazel so that the sections are:

  1. All bazel_deps at the top.
  2. All overrides (git_override. and single_version_overrides).
  3. The rest of the extensions and toolchain registrations.

You can also drop the "original from x.MODULE.bazel" comments if you like, they won't be useful anymore. Feel free to add "Rust configuration", "Python configuration" headers to separate the sections if you like though.

dir = rctx.getenv(repo.env, repo.dummy)
local_repository(name = repo.name, path = dir)
d = rctx.getenv(repo.env, str(rctx.path(repo.dummy)))
# (hack) Make sure the dir is actually populated by reading a file
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why this is necessary?

Copy link
Author

@korran korran Jan 24, 2025

Choose a reason for hiding this comment

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

I've found that when doing clean builds, intermittently bazel hasn't populated this directory before local_repository() is executed, and it fails with a file-not-found error.

FWIW, I don't think local_repository() should be abused to do what you want here, as it shouldn't be used to look at internal bazel-managed files (such as those in the lowrisc_opentitan module). I think it's much safer to to iterate over the files in this label and manually put them into the repo with rctx.file().

Copy link
Author

Choose a reason for hiding this comment

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

I've changed this logic. Calling local_repository() on files from a label ends up putting horrible absolute paths into MODULE.bazel.lock, which is unacceptable. Instead, I've changed it to use a custom repository_rule that references the label instead of a path.

Copy link
Author

Choose a reason for hiding this comment

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

Also, I wonder if this might be a lot simpler if instead of doing these environment-variable tricks, we just used a bazel module for these things, letting users override on the command line with --override_module=provisioning_exts=some/path.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi Korran, this rule is there for mostly for pre-blzmod backward compatibility. We discussed switch to module overrides previously. Maybe we should accelerate the transition. @a-will @jwnrt

Copy link
Contributor

Choose a reason for hiding this comment

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

I know that somebody recently had issues with this being an extension since there was no way to add extra dependencies in the hook repo. I think making this an overridable module would solve that problem. Now would be a great time to do that.

@pamaury
Copy link
Contributor

pamaury commented Jan 23, 2025

Thanks @korran for this contribution, this looks very useful. I don't know if we should make this part of this PR, but I think some kind of CI check to make sure that we do not regress would be very useful. Otherwise it's only a matter of time before we split another @//something instead of @lowrisc_opentitan// which will break the repo.

Ping @jwnrt @cfrantz on that.

This does not work when used as a non-root bazel module.

Signed-off-by: Kor Nielsen <[email protected]>
This is necessary when used as a non-root bazel module.

Signed-off-by: Kor Nielsen <[email protected]>
@korran
Copy link
Author

korran commented Jan 24, 2025

You'll need to sign your git commits to get CI beyond the lint stage. (as in git commit --signoff, where it would append something like Signed-off-by: Kor Nielsen <user@domain> to the end of the commit message)

I've added sign-offs to all the commits.

This is necessary when used as a non-root bazel module, as relative
paths are relative to the root workspace.

Signed-off-by: Kor Nielsen <[email protected]>
This is necessary because include() can only be used by non-root
modules.

Signed-off-by: Kor Nielsen <[email protected]>
These don't work when used as a non-root module.

Signed-off-by: Kor Nielsen <[email protected]>
@moidx moidx added the CI:Rerun Rerun failed CI jobs label Jan 29, 2025
@github-actions github-actions bot removed the CI:Rerun Rerun failed CI jobs label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bazel] OpenTitan as a Bazel module dependency
5 participants