Skip to content

Commit 00b62f0

Browse files
committed
Depend on system package instead of vendoring
1 parent 4639806 commit 00b62f0

24 files changed

+77
-393
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/dune

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(executables
2-
(names bootstrap bootstrap_c kprobe minimal)
2+
(names sockfilter tc bootstrap bootstrap_c kprobe minimal)
33
(libraries ocaml_libbpf ocaml_libbpf_maps))
44

55
; Below is repetitive build rules to compile *.bpf.c eBPF C source code that runs in the kernel
@@ -10,11 +10,10 @@
1010
(targets minimal.bpf.o)
1111
(deps
1212
arch
13-
minimal.bpf.c
14-
%{project_root}/src/root/usr/include/bpf/bpf_helpers.h)
13+
minimal.bpf.c)
1514
(action
1615
(system
17-
"clang -g -O2 -target bpf -I%{project_root}/src/root/usr/include/ -I/usr/include/%{architecture}-linux-gnu/ -c minimal.bpf.c -D__TARGET_ARCH_%{read:arch}")))
16+
"clang -g -O2 -target bpf -I/usr/include/%{architecture}-linux-gnu/ -c minimal.bpf.c -D__TARGET_ARCH_%{read:arch}")))
1817

1918
(rule
2019
(mode
@@ -23,11 +22,22 @@
2322
(deps
2423
arch
2524
vmlinux.h
26-
kprobe.bpf.c
27-
%{project_root}/src/root/usr/include/bpf/bpf_helpers.h)
25+
kprobe.bpf.c)
2826
(action
2927
(system
30-
"clang -g -O2 -target bpf -I%{project_root}/src/root/usr/include/ -I/usr/include/%{architecture}-linux-gnu/ -c kprobe.bpf.c -D__TARGET_ARCH_%{read:arch}")))
28+
"clang -g -O2 -target bpf -I/usr/include/%{architecture}-linux-gnu/ -c kprobe.bpf.c -D__TARGET_ARCH_%{read:arch}")))
29+
30+
(rule
31+
(mode
32+
(promote (until-clean)))
33+
(targets tc.bpf.o)
34+
(deps
35+
arch
36+
vmlinux.h
37+
tc.bpf.c)
38+
(action
39+
(system
40+
"clang -g -O2 -target bpf -I/usr/include/%{architecture}-linux-gnu/ -c tc.bpf.c -D__TARGET_ARCH_%{read:arch}")))
3141

3242
(rule
3343
(mode
@@ -37,11 +47,10 @@
3747
arch
3848
vmlinux.h
3949
bootstrap.bpf.c
40-
bootstrap.h
41-
%{project_root}/src/root/usr/include/bpf/bpf_helpers.h)
50+
bootstrap.h)
4251
(action
4352
(system
44-
"clang -g -O2 -target bpf -I%{project_root}/src/root/usr/include/ -I/usr/include/%{architecture}-linux-gnu/ -c bootstrap.bpf.c -D__TARGET_ARCH_%{read:arch}")))
53+
"clang -g -O2 -target bpf -I/usr/include/%{architecture}-linux-gnu/ -c bootstrap.bpf.c -D__TARGET_ARCH_%{read:arch}")))
4554

4655
(rule
4756
(mode
@@ -57,5 +66,4 @@
5766
(bash
5867
"uname -m | sed 's/x86_64/x86/' | sed 's/arm.*/arm/' | sed 's/aarch64/arm64/' | sed 's/ppc64le/powerpc/' | sed 's/mips.*/mips/' | sed 's/riscv64/riscv/' | sed 's/loongarch64/loongarch/'")))))
5968

60-
; %{project_root}/src/root/usr/include/ Vendored libbpf headers
6169
; /usr/include/%{architecture}-linux-gnu/ Find asm/types.h for eBPF code

ocaml_libbpf.opam

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,24 @@ dev-repo: "git+https://github.com/koonwen/ocaml-libbpf.git"
3838
# Fix to kernel >= 5.15 to allow executing syscalls
3939
available: [ os = "linux" &
4040
(( os-distribution = "debian" & os-version >= "12" ) | # Linux 6.1
41-
( os-distribution = "ubuntu" & os-version >= "22.04" ) | # Linux 5.15
42-
( os-distribution = "fedora" & os-version >= "36" ) | # Linux 5.17
43-
( os-distribution = "opensuse-leap" & os-version >= "15.6" )) # Linux 6.14
41+
( os-distribution = "ubuntu" & os-version >= "23.04" ) | # Linux 6.2
42+
( os-distribution = "fedora" & os-version >= "38" ) | # Linux 6.2
43+
( os-distribution = "opensuse-leap" & os-version >= "15.6" )) # Linux 6.4
4444
]
4545

4646
# Need to extend to the rest of the linux distros
4747
depexts: [
48+
# libbpf
49+
["libbpf-dev"] {os-distribution = "ubuntu" # 1.1.0
50+
| os-distribution = "debian" # 1.1.0
51+
| os-distribution = "opensuse" } # 1.2.2
52+
["libbpf-devel"] {os-distribution = "fedora"} # 1.1.0
53+
4854
[ "linux-tools-common" ] {os-distribution = "ubuntu"}
49-
["bpftool"] {os-distribution = "debian" | "fedora"}
50-
["libelf-dev"] {os-distribution = "debian"| os-distribution = "ubuntu" }
51-
["libelf-devel"] {os-distribution = "opensuse"}
52-
["elfutils-libelf-devel"] {os-distribution = "fedora"}
55+
["bpftool"] {os-distribution = "debian" | "fedora" | "opensuse-leap" }
56+
57+
# # libelf
58+
# ["libelf-dev"] {os-distribution = "debian"| os-distribution = "ubuntu" }
59+
# ["libelf-devel"] {os-distribution = "opensuse"}
60+
# ["elfutils-libelf-devel"] {os-distribution = "fedora"}
5361
]

ocaml_libbpf.opam.template

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22
# Fix to kernel >= 5.15 to allow executing syscalls
33
available: [ os = "linux" &
44
(( os-distribution = "debian" & os-version >= "12" ) | # Linux 6.1
5-
( os-distribution = "ubuntu" & os-version >= "22.04" ) | # Linux 5.15
6-
( os-distribution = "fedora" & os-version >= "36" ) | # Linux 5.17
7-
( os-distribution = "opensuse-leap" & os-version >= "15.6" )) # Linux 6.14
5+
( os-distribution = "ubuntu" & os-version >= "23.04" ) | # Linux 6.2
6+
( os-distribution = "fedora" & os-version >= "38" ) | # Linux 6.2
7+
( os-distribution = "opensuse-leap" & os-version >= "15.6" )) # Linux 6.4
88
]
99

1010
# Need to extend to the rest of the linux distros
1111
depexts: [
12+
# libbpf
13+
["libbpf-dev"] {os-distribution = "ubuntu" # 1.1.0
14+
| os-distribution = "debian" # 1.1.0
15+
| os-distribution = "opensuse" } # 1.2.2
16+
["libbpf-devel"] {os-distribution = "fedora"} # 1.1.0
17+
1218
[ "linux-tools-common" ] {os-distribution = "ubuntu"}
13-
["bpftool"] {os-distribution = "debian" | "fedora"}
14-
["libelf-dev"] {os-distribution = "debian"| os-distribution = "ubuntu" }
15-
["libelf-devel"] {os-distribution = "opensuse"}
16-
["elfutils-libelf-devel"] {os-distribution = "fedora"}
19+
["bpftool"] {os-distribution = "debian" | "fedora" | "opensuse-leap" }
20+
21+
# # libelf
22+
# ["libelf-dev"] {os-distribution = "debian"| os-distribution = "ubuntu" }
23+
# ["libelf-devel"] {os-distribution = "opensuse"}
24+
# ["elfutils-libelf-devel"] {os-distribution = "fedora"}
1725
]

src/dune

Lines changed: 13 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,15 @@
1-
; Build vendored libbpf
2-
3-
(rule
4-
(deps
5-
(source_tree %{project_root}/vendor/libbpf))
6-
(targets
7-
libbpf.pc
8-
dllbpf.so
9-
libbpf.a
10-
bpf_core_read.h
11-
bpf_endian.h
12-
bpf.h
13-
bpf_helper_defs.h
14-
bpf_helpers.h
15-
bpf_tracing.h
16-
btf.h
17-
libbpf_common.h
18-
libbpf.h
19-
libbpf_legacy.h
20-
libbpf_version.h
21-
skel_internal.h
22-
usdt.bpf.h)
23-
(action
24-
(no-infer
25-
(progn
26-
(chdir
27-
%{project_root}/vendor/libbpf/src
28-
(progn
29-
(bash "mkdir build root")
30-
(run make OBJDIR=build DESTDIR=root install)))
31-
(copy %{project_root}/vendor/libbpf/src/build/libbpf.pc libbpf.pc)
32-
(copy %{project_root}/vendor/libbpf/src/build/libbpf.so dllbpf.so)
33-
(copy %{project_root}/vendor/libbpf/src/build/libbpf.a libbpf.a)
34-
(copy
35-
%{project_root}/vendor/libbpf/src/root/usr/include/bpf/bpf_core_read.h
36-
bpf_core_read.h)
37-
(copy
38-
%{project_root}/vendor/libbpf/src/root/usr/include/bpf/bpf_endian.h
39-
bpf_endian.h)
40-
(copy %{project_root}/vendor/libbpf/src/root/usr/include/bpf/bpf.h bpf.h)
41-
(copy
42-
%{project_root}/vendor/libbpf/src/root/usr/include/bpf/bpf_helper_defs.h
43-
bpf_helper_defs.h)
44-
(copy
45-
%{project_root}/vendor/libbpf/src/root/usr/include/bpf/bpf_helpers.h
46-
bpf_helpers.h)
47-
(copy
48-
%{project_root}/vendor/libbpf/src/root/usr/include/bpf/bpf_tracing.h
49-
bpf_tracing.h)
50-
(copy %{project_root}/vendor/libbpf/src/root/usr/include/bpf/btf.h btf.h)
51-
(copy
52-
%{project_root}/vendor/libbpf/src/root/usr/include/bpf/libbpf_common.h
53-
libbpf_common.h)
54-
(copy
55-
%{project_root}/vendor/libbpf/src/root/usr/include/bpf/libbpf.h
56-
libbpf.h)
57-
(copy
58-
%{project_root}/vendor/libbpf/src/root/usr/include/bpf/libbpf_legacy.h
59-
libbpf_legacy.h)
60-
(copy
61-
%{project_root}/vendor/libbpf/src/root/usr/include/bpf/libbpf_version.h
62-
libbpf_version.h)
63-
(copy
64-
%{project_root}/vendor/libbpf/src/root/usr/include/bpf/skel_internal.h
65-
skel_internal.h)
66-
(copy
67-
%{project_root}/vendor/libbpf/src/root/usr/include/bpf/usdt.bpf.h
68-
usdt.bpf.h)))))
69-
70-
; Everything below is the bindings generation process using ctypes. It produces
71-
; two OCaml modules, Libbpf_c_generated_functions and Libbpf_c_generated_types.
72-
73-
; Type bindings (Libbpf_c_generated_types).
74-
75-
; Functor of type descriptions to be used in stub generator
76-
; libbpf_c_type_descriptions.ml -> libbpf_c_type_descriptions.cma/cmxa/cmxs
77-
781
(library
79-
(name libbpf_c_type_descriptions)
80-
(public_name ocaml_libbpf.libbpf_c_type_descriptions)
81-
(modules libbpf_c_type_descriptions)
82-
(libraries ctypes))
83-
84-
; Compile types_bindings_stub_gen with Libbpf_c_type_description.Types
85-
; functor to output C generator from type descriptions
86-
; types_binding_stub_gen.ml + libbpf_c_type_descriptions.cma/cmxa/cmxa -> types_binding_stub_gen.exe
87-
88-
(executable
89-
(name gen_type_bindings)
90-
(modules gen_type_bindings)
91-
(libraries ctypes.stubs libbpf_c_type_descriptions))
92-
93-
; Run generator gen_type_bindings.exe to get c source file to generate OCaml module
94-
; gen_type_bindings.exe -> gen_type_bindings.c
95-
96-
(rule
97-
(targets gen_type_bindings.c)
98-
(deps libbpf.h)
99-
(action
100-
(run ./gen_type_bindings.exe)))
101-
102-
; Compile types_bindings_c_stub_gen.c
103-
; types_bindings_c_stub_gen.c -> gen_type_bindings.exe
104-
105-
(rule
106-
(targets gen_type_bindings_from_c.exe)
107-
(deps gen_type_bindings.c)
108-
(action
109-
(bash
110-
"%{cc} %{deps} -I `dirname %{lib:ctypes:ctypes_cstubs_internals.h}` -I %{ocaml_where} -o %{targets}")))
111-
112-
; Run generator gen_type_bindings.exe to get
113-
; libbpf_c_generated_types.ml
114-
; gen_type_bindings_from_c.exe -> libbpf_c_generated_types.ml
115-
116-
(rule
117-
(with-stdout-to
118-
libbpf_c_generated_types.ml
119-
(run ./gen_type_bindings_from_c.exe)))
120-
121-
; Function bindings.
122-
123-
(library
124-
(name libbpf_c_function_descriptions)
125-
(public_name ocaml_libbpf.libbpf_c_function_descriptions)
126-
(flags ; (:standard -w -9-16-27)
127-
)
128-
; (wrapped false)
129-
(modules libbpf_c_generated_types libbpf_c_function_descriptions)
130-
(libraries ctypes libbpf_c_type_descriptions))
131-
132-
; Compile gen_function_bindings
133-
134-
(executable
135-
(name gen_function_bindings)
136-
(modules gen_function_bindings)
137-
(libraries ctypes.stubs libbpf_c_function_descriptions))
138-
139-
; Generate both the function stubs and the generated functions
140-
141-
(rule
142-
(targets libbpf_stubs.c libbpf_c_generated_functions.ml)
143-
(deps gen_function_bindings.exe)
144-
(action
145-
(run %{deps})))
146-
147-
; This is so that we can collate the functions and type bindings
148-
149-
(library
150-
(name libbpf_bindings)
151-
(public_name ocaml_libbpf.libbpf_bindings)
152-
(libraries libbpf_c_function_descriptions)
153-
(modules libbpf_bindings libbpf_c_generated_functions))
154-
155-
; The Nicely packaged library for users
156-
157-
(library
158-
(name ocaml_libbpf)
1592
(public_name ocaml_libbpf)
160-
(foreign_archives bpf)
161-
(c_library_flags -lelf -lz)
162-
(foreign_stubs
163-
(language c)
164-
(names libbpf_stubs)
165-
(include_dirs root/usr/include))
166-
(libraries ctypes.stubs libbpf_bindings)
167-
(modules ocaml_libbpf))
3+
(ctypes
4+
(external_library_name libbpf)
5+
(build_flags_resolver pkg_config)
6+
(headers (include bpf/libbpf.h))
7+
(type_description
8+
(instance Types)
9+
(functor Type_description))
10+
(function_description
11+
(concurrency unlocked)
12+
(instance Functions)
13+
(functor Function_description))
14+
(generated_types Types_generated)
15+
(generated_entry_point C)))

0 commit comments

Comments
 (0)