-
Notifications
You must be signed in to change notification settings - Fork 154
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
Generating Rust bindings which include a type named String doesn't compile #1371
Comments
Please file a test case PR following these instructions. Unfortunately all the stuff around names in autocxx is very fragile so this might not be an easy fix. |
Added a test in #1402 I was able to create a simpler reproducible test case, I believe it's just name conflicts with the default prelude, using a different struct name other than |
Is there a workaround for this if it's not possible to rename the String class we're binding to? |
This is severely blocking progress for me and I haven't found a great workaround. I was able to write manual bindings for the I'm wondering if making it possible to specify an alternate name in the |
I'd accept a PR to fix this. To be honest just having a PR which I can use to reproduce the problem in a test case might be enough for me to take a look. #1402 is the right sort of thing but I can't merge it due to the contributor not signing the (admittedly annoying) Google CLA. There's a 50/50 chance that this is an easy fix, versus a bit of a nightmare which requires revisiting all the fragile naming stuff that I've been failing to rework for years. |
Adds one passing test and one currently failing test, the only difference being the name of the class.
Adds one passing test and one currently failing test, the only difference being the name of the class.
I've actually just come up with a decent workaround by combining the following: manual bindings to my Now I'm able to generate other classes which have a few methods that accept/return So, this is no longer urgent for me, although it would be nice it were fixed. P.s. thank you Adrian for all of your hard work on this crate, in most cases it works spectacularly well and has saved me a ton of work! |
Thanks - I'm glad you found a workaround. As I mentioned, the naming stuff is annoyingly fragile, and unfortunately I think providing custom names for stuff falls into the category of "stuff I'm not quite brave enough to touch" until more work is done to clean it up - specifically a bunch of newtype wrappers for the different kinds of name we hold, which is roughly the thing tracked in #520. |
This is an internal change which begins to dig us out of the mess of naming we have inside autocxx. We deal with all sorts of different kinds of identifiers - for Rust, for cxx, for C++, from bindgen - and convert between them in a fairly ad-hoc basis. It's all too fragile to be able to tackle changes like #1371. Fortunately, Rust makes it easy to solve these sorts of messes using newtype wrappers. Unfortunately, I've tried that in the past and it's got to be a huge muddle. Here's another attempt at carving off part of the space. This introduces such wrappers for two types of name: * The [bindgen_original_name] identifiers discovered in bindgen attributes; * The final name to be used for C++ function calls. There are various FIXMEs added in locations where we're converting to or from other types of name in questionable ways. A bit of #520.
This is an internal change which begins to dig us out of the mess of naming we have inside autocxx. We deal with all sorts of different kinds of identifiers - for Rust, for cxx, for C++, from bindgen - and convert between them in a fairly ad-hoc basis. It's all too fragile to be able to tackle changes like #1371. Fortunately, Rust makes it easy to solve these sorts of messes using newtype wrappers. Unfortunately, I've tried that in the past and it's got to be a huge muddle. Here's another attempt at carving off part of the space. This introduces such wrappers for two types of name: * The [bindgen_original_name] identifiers discovered in bindgen attributes; * The final name to be used for C++ function calls. There are various FIXMEs added in locations where we're converting to or from other types of name in questionable ways. A bit of #520.
I've now dug into #520 enough to refresh my memory of the naming stuff, and what it would take to fix this. I'm not likely to tackle this myself, but here's what it would take. Each of these steps can be a separate PR. This would improve the maintainability of the codebase so I'm in favour of it; it's just not near the top of my priority list for the limited time I can personally spend on autocxx.
This is all pretty major surgery but I have a reasonable amount of faith that the hundreds of integration tests will catch most of the corner cases, so it should be achievable. Meanwhile it's quite possible that I'll raise a PR to simply reject APIs called |
Describe the bug
When trying to generate bindings to a type with the name String I get the error
In my particular case the String type is being incidentally generated because it is being returned from another function. But it will reproduce when directly generating the type named String as well.
To Reproduce
I created a minimized example which reproduces this behaviour with a header named
test.h
Additional notes
I did some initial digging and found that the
cxxbridge
that autocxx is generating containswithout the corresponding
type String = super::bindgen::root::tester::String;
declaration (which appears later). If these lines are removed then compilation will fail withcxx0.h
containing a function conversion which attempts to return arust::String
instead oftester::String
.I am happy to continue to explore/fix this problem, but I would like some guidance on where I should look to find the String -> rust::String conversion machinery.
The text was updated successfully, but these errors were encountered: