-
Notifications
You must be signed in to change notification settings - Fork 440
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
add rule for bindgen (#102) #108
Conversation
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'm not sure why, but I'm really skeptical about this PR.
Unrelated, the variable names here are really spartan (e.g. "unformatted" "rustfmt", "bindgen" instead of "unformatted_out", "rustfmt_bin", "bindgen_bin"). I let some questionable variable names go through earlier, but during my refactoring I really regretted it every time I looked at them. Are you averse to being a bit more specific on these?
I am happy to expand on the names. My thought process was something like Do you think it is better to reference ctx.executable.bindgen every time or go with |
On the skeptical bit, I think the cc provider and toolchain usage is weird, and even the clang usage feels like it should maybe come from a clang cc_toolchain. |
I haven't come back to this yet because upstreaming this while requiring libstdcxx as a parameter is extremely suspect to me, though I haven't had any issues with the current incarnation. |
Shipping this requires either writing a @damienmg can you comment on whether the latter is actually a good idea? |
I think the latter is wiser, especially since the c++ toolchain can now be written in Starlark. I'll try to talk a bit with @mhlopko a bit latter about it to see if he can help. |
010ed33
to
3d7f9cf
Compare
Updated this to use a toolchain, which makes it a little cleaner. This "Works On My Machine".. Things to do before pushing:
The example should involve a tarball of clang and a raze imported bindgen, which is hopefully straight forward. |
genrule and actions don't seem to be able to call 'tar' anymore, on bazel 21 installed with nix, on ubuntu 18.04 ... might need to turn the build script genrules into a rule
3d7f9cf
to
5070b0a
Compare
The Ubuntu 16.04 (local and rbe) CI failures are due to the builders having an older version of libstdc++ than libclang wants...
Ubuntu 14.04 failure is probably caused by using the wrong clang tarball
Will look to fix for 16.04... |
126db22
to
6b7d1e0
Compare
Alright this looks like it works, ptal @damienmg @acmcarther There is something to be said about how much boilerplate is required to support a ~150 line rule. |
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.
First pass, I spotted a few bugs but API-wise it looks good to me.
It is still missing documentation though. Especially how to plug other dependencies (see the protobuf change).
.bazelci/presubmit.yml
Outdated
macos: | ||
osx_targets: &osx_targets | ||
- "--" # Allows negative patterns; hack for https://github.com/bazelbuild/continuous-integration/pull/245 | ||
- "--" |
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.
Why remove the comment?
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 moved the comment up to the first occurence
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 we duplicate the comment rather? or later the first one might goes away but not this one.
tools = [clang_bin], | ||
) | ||
|
||
if rustfmt_bin: |
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.
Is running rustfmt needed on generated sources? I meant, they are not made for being read anyway.
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 personally found it useful (in my own hacky version of this) when inspecting generated files. In my experience, bindgen can be a bit finnicky and require special params to configure generation. Its much easier to diagnose issues in a formatted file compared to a super long single line unformatted 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.
Beyond being useful, this is what bindgen does by default. I think it is best to keep parity with other tools whenever possible.
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.
Sounds good, can you just add a comment about it?
executable = True, | ||
cfg = "host", | ||
), | ||
"libclang": attr.label( |
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 am surprised you did not got hit by bazelbuild/bazel#6889. This will get shipped in the host configuration :(
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.
Not sure if @mfarrugi fully follows the issue, but I'm a bit confused.
Isn't host configuration the configuration we want to run bindgen 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.
We want to run this at build-time on the host, so I don't follow what "shipped" means. (I also don't understand the issue :))
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.
If we want to run this in host configuration please add cfg = "host". The default value of cfg is "target" but due to bazelbuild/bazel#6889 it somehow becomes the host configuration. This is a bug in Bazel.
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.
Thanks for following up on this (even after so long)! I know the code generation experience with cargo is super clunky and this is a good place for Bazel to stand out.
I second @damienmg's request for a bit more documentation but otherwise I'm happy with the implementation.
executable = True, | ||
cfg = "host", | ||
), | ||
"libclang": attr.label( |
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.
Not sure if @mfarrugi fully follows the issue, but I'm a bit confused.
Isn't host configuration the configuration we want to run bindgen in?
I'll look to finish this up soon. Any ideas on skipping the |
…e more user friendly.
Now I just need to skip loading local_linux on osx... |
…ldn't blow up on osx.
This probably is not far from working on osx, but I don't have a mac to test with and I don't want bounce diffs off of CI. ptal! |
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.
Only some nits now. Since buildkite is green, I say it is a go for me :)
.bazelci/presubmit.yml
Outdated
macos: | ||
osx_targets: &osx_targets | ||
- "--" # Allows negative patterns; hack for https://github.com/bazelbuild/continuous-integration/pull/245 | ||
- "--" |
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 we duplicate the comment rather? or later the first one might goes away but not this one.
tools = [clang_bin], | ||
) | ||
|
||
if rustfmt_bin: |
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.
Sounds good, can you just add a comment about it?
executable = True, | ||
cfg = "host", | ||
), | ||
"libclang": attr.label( |
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.
If we want to run this in host configuration please add cfg = "host". The default value of cfg is "target" but due to bazelbuild/bazel#6889 it somehow becomes the host configuration. This is a bug in Bazel.
Co-Authored-By: mfarrugi <[email protected]>
Looks like there are some unrelated RBE failures..
other than that I think this looks good. @acmcarther any other comments? |
@nlopezgi where's the right place to complain about rbe ci issues? (https://buildkite.com/bazel/rules-rust-rustlang?branch=master failing after a trivial change convinces me this is not our fault) |
Hi @mfarrugi |
#102
This is what I got working for me, but I haven't tested it against anything else.
Main issues I can see,
I imagine I can setup a small raze environment based on the examples in this repo, but I would like to get comments on the cc_toolchain usage (and anything else) before continuing on this.