-
Notifications
You must be signed in to change notification settings - Fork 805
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
base: master
Are you sure you want to change the base?
Conversation
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 |
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.
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:
- All
bazel_dep
s at the top. - All overrides (
git_override
. andsingle_version_override
s). - 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.
rules/extensions.bzl
Outdated
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 |
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.
Can you explain why this is 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.
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().
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.
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.
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.
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
.
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.
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
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.
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.
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 |
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]>
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]>
Example using this repo externally:
https://github.com/korran/opentitan-external-example