Commit 61fdef4
authored
refactor(ebpf): add Bazel convenience targets, remove Python verification glue (#48667)
### What does this PR do?
Migrates runtime compilation bundles from Ninja to Bazel, adds central convenience targets, and removes Python verification glue code.
**Runtime compilation bundle migration (Ninja → Bazel):**
- Introduces `runtime_compilation_bundle` macro in `bazel/rules/ebpf/runtime_compilation.bzl` that chains `include_headers` → `integrity` to produce flattened `.c` files and Go integrity hash `.go` files.
- Removes `ninja_runtime_compilation_files()` and its Ninja rules (`headerincl`, `integrity`, `rctool`) from `tasks/system_probe.py`. The Linux branch of `ninja_generate()` is now a no-op — runtime compilation is fully handled by Bazel.
- Expands `bazel_build_ebpf()` to build `_BAZEL_RUNTIME_FLAT_TARGETS` and `_BAZEL_RUNTIME_GEN_TARGETS`, then copies flattened `.c` files to `pkg/ebpf/bytecode/build/runtime/` and `.go` hash files to `pkg/ebpf/bytecode/runtime/`.
- Updates `save_build_outputs()` to include both flattened `.c` files and `.go` hash files in the CI tarball artifact, so omnibus `go build` and packaging can find them.
- Keeps `go:generate` directives in the 9 source files as a fallback for `go build` users.
**Convenience targets:**
- **`//pkg/ebpf:all_ebpf_programs`** — a `filegroup` that collects every eBPF `.o` (prebuilt, CO-RE, inplace) and runtime flattened `.c` file, enabling a single `bazel build` invocation for all eBPF artifacts.
- **`//pkg/ebpf:verify_generated_files`** — a `test_suite` aggregating all `write_source_file` diff tests (Linux/Windows cgo godefs), runnable with a single `bazel test` command.
**Python glue removal:**
- Removed `_BAZEL_CGO_GODEFS_TARGETS`, `_BAZEL_CGO_GODEFS_WIN_TARGETS`, and `_bazel_verify_cgo_godefs()` / `_godefs_test_targets()` helper functions from `tasks/system_probe.py` (~60 lines).
- Replaced inline verification in `build_object_files()` with a single `bazel test //pkg/ebpf:verify_generated_files` call that works on both Linux and Windows.
- Added the same verification call in `build_cws_object_files()` and `kmt.build_object_files()`.
**Macro visibility cleanup:**
- All three eBPF macros (`ebpf_prog`, `ebpf_program_suite`, `cgo_godefs`, `runtime_compilation_bundle`) now pass `visibility` through from callers instead of hardcoding `["//visibility:public"]`. All ~60 callsites explicitly set `visibility = ["//visibility:public"]`.
- Set `--skip_incompatible_explicit_targets` globally in `.bazelrc` so `target_compatible_with` silently skips platform-incompatible targets.
### Motivation
The Python orchestration in `tasks/system_probe.py` maintained ~100 lines of target lists and helper functions for both cgo godefs verification and runtime compilation. This was fragile (target lists had to stay in sync with BUILD files) and was the last remaining Ninja workload on Linux. Moving verification into a Bazel `test_suite` and runtime compilation into a Bazel macro:
- Eliminates the Ninja dependency for Linux runtime compilation builds
- Eliminates a class of sync bugs between Python and Bazel
- Reduces Python glue code as part of the broader effort to minimize invoke task complexity
- Gives developers simple one-liner commands for common workflows
### Describe how you validated your changes
- Verified `bazel query` resolves both new targets and all their transitive dependencies
- Confirmed `--skip_incompatible_explicit_targets` correctly skips Linux-only targets on macOS without errors
- CI: buildifier, eBPF object builds, cgo godefs verification, omnibus packaging, and KMT functional tests all pass
- KMT `TestGRPCScenarios/runtime_compiled` exercises runtime compilation end-to-end (flattened `.c` → clang compile → eBPF load) — confirms Bazel-produced bundles work correctly
### Additional Notes
The `_BAZEL_EBPF_INPLACE_TARGETS`, `_BAZEL_EBPF_CORE_TARGETS`, and `_BAZEL_EBPF_PREBUILT_TARGETS` Python lists in `tasks/system_probe.py` remain — they drive the `_copy_output` logic that maps Bazel outputs to specific staging directories with `.stripped` variant handling, which a simple `filegroup` cannot express. Removing those requires a different approach (e.g., `pkg_install` rules or a Bazel run target that does the copying).
Runtime compilation hash `.go` files remain `.gitignore`d — they are generated by Bazel during the build and copied to the source tree, but not committed. To update them locally: `bazel run //pkg/ebpf/bytecode:<name>_verify`.
Co-authored-by: joseph.gette <joseph.gette@datadoghq.com>1 parent 94bc64e commit 61fdef4
44 files changed
Lines changed: 424 additions & 178 deletions
File tree
- bazel/rules/ebpf
- cmd/system-probe/subcommands/ebpf/testdata
- pkg
- collector/corechecks/ebpf
- c/runtime
- probe
- ebpfcheck
- noisyneighbor
- oomkill
- tcpqueuelength
- dyninst
- ebpf
- loader
- output
- ebpf
- bytecode
- runtime
- c
- kernelbugs/c
- telemetry
- testdata/c
- gpu/ebpf
- c/runtime
- network
- driver
- ebpf
- c
- co-re
- prebuilt
- runtime
- protocols
- events
- http2
- http
- gotls
- kafka
- postgres/ebpf
- redis
- tls
- tracer/offsetguess
- security/ebpf/c/prebuilt
- windowsdriver/procmon
- tasks
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
111 | 144 | | |
112 | 145 | | |
113 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
2 | 8 | | |
3 | 9 | | |
| 10 | + | |
4 | 11 | | |
5 | | - | |
| 12 | + | |
6 | 13 | | |
7 | 14 | | |
8 | 15 | | |
| 16 | + | |
9 | 17 | | |
10 | 18 | | |
11 | 19 | | |
| |||
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
| 44 | + | |
36 | 45 | | |
37 | | - | |
| 46 | + | |
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
41 | 50 | | |
42 | 51 | | |
43 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
44 | 64 | | |
45 | 65 | | |
46 | 66 | | |
47 | 67 | | |
48 | 68 | | |
49 | 69 | | |
50 | 70 | | |
| 71 | + | |
51 | 72 | | |
52 | 73 | | |
53 | 74 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
97 | 99 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
102 | 108 | | |
103 | | - | |
104 | | - | |
105 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
106 | 113 | | |
107 | 114 | | |
108 | 115 | | |
| |||
116 | 123 | | |
117 | 124 | | |
118 | 125 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
126 | 129 | | |
127 | 130 | | |
128 | | - | |
| 131 | + | |
| 132 | + | |
129 | 133 | | |
130 | 134 | | |
131 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| |||
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
| 61 | + | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
0 commit comments