summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2016-09-16Rewrite the core of the binding generator.Emilio Cobos Álvarez
TL;DR: The binding generator is a mess as of right now. At first it was funny (in a "this is challenging" sense) to improve on it, but this is not sustainable. The truth is that the current architecture of the binding generator is a huge pile of hacks, so these few days I've been working on rewriting it with a few goals. 1) Have the hacks as contained and identified as possible. They're sometimes needed because how clang exposes the AST, but ideally those hacks are well identified and don't interact randomly with each others. As an example, in the current bindgen when scanning the parameters of a function that references a struct clones all the struct information, then if the struct name changes (because we mangle it), everything breaks. 2) Support extending the bindgen output without having to deal with clang. The way I'm aiming to do this is separating completely the parsing stage from the code generation one, and providing a single id for each item the binding generator provides. 3) No more random mutation of the internal representation from anywhere. That means no more Rc<RefCell<T>>, no more random circular references, no more borrow_state... nothing. 4) No more deduplication of declarations before code generation. Current bindgen has a stage, called `tag_dup_decl`[1], that takes care of deduplicating declarations. That's completely buggy, and for C++ it's a complete mess, since we YOLO modify the world. I've managed to take rid of this using the clang canonical declaration, and the definition, to avoid scanning any type/item twice. 5) Code generation should not modify any internal data structure. It can lookup things, traverse whatever it needs, but not modifying randomly. 6) Each item should have a canonical name, and a single source of mangling logic, and that should be computed from the inmutable state, at code generation. I've put a few canonical_name stuff in the code generation phase, but it's still not complete, and should change if I implement namespaces. Improvements pending until this can land: 1) Add support for missing core stuff, mainly generating functions (note that we parse the signatures for types correctly though), bitfields, generating C++ methods. 2) Add support for the necessary features that were added to work around some C++ pitfalls, like opaque types, etc... 3) Add support for the sugar that Manish added recently. 4) Optionally (and I guess this can land without it, because basically nobody uses it since it's so buggy), bring back namespace support. These are not completely trivial, but I think I can do them quite easily with the current architecture. I'm putting the current state of affairs here as a request for comments... Any thoughts? Note that there are still a few smells I want to eventually re-redesign, like the ParseError::Recurse thing, but until that happens I'm way happier with this kind of architecture. I'm keeping the old `parser.rs` and `gen.rs` in tree just for reference while I code, but they will go away. [1]: https://github.com/Yamakaky/rust-bindgen/blob/master/src/gen.rs#L448
2016-09-08Auto merge of #54 - vvuk:master, r=emiliobors-servo
Skip -isystem stuff if --target is specified, and don't strip leading _ on Windows The -isystem stuff fixes issue #53. Stripping leading _ on Windows is weird; it needs to not be stripped on MSVC (leading @), but on gcc at one point it needed to be. But now it no longer does. I don't know. 'cargo test' succeeds with mozjs bindings generated with these fixes.
2016-09-07Don't add -isystem header args when --target is specifiedVladimir Vukicevic
2016-09-07Only strip the prefix _ on macos; windows needs it on gnu as wellVladimir Vukicevic
2016-09-01Auto merge of #52 - servo:dedup-virtual-overloaded-names, r=emiliobors-servo
Deduplicate names of virtual overloaded methods. Fix #48 r? @emilio
2016-09-01Deduplicate names of virtual overloaded methods. Fix #48Simon Sapin
2016-08-30Auto merge of #45 - fitzgen:use-docopt-for-args, r=emiliobors-servo
Append the input header to the end of the clang args, instead of the front r @emilio
2016-08-30Append the input header to the end of the clang args, instead of the frontNick Fitzgerald
2016-08-27Auto merge of #44 - fitzgen:use-docopt-for-args, r=emiliobors-servo
Use docopt for argument parsing This commit switches bindgen over to using the docopt crate for argument parsing instead of manual argument parsing. This required two notable changes in the arguments and flags style: 1. All flags of the form `-foo` are now of the form `--foo`. 2. We can no longer pass unknown flags straight through to clang. Instead, the user appends `--` after the bindgen flags and input header, after which point any more flags and arguments get collected and passed to clang. This required changes to the test runner and the `// bindgen-flags` comments. r? @emilio
2016-08-26Use docopt for argument parsingNick Fitzgerald
This commit switches bindgen over to using the docopt crate for argument parsing instead of manual argument parsing. This required two notable changes in the arguments and flags style: 1. All flags of the form `-foo` are now of the form `--foo`. 2. We can no longer pass unknown flags straight through to clang. Instead, the user appends `--` after the bindgen flags and input header, after which point any more flags and arguments get collected and passed to clang. This required changes to the test runner and the `// bindgen-flags` comments.
2016-08-25Auto merge of #43 - fitzgen:document-testing, r=emiliobors-servo
Add description of how to run the tests to README.md Fixes #42 r? @emilio
2016-08-25Add description of how to run the tests to README.mdNick Fitzgerald
Fixes #42
2016-08-23Auto merge of #36 - fitzgen:expand-build-instructions, r=emiliobors-servo
Expand the build instructions when using llvm 3.9 r? @emilio
2016-08-22Make sure to mention the need to checkout and build clangNick Fitzgerald
2016-08-22Expand the build instructions when using llvm 3.9Nick Fitzgerald
2016-08-18Auto merge of #34 - upsuper:blacklist-typedef, r=emiliobors-servo
Allow blacklist typedef This allows making type aliases to be blacklisted.
2016-08-19Allow blacklist typedef.Xidorn Quan
2016-08-17Auto merge of #33 - emilio:union-dtor, r=Manishearthbors-servo
Unions with destructors. r? @Manishearth
2016-08-16tests: Add test for a union with explicit destructor.Emilio Cobos Álvarez
2016-08-16types: Don't avoid the destructor check when looking at unions.Emilio Cobos Álvarez
This is kind of unfortunate, but we weren't taking into account explicit destructors.
2016-08-16Auto merge of #29 - emilio:template-unions, r=noxbors-servo
Add support for basic template unions. Fixes #28. r? @nox cc @bholley
2016-08-15parser: If we find no declarations, check for primitive type before going ↵Emilio Cobos Álvarez
down the hack version.
2016-08-15types: Implement PartialEq in the Type trait looking at the values pointed ↵Emilio Cobos Álvarez
by Rc<T>s
2016-08-14Auto merge of #31 - emilio:testing, r=noxbors-servo
test: Add test for keywords from upstream. This is the only test that's missing from upstream apart from the `va_list` one, that produces similar output but doesn't compile in any of the versions.
2016-08-14test: Add test for keywords from upstream.Emilio Cobos Álvarez
2016-08-13Add test for union templates without using template parameters.Emilio Cobos Álvarez
2016-08-13Properly detect template<typename T> union ...Emilio Cobos Álvarez
2016-08-13Improve support for unions inside templated structs, or unions with template ↵Emilio Cobos Álvarez
parameters in general that don't use the template argument.
2016-08-13refactor: Take rid of CompMember::CompField, which was effectively dead ↵Emilio Cobos Álvarez
since I introduced support for anonymous structs.
2016-08-12Auto merge of #30 - Manishearth:ignore_methods, r=emiliobors-servo
Add ignore_methods to bindgen I'm defining a struct inline in ServoBindings.h via a macro (for the already_addrefed stuff), and I need to forbid its ignore_methods from getting generated without forbidding functions as well. r? @bholley
2016-08-12Add ignore_methods to bindgenManish Goregaokar
2016-07-26Auto merge of #20 - Manishearth:unsafe-field, r=Manishearthbors-servo
Add support for 'unsafe fields' Needed for the next step of https://github.com/servo/servo/pull/12521 These are fields which are private but have unsafe accessor functions. Since we generate bindings in a separate module, we can't touch private fields from other parts of the module (an alternative is to inject a footer with these private impls). `pub(restricted)` exists, but is not stable. r? @emilio
2016-07-26Add support for 'unsafe fields'Manish Goregaokar
2016-07-26Output diff from travisManish Goregaokar
2016-07-26Make it possible to run tests on El CapitanManish Goregaokar
2016-07-25Auto merge of #23 - emilio:crtp, r=noxbors-servo
Avoid recursing infinitely with CRTP while looking for a destructor. Fixes #22 r? @nox
2016-07-21Avoid recursing infinitely with CRTP while looking for a destructor.Emilio Cobos Álvarez
Fixes #22
2016-07-18Auto merge of #19 - upsuper:bump-clang-sys, r=KiChjangbors-servo
Bump clang-sys version to 0.8.0 To include the fix for Windows build.
2016-07-19Bump clang-sys version to 0.8.0Xidorn Quan
To include the fix for Windows build.
2016-07-18Auto merge of #18 - vvuk:rust-msvc, r=emiliobors-servo
Add support for generating MSVC bindings (using clang) This adds support for generating MSVC bindings, using clang's MSVC C++ ABI support. It requires a command line flag for selecting this binding due to an inability to pick up the msvc target triple.
2016-07-18Check method_is_virtual and flag has_vtable before deciding whether to skip ↵Vladimir Vukicevic
method
2016-07-18Add explicit option for selecting MSVC manglingVladimir Vukicevic
There's no easy way to get the current target triple from the clang-c bindings. Make this simple and require an option to be passed when generating bindings for msvc, using the x86_64-pc-win32 target (or i686)
2016-07-18Support MSVC mangled names (which have @ symbols in them) when generating ↵Vladimir Vukicevic
bindings
2016-07-17Auto merge of #15 - upsuper:fix-msvc, r=upsuperbors-servo
Some fixes to make it work with MSVC The last commit -- removing clang searching code, is not closely related. The reason its being there is that the C++ headers we need in geckolib require LLVM 3.9, which is pre-release, and thus it is usually necessary to setting `LIBCLANG_PATH` manually to get the proper clang library linked. However, the current searching code doesn't work well on Windows, because LLVM for Windows puts `libclang.dll` and `libclang.lib` in different directories, while you can only specify one of them in `LIBCLANG_PATH`. To fix this, I submitted some code in KyleMayes/clang-sys#34 (landed in development branch), and I don't want the searching code here to introduce any conflicts with the code there.
2016-07-18Remove clang searching code from build.rsXidorn Quan
The dependency clang-sys has been working hard to find and link with LLVM and Clang. It doesn't make sense to duplicate that work. Also, there could be undesired conflict if the searching code doesn't match exactly, and different libraries are found.
2016-07-18Restrict the undo mangling hack to gnu targetXidorn Quan
This is not needed at least for Clang 3.9 (which is required to parse stdlib headers of MSVC 2015). This hack leads to incorrect mangling result there.
2016-07-15Normalize header path to use unix sepXidorn Quan
Otherwise it would be hard to write uniform blacklist header list across platforms, especially given that on Windows, some part of path could be using '/' while others use '\'.
2016-07-10Auto merge of #14 - emilio:stable, r=noxbors-servo
Allow building bindgen with stable rust. Fixes #13 r? @nox cc @bholley
2016-07-10travis: test on rust stableEmilio Cobos Álvarez
2016-07-10Use aster and quasi to allow building with stable Rust.Emilio Cobos Álvarez