-
Notifications
You must be signed in to change notification settings - Fork 743
libbindgen: error: expected type, found keyword type
#342
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
Comments
Can you paste or upload the |
That usually means that there's some template magic we can't support in rust. We can try to fix this case if it's not too painful, but otherwise the alternatives are to use the whitelisting/blacklisting APIs to deal with that. |
Oh, and thanks for the reports, they're really helpful :) |
Yeah, so it's trying to generate the whole STL, that is something that #[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct std_pointer_to_unary_function<_Arg, _Result> {
pub _M_ptr: ::std::option::Option<unsafe extern "C" fn(arg1: _Arg)
-> type-parameter-0-1>,
pub _phantom_1: ::std::marker::PhantomData<_Result>,
} We can try to fix those particular issues, but for C++ libraries it's .whitelist_type("Cv.*")
.whitelist_function("cv.*) should do the trick :) |
It worked for Now I have two other cases:
|
Nice, the rest are fallout from recent changes. Should be fixed with #344. |
We didn't have a test for inline destructors, and it bited us :P |
Also, I didn't notice that the opencv library used namespaces, bindgen has support for those, in case of name conflicts. We plan to enable them by default sometime soon, and since both SpiderMonkey and Gecko are using bindgen with that feature enabled, I'm pretty confident they'd be solid enough for OpenCv. |
Do you mean With your 'fix-dtors' branch (and still using
|
So the untagged union thing is that we prefer to generate those if we can given we can support more nasty stuff like template parameters in unions properly. But since it's only nightly rust by default, you can override that with I'm really surprised about the double That being said, I've been able to generate bindings for OpenCv with the following bits: let bindings = Builder::default()
.no_unstable_rust()
.header("wrapper.h")
.clang_arg("-x")
.clang_arg("c++")
.opaque_type("std::char_traits")
.enable_cxx_namespaces()
.no_unstable_rust()
.whitelisted_function("cv.*")
.whitelisted_type("Cv.*")
.whitelisted_type("cv::.*")
.generate()
.expect("Unable to generate bindings"); The whitelisting can probably get smarter, and you can cut-off parts of the API you don't want with the opaque/blacklisting APIs. |
Oh, forgot to mention that the patches in #346 are needed. |
Nice, thanks!! By the way some tests are failing when I run |
Also, are the warnings normal?
|
Yes, unfortunately stuff that uses |
That's rust-lang/rust#34798. Regarding the type size and alignment failures, I hadn't taken a look at them. I'd need to rewrite the crate since I deleted it, but was easy enough last time, so I'll re-do it :) |
So the failures are mostly expected. On one hand, there's a failure with the template<typename _Tp> class Scalar_ : public Vec<_Tp, 4> The other ones are the All the rest are derived from those. There's additionally the If you find one of these problems, there are multiple ways to work around the problem, depending on needs. If you don't need to access the members, the easiest thing is marking stuff as opaque. Marking a type as opaque tries to replace that type with a proper replacement in each situation. For example: .opaque_type("std::vector") Would fix a bunch of tests, and replace the fields with properly-aligned arrays in rust. Other possible workaround/fix, for when you need access to the type's field, would be using replacements. For example, I know that I could make the /**
* <div rustbindgen replaces="std::vector"></div>
*/
template<typename T, typename Alloc>
class vector_replacement {
T* start;
T* end;
T* storage_end;
};
#include <opencv2/core.hpp> That will replace the definition of Combining those configuration options, you can ensure the layout of your types is correct, even when bindgen can't quite do the correct thing. I'm not sure if I missed something (this should probably be documented in a more visible place). @fitzgen may correct me if I'm wrong. |
Yeah, I think we need a users' guide. I've been kind of meaning to write one, but (a) I have higher priorities (sorta lame excuse) and (b) we've been overhauling a lot of this stuff frequently (eg "_" => "::" in replacements and whitelisting etc). I think maybe if we (I? you? :P) make a skeleton of a guide, people can start helping to contribute. But I do think we need the skeleton first to act as a framework for others who want to jump in and help. |
I think we can close this issue, as it seems we have a users' guide now and there doesn't seem to be much left here that is actionable. |
rustc 1.15.0-nightly (daf8c1dfc 2016-12-05)
libbindgen = "0.1.2"
clang 3.9.0-3
opencv 3.1.0-6
Arch Linux 64-bit
wrapper.hpp
build.rs
The text was updated successfully, but these errors were encountered: