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: enable ebpf code reuse across go packages #1625

Closed
wants to merge 1 commit into from

Conversation

mejedi
Copy link
Contributor

@mejedi mejedi commented Dec 12, 2024

New -import command line option specifies golang packages to pull headers from. Scan packages for header files, and expose headers to clang. C code consumes headers by providing a go package path in include directive, e.g.

frob.c:
#include "example.org/foo/foo.h"

It is handy for sharing code between multiple ebpf blobs within a project. Even better, it enables sharing ebpf code between multiple projects using go modules as delivery vehicle.

"Build" dependencies are recorded in generated files so that "go mod tidy" can see them. Further, we don't check if -import refers to internal packages, but "go build" will.

@mejedi
Copy link
Contributor Author

mejedi commented Dec 12, 2024

Change to listing packages explicitly on command line with -import option.

Prior iteration (#1509) pulled them from the "magic" bpf2go.hfiles.go in the output directory.

New -import command line option specifies golang packages to pull
headers from. Scan packages for header files, and expose headers to
clang. C code consumes headers by providing a go package path in include
directive, e.g.

frob.c:
  #include "example.org/foo/foo.h"

It is handy for sharing code between multiple ebpf blobs within a
project. Even better, it enables sharing ebpf code between multiple
projects using go modules as delivery vehicle.

"Build" dependencies are recorded in generated files so that "go mod
tidy" can see them. Further, we don't check if -import refers to
internal packages, but "go build" will.

Signed-off-by: Nick Zavaritsky <[email protected]>
@mejedi mejedi force-pushed the bpf2go-ebpf-code-reuse-v3 branch from bda6995 to 4d85998 Compare December 25, 2024 09:08
@ti-mo
Copy link
Collaborator

ti-mo commented Feb 25, 2025

I don't think we want bpf2go to do C dependency management using Go packages as a vehicle. It's a great idea, but again not something the majority of users will need to leverage. This kind of stuff is also bound to be specific to the the user's code/package layout, so I don't see this translate to the masses.

Personally, I'd write a separate tool that can pull C headers from Go packages and roll it into a vfs artifact. (which is basically a tar) Then, call it using a //go:generate statement preceding bpf2go and specify the vfs path as a c flag.

@ti-mo ti-mo closed this Feb 25, 2025
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.

2 participants