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 #1509

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mejedi
Copy link
Contributor

@mejedi mejedi commented Jul 10, 2024

Extract imports from "bpf2go.hfiles.go" in the output dir, 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.

bpf2go.hfiles.go:
  package awesome
  import (
    _ "example.org/foo"
  )

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.

By listing build dependencies in a .go file, we ensure that they are properly reflected in go.mod.

@mejedi mejedi requested a review from lmb July 10, 2024 09:32
cmd/bpf2go/vfs.go Show resolved Hide resolved
cmd/bpf2go/main.go Outdated Show resolved Hide resolved
@mejedi mejedi force-pushed the bpf2go-ebpf-code-reuse-v2 branch 2 times, most recently from 1576cb6 to c27e4b3 Compare October 29, 2024 19:14
@mejedi mejedi changed the title bpf2go: enable ebpf code reuse across go packages (WIP) bpf2go: enable ebpf code reuse across go packages Oct 29, 2024
@mejedi mejedi marked this pull request as ready for review October 29, 2024 19:49
Extract imports from "bpf2go.hfiles.go" in the output dir, 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.

bpf2go.hfiles.go:
  package awesome
  import (
    _ "example.org/foo"
  )

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

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

By listing build dependencies in a .go file, we ensure that they are
properly reflected in go.mod.

Signed-off-by: Nick Zavaritsky <mejedi@gmail.com>
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