You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Each Rust Item has a path that includes the crate and mods needed to get to it. Currently cbindgen just ignores all segments of a path except the last one, which is the name of the item.
This works as long as there are no duplicates in different modules, but isn't correct and will probably cause someone an issue someday.
Reacted by Kévin Lefèvre, Stefan Lau, Adam Rzepka, Joseph Price and UebelAndre
Unfortunately, I'm not sure there is a workaround yet besides renaming the types. My first thought would have been to use the structs behind type aliases with different names, but that won't work if you want to expose them..
I don't currently have specific plans on implementing this. Unfortunately this is a tricky issue with a couple different options.
Implement a custom path resolution algorithm on top of syn
Use rls-analysis to hook into the work going on there for goto definition
Write a rustc integration to get this data
I've been told by @gankro that option 1 is not going to be fun as this is a very complicated and not well understood part of rustc and has evolved. I think this part of the rust reference is relevant.
Using rls-analysis could be viable, but needs investigation. My concern with using rls would be if it is using a lossy/mostly correct goto definition feature and not focused on strict correctness.
@UebelAndre A look at the diff shows that the PR replaces the use of bare strings with
pubstructPath{name:String,}
As such the PR has improved type-safety, but has not actually made the jump from "name-based" to "full qualified path-based", unlike what the name might suggest.
(where the parse section of the cbindgen config carefully doesn't include either of the load or emit crates)
This only works in my specific case because these types are opaque (they're always provided behind a pointer). I don't know a workaround for non-opaque types.
Activity
eqrion commentedon Oct 10, 2017
My comments earlier were wrong.
cbindgenused to refuse to parse paths that had multiple segments. This wasn't great so I fixed it in 0155728.AdamRzepka commentedon May 21, 2018
Any updates on this? I've got multiple
struct Configs in different modules and want to export them all.eqrion commentedon May 21, 2018
Unfortunately, I'm not sure there is a workaround yet besides renaming the types. My first thought would have been to use the structs behind type aliases with different names, but that won't work if you want to expose them..
I don't currently have specific plans on implementing this. Unfortunately this is a tricky issue with a couple different options.
I've been told by @gankro that option 1 is not going to be fun as this is a very complicated and not well understood part of rustc and has evolved. I think this part of the rust reference is relevant.
Using rls-analysis could be viable, but needs investigation. My concern with using rls would be if it is using a lossy/mostly correct goto definition feature and not focused on strict correctness.
I have no idea of how feasible option 3 would be.
[-]Handle item paths better[/-][+]Handle fully qualified paths and `use` aliases[/+]regexident commentedon Aug 22, 2018
Issue: Import renames à la
use Foo as Bar;are not resolved properly.A minimalistic crate like this …
Details
… generates a header like this …
Details
… emitting the following warning:
… while it should generate something like this instead:
What's wrong:
Foois used in an exportedfnthus does not generate it._bar: &Baris not properly resolved to_bar: &Fooin the function argument.(Cross-posted from #200, which was closed in favor of this original issue)
regexident commentedon Aug 22, 2018
Issue: Incorrect type resolving for differently scoped types of same name.
A minimalistic crate like this …
Details
… generates a header like this …
Details
… while it should generate something like this instead:
What's wrong:
Foobar<T>is not used in any exportedfnand hence shouldn't be generated.Foobarhowever is used in an exportedfnand hence should be generated.Observations:
mod fooandmod barmakes it behave correctly.#[repr(C)]tobar::Foobarmakes it behave correctly, strangely enough.<T>doesn't seem to be strictly necessary for triggering this bug, but makes things easier to spot in the generated header.(Cross-posted from #199, which was closed in favor of this original issue)
regexident commentedon Aug 22, 2018
I just pushed a PR (#201) that aims to move us a bit closer towards a direction of fixing this.
ysangkok commentedon Oct 13, 2018
This is an issue with https://github.com/KZen-networks/multi-party-ecdsa
saschanaz commentedon May 9, 2020
Did #233 fix this?
emilio commentedon Sep 28, 2020
Not really, though it added the infrastructure to potentially do it.
UebelAndre commentedon Nov 30, 2020
Any updates here? Would love to see this implemented 🙏
UebelAndre commentedon Dec 7, 2020
Can you elaborate on this a bit? I know nothing about the internals of this project but would really like to see this feature implemented 😅
regexident commentedon Dec 7, 2020
@UebelAndre A look at the diff shows that the PR replaces the use of bare strings with
As such the PR has improved type-safety, but has not actually made the jump from "name-based" to "full qualified path-based", unlike what the name might suggest.
fix(rtc_types::enclave_messages): work around cbindgen generic type h…
fix(rtc_types::enclave_messages): work around cbindgen generic type h…
fix(rtc_types::enclave_messages): work around cbindgen generic type h…
aidanhs commentedon Nov 10, 2023
My workaround for the "Issue: Import renames à la use Foo as Bar; are not resolved properly." issue is a macro for opaque newtype wrapping.
(where the
parsesection of the cbindgen config carefully doesn't include either of theloadoremitcrates)This only works in my specific case because these types are opaque (they're always provided behind a pointer). I don't know a workaround for non-opaque types.
lu-zero commentedon Aug 11, 2024
hyper has plenty of structs named
Senderacross its codebase if you want yet another case study.