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
rustup: wrap bindgen to find header files in a nix-shell #45330
Conversation
cc @Ralith as maintainer |
Ideally, the injected arguments to clang should be added immediately after the |
I agree, but this is beyond my bash skills. Anyway, we only add
its was moved from clang-unwrapped.lib to libclang.lib. I can solve the parsing of |
Sorry for the delay getting back to you; this fell off my stack for a while.
Can you add leave a comment explaining that this behavior is unintended instead, then?
It could still be an issue with e.g.
The concern is that might change in the future without any of us noticing.
Seems like a good thing to have, unless there's prospects of upstream making the tests more portable themselves. |
8dbb33d
to
db09698
Compare
Done
Fixed I squashed everything together. |
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! Big step in the right direction.
I get an error message, maybe you can clarify what happens: $ nix-review pr 45330
nix-shell> bindgen
error: header '-isystem' does not exist. # <- is this error supposed to happen?
thread 'main' panicked at 'Unable to generate bindings: ()', libcore/result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace. |
huh it seems it is bindgen's fault.
|
Fixed by a small patch which I sent upstream: rust-lang/rust-bindgen#1376
|
Hum for some reason the UI of github didn't take my push force into account: the PR is now symphorien@33969e2 (edit: fail paste) |
patches = [ | ||
# https://github.com/rust-lang-nursery/rust-bindgen/pull/1376 | ||
(fetchpatch { | ||
url = https://github.com/rust-lang-nursery/rust-bindgen/pull/1376/commits/c8b5406f08af82a92bf8faf852c21ba941d9c176.patch; |
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 they ask you to update the pull request, would this patch url still be valid?
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.
right it would disappear. I just tested with the precedent hash of this PR
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.
apparently https://github.com/nixos/nixpkgs/commit/db096988b8c.patch is still available
The easy part is to add NIX_CFLAGS_COMPILE for "regular" libraries. A bit more tricky is to add the required flags for libclang to find libstdcxx. For this we parse arguments to bindgen to look for -x c++ or -xc++ and if found add NIX_CXXSTDLIB_COMPILE to the arguments. This variable is populated by a complex dance of setupHooks. We trigger this by adding clang to propagatedBuildInputs. A more subtle way may exist.
options: mark clang-args last before, `bindgen -- -I blah` would try to open `-I` as a header file, leading to a very confusing error message. The "real" use case behind this is described here: NixOS/nixpkgs#45330 I have checked that these ways of passing args still work/error as expected: ``` bindgen a.h bindgen a.h -- bindgen a.h -- -Dblah=1 bindgen -- -Dblah=1 bindgen -- bindgen ```
The PR was merged so the commit should not disappear anymore. |
Motivation for this change
this is a second attempt at #40746
it should work in any nix-shell where the header file is correctly parsed by clang, as long as -x c++ is
explicitly specified for c++ headers.
This is done in two commits: the first one is the one which wraps bindgen. The second one is an attempt at making tests works. Around 190/300 pass, but the test suite requires nightly rustfmt so most if not all failures are just a question of formatting :(
This second commit is therefore unnecessary, but when we update rustc or when rustfmt becomes stable it may prove useful. I was not sure whether to leave it, so if you think I should remove it from the PR just tell me.
About closure size: to have NIX_CXXSTDLIB_COMPILE populated, the only non absurd way I found was to add clang as propagatedBuildInputs. This is wasteful, but I could not get
libstdcxxHook
to work.Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)