-
Notifications
You must be signed in to change notification settings - Fork 742
Wrapped statics should generate more portable code #2445
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
I don't see why can't we use
So yes, this was done because mangling on macos was messing up the linking because a I don't have anything against removing the labeling syntax if we can make this work in linux and macos. Maybe we can just ask clang to mangle the name before generating the code or something. This issue doesn't happen on linux and I don't have any apple hardware so testing will be slow. About portability, well I mean, The good news is that the feature is experimental so we don't need to be strict about breaking changes, What do you think? |
Regarding |
I'm not sure how most folks are using bindgen, but at least the way I've used it in the linux kernel and also boringssl, we have a single |
I would assume the generated C file, in that mode, just don't work at all because the generated file would have no way to get at the inline functions. Though I suppose bindgen could just paste the raw C code in front? But I don't know how people who do it that way use it, so I'm not sure.
I was actually thinking something simpler. Any reason not to just do it like this? extern "C" {
#[link_name = "inline_func__extern"]
pub fn inline_func();
}
extern "C" {
pub fn not_inline_func();
} void inline_func__extern(void);
void inline_func__extern(void) { return inline_func(); } That is, based on #1063, it sounds like removing the |
Yeah I think that for 99.9% of users that's the case. Happy to see you in the discussion as you're the only person I know of using this feature in a real life scenario :P
Injecting that code is definitely something we could do without issue. I think that little issue is solved. I'll start working on
Yeah we could "enable" mangling for It seems we have a plan! Thanks you two for your opinions. See you on review/testing/release :P Let me know if anything else comes up as this is code I'm very familiar so we can iterate over it quickly. |
Well... integration tests are passing 🎉 Let me know if you can compile your projects with these changes. |
Input C/C++ Header
Bindgen Invocation
Actual Results
Expected Results
The output uses GCC
asm
labels and is missing an include ofheader.h
. This seems to make it needlessly difficult to integrate into a project:-include
to forcibly include the header. This isn't a standard flag and won't work if, say, building with MSVC.asm
label syntax to change the symbol bypasses the platform's underlying name mangling mechanism (e.g. C symbols are underscore-prefixed on darwin), and also breaks if building with a non-GCC-compatible compiler.Is there a reason the feature was designed this way?
Adding the include seems a straightforward way to stick to standard C mechanisms.
The non-inline function doesn't require any decoration, so clearly bindgen and rustc are perfectly capable of handling the normal C mangling. If the aim was just so the Rust symbol appears as
inline_func
instead ofinline_func__extern
, #1063 suggests that, by default,link_name
still does the default C mangling.The text was updated successfully, but these errors were encountered: