mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
add support for compilation with pylibbpf
Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
This commit is contained in:
@ -16,7 +16,8 @@ requires-python = ">=3.8"
|
|||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"llvmlite",
|
"llvmlite",
|
||||||
"astpretty"
|
"astpretty",
|
||||||
|
"pylibbpf"
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.setuptools.packages.find]
|
[tool.setuptools.packages.find]
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
from .decorators import bpf, map, section, bpfglobal, struct
|
from .decorators import bpf, map, section, bpfglobal, struct
|
||||||
from .codegen import compile_to_ir, compile
|
from .codegen import compile_to_ir, compile, BPF
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import inspect
|
import inspect
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from pylibbpf import BpfProgram
|
||||||
|
|
||||||
|
|
||||||
def find_bpf_chunks(tree):
|
def find_bpf_chunks(tree):
|
||||||
@ -116,3 +117,17 @@ def compile():
|
|||||||
], check=True)
|
], check=True)
|
||||||
|
|
||||||
print(f"Object written to {o_file}, {ll_file} can be removed")
|
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))
|
||||||
|
|||||||
Reference in New Issue
Block a user