add support for compilation with pylibbpf

Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
This commit is contained in:
2025-09-21 18:05:43 +05:30
parent a1bc813ec5
commit 28e6f97708
3 changed files with 18 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import os
import subprocess
import inspect
from pathlib import Path
from pylibbpf import BpfProgram
def find_bpf_chunks(tree):
@ -116,3 +117,17 @@ def compile():
], check=True)
print(f"Object written to {o_file}, {ll_file} can be removed")
def BPF() -> BpfProgram:
caller_frame = inspect.stack()[1]
caller_file = Path(caller_frame.filename).resolve()
ll_file = Path("/tmp") / caller_file.with_suffix(".ll").name
o_file = Path("/tmp") / caller_file.with_suffix(".o").name
compile_to_ir(str(caller_file), str(ll_file))
subprocess.run([
"llc", "-march=bpf", "-filetype=obj", "-O2",
str(ll_file), "-o", str(o_file)
], check=True)
return BpfProgram(str(o_file))