-
Notifications
You must be signed in to change notification settings - Fork 743
[WIP] reexport the static inline functions and TLS variables with C/CPP wrapper #1460
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f6e66d5
generate wrapper to reexport static inline functions
flier cd4d089
handle C pointer in result and argument
flier fd1ca61
provide c!{} and cpp!{} macros with build suppport
flier 1a6aaac
fix bindgen test cases
flier 6fd3ec5
generate getter/setter for TLS variables
flier 6b41289
handle typedef
flier 5400607
check clang_getCursorTLSKind is loaded for old LLVM
flier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
#![allow( | ||
dead_code, | ||
non_snake_case, | ||
non_camel_case_types, | ||
non_upper_case_globals | ||
)] | ||
|
||
c! { # include "generate-c-inline.h" } | ||
extern "C" { | ||
#[link_name = "\u{1}_foo"] | ||
pub fn foo(x: ::std::os::raw::c_int, y: ::std::os::raw::c_int) -> ::std::os::raw::c_int; | ||
} | ||
c! { int _foo ( const int x , const int y ) { return foo ( x , y ) ; } } | ||
extern "C" { | ||
#[link_name = "\u{1}_nop"] | ||
pub fn nop(); | ||
} | ||
c! { void _nop ( ) { nop ( ) ; } } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// bindgen-flags: --generate-inline-functions | ||
|
||
inline static int foo(const int x, const int y) { return x + y; } | ||
static int bar(const int x, const int y) { return x - y; } | ||
inline static void nop() { return; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ class Foo { | |
inline int foo() { | ||
return 42; | ||
} | ||
inline static int bar(const int x, const int y) { return x + y; } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do these macros come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rust-c has a simple
c! {}
implementation for C, and rust-cpp also providescpp! {}
macro for C++if you think the way is right, I could add a special implementation to
bindgen
, it need add some code tobuild.rs
, generate some.c
/.cpp
file on building.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it may be ok to depend on external crates, but then it should be documented and obviously not on-by-default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After read the
rust_c
andrust-cpp
crates, I believe we only need a very simple implementation likeand a
bindgen-build
crate be added to support extract and build C/C++ code in the build script.You can check a real example that includes hundreds of static inline functions with some build script, like
besides, I added some code to handle the deprecated functions, like
and the generated C/C++ file like
What's your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
besides, with the C/C++ wrapper, we could reexport the thread local variable to solve #1187
could generate the getter/setter functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach works, but there's a lot of unanswered questions related to mangling and such...
I'm sorry for having missed this, btw :(
Maybe a better approach would be to instead add a
ParseCallback
when we see a thread-local variable, in order to let the caller to do whatever they want with it, since this seems like a pretty opinionated solution to the problem.That would allow us not to depend on
c!
/cpp!
in any way.