-
Notifications
You must be signed in to change notification settings - Fork 768
feat(bpf2go): Export go binding generation #1475
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
Conversation
7f2f5cd
to
094ddd7
Compare
094ddd7
to
d0043ec
Compare
Moves the code to generate go bindings to its own dedicated package and export the necessary functions to use it in bpf2go. This change will make it possible to reuse this code in other tools, without having to compile the C programs. The behaviour of bpf2go is unchanged. Two additional changes were made: 1. The 'Module' parameter has been made an input to the code generation. Otherwise embedding the bindings package in another module would lead to incorrect import statements in the generated code. I fail to see the value of the 'debug' lookup, the only valid value is "github.com/cilium/ebpf", but maybe there are some cilium internal build constraints, so I left it configurable. 2. The function which transforms type names to go identifiers has been updated to deal with all caps names. These shouldn't be present in C code, but appear when using rust. The change ensures the field names in the bindings are idiomatic Go field names. Signed-off-by: Wouter Dullaert <[email protected]>
d0043ec
to
36cdcba
Compare
I made the I wanted to apply stronger normalization to the produced go identifiers, but this would result in a breaking change. |
Stumbling across this because I also need a solution for what's described in #1142 . I was about to fork and work on this myself, and then I saw that there is this PR here already 👍 ... However, I can also see that there is already #1448 as well. Personally, I like this solution here better because I think it's the right idea to move this to a dedicated package and keep it outside of the command/main package. @ti-mo and @lmb , it looks like some time has passed since the original discussion in #1142. This (non-breaking) change to bpf2go would help unblock others (like myself) without us needing to fork and maintain this repository ourselves. |
@wdullaer sorry it took so long. I took your code as a base and extended it to cover most of the interesting parts of bpf2go: #1494 I undid the two changes you proposed. I think the module should not be configurable, because we are generating a binding against the API of the |
I think you misunderstood why I made module configurable. I agree that it shouldn't be configurable, it should be hardcoded to current fallback value of I also don't understand why you do removed the Ident function again. |
Couple of reasons:
|
Fair enough on the separate change. For the validation of the returned string: since the input is a function, you can't guarantee you will exhaustively test the full state space. It is the responsibility of the caller to make sure that the function logic makes sense. If you're open to accepting the feature, I can supply another PR once #1448 merges. |
Moves the code to generate go bindings to its own dedicated package and export the necessary functions to use it in bpf2go.
This change will make it possible to reuse this code in other tools, without having to compile the C programs.
The behaviour of bpf2go is unchanged.
Two additional changes were made:
This approach was taken after reading the feedback in #1142