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

[WIP] rustc_llvm: use rust-bindgen to generate FFI bindings #46353

Closed
wants to merge 4 commits into from

Conversation

tamird
Copy link
Contributor

@tamird tamird commented Nov 29, 2017

This is my WIP attempt at #17795; note that the majority of the work involves hoisting various definitions from rustllvm/*.cpp to rustllvm/rustllvm.h, and then mapping various LLVMFoo to Foo in Rust to match the current exported names.

This doesn't compile since many definitions haven't yet been hoisted, but librustc_llvm itself does compile, so this should be a decent proof of concept for y'all to give feedback on before I proceed.

I suspect @eddyb will have opinions.

EDIT: compiles now.

@tamird
Copy link
Contributor Author

tamird commented Nov 29, 2017

It turns out I can feed the .cpp files directly into bindgen, negating the need for most of the manual work of moving things into the header! Let me know if that's preferable.

@kennytm kennytm added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 29, 2017
@tamird tamird force-pushed the bindgen branch 3 times, most recently from 990372c to 9b6ca0a Compare November 29, 2017 12:48
@tamird
Copy link
Contributor Author

tamird commented Nov 29, 2017

Ah, there's no libclang on the builders. Maybe the generated bindings should just be checked in.

@tamird
Copy link
Contributor Author

tamird commented Nov 29, 2017

Anyway, I was able to bootstrap with this locally 🎉

extern "C" void LLVMRustMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD) {
wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD)));
extern "C" LLVMValueRef LLVMRustMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD) {
return wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here's the first mistake caught by this.

@cuviper
Copy link
Member

cuviper commented Nov 29, 2017

Ah, there's no libclang on the builders. Maybe the generated bindings should just be checked in.

Requiring libclang would also make it harder on third-party builders, like distros. I think it would make sense to have bindgen use as an optional feature. Then yes, either check in the bindings, or just use them as a sanity check on the current bindings.

@tamird
Copy link
Contributor Author

tamird commented Nov 29, 2017

@cuviper how would I plumb the optional feature through? It doesn't look like I can pass --features rustc_llvm/rebuild_bindings from the top level cargo invocation - would I have to plumb "rebuild_llvm_bindings" through the dependency tree?

@cuviper
Copy link
Member

cuviper commented Nov 29, 2017

would I have to plumb "rebuild_llvm_bindings" through the dependency tree?

Hmm, that's annoying.

It could just be a standalone crate in src/tools/ which performs bindgen. It would act basically like an early build script for rustc_llvm -- Cargo wouldn't know about it, but rustbuild could manage it and build/run it when enabled. This may even be better overall, since tools don't have to be rebuilt for each stage of the compiler bootstrap.

@tamird
Copy link
Contributor Author

tamird commented Nov 29, 2017 via email

@tamird
Copy link
Contributor Author

tamird commented Nov 29, 2017

Actually, that may not be so bad. I'm looking into it.

@tamird
Copy link
Contributor Author

tamird commented Nov 29, 2017

Eh, on second thought, I have no idea how bootstrap is organized. Perhaps someone more familiar with it could help with this part?

@eddyb
Copy link
Member

eddyb commented Nov 30, 2017

cc @alexcrichton

@bors
Copy link
Collaborator

bors commented Nov 30, 2017

☔ The latest upstream changes (presumably #46144) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton
Copy link
Member

Hm I think this requires a dependency on libclang, right? I think for that reason alone (unfortunately) I wouldn't want to take this route. If we want to validate the bindings then I think we should set up ctest which doesn't require any extra system dependencies.

@tamird
Copy link
Contributor Author

tamird commented Nov 30, 2017 via email

@alexcrichton
Copy link
Member

I would personally prefer to do validation rather than generation of bindings here myself, I've found handwritten bindings to be quite easy to maintain over time and it doesn't require contributors to get libclang set up or anything like that.

For rustbuild integration of verification it would probably look like a dedicated whole new test suite, I don't think it would fit into any of our existing test suites. You'd basically be twiddling with support in src/bootstrap/check.rs I believe.

@shepmaster
Copy link
Member

@tamird We haven't heard from you in over 7 days — will you be able to address the recent feedback about pivoting to a validation perspective?

@tamird
Copy link
Contributor Author

tamird commented Dec 9, 2017 via email

@aidanhs aidanhs added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 14, 2017
@alexcrichton
Copy link
Member

Ok it's been a few weeks now so I'm going to close this, but we can of course reconsider a resubmission!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants