Skip to content
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

bpf2go: export core functionality #1494

Merged
merged 3 commits into from
Jun 24, 2024
Merged

bpf2go: export core functionality #1494

merged 3 commits into from
Jun 24, 2024

Conversation

lmb
Copy link
Collaborator

@lmb lmb commented Jun 21, 2024

bpf2go: export binding generator

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.

[ Lorenz: move code and backed out changes around module and identifier.
 These can come later, with tests. ]

Co-developed-by: Lorenz Bauer <lmb@isovalent.com>
Signed-off-by: Wouter Dullaert <wouter.dullaert@exoscale.ch>

bpf2go: export compilation

Move the code necessary to compile a C to an ELF. The behaviour of bpf2go is
unchanged.

The code to fix up make-style depfiles remains in bpf2go since it has little
tests, and is probably used only seldomly.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

bpf2go: export targets

Move target and force users to use one of the predefined targets. Also
export logic to generate build contraints from goarches.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

return "github.com/cilium/ebpf"
}

return bi.Main.Path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://pkg.go.dev/runtime/debug#BuildInfo

This means that any outside program trying to use the code template will insert its own package instead of github.com/cilium/ebpf.
So even though the template functions are now public, it is not possible to use them outside of this repo and generate functional bindings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, good point. I guess removing the parameter outright it is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing this properly is a headache as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goodbye BuildInfo, it was probably a bad idea from the start.

@lmb lmb force-pushed the export-bpf2go branch 3 times, most recently from 88c83d4 to 20f267d Compare June 24, 2024 14:09
@lmb
Copy link
Collaborator Author

lmb commented Jun 24, 2024

@wdullaer does this work for you now (sans the identifier stuff)?

@wdullaer
Copy link
Contributor

Looks great. I appreciate the speedy follow up!

wdullaer and others added 3 commits June 24, 2024 17:08
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.

[ Lorenz: move code and backed out changes around module and identifier.
  These can come later, with tests. ]

Co-authored-by: Lorenz Bauer <lmb@isovalent.com>
Signed-off-by: Wouter Dullaert <wouter.dullaert@exoscale.ch>
Move the code necessary to compile a C to an ELF. The behaviour of
bpf2go is unchanged.

The code to fix up make-style depfiles remains in bpf2go since it
has little tests, and is probably used only seldomly.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
Move target and force users to use one of the predefined targets.
Also export logic to generate build contraints from goarches.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
@lmb lmb merged commit 13a828e into cilium:main Jun 24, 2024
17 checks passed
@lmb lmb deleted the export-bpf2go branch June 24, 2024 16:17
@mheese
Copy link

mheese commented Jun 24, 2024

@lmb @wdullaer thanks for this guys! greatly appreciated 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants