Add libbpf as a submodule

This is to potentinally reduce issues with folks using
different versions of libbpf at runtime.
This commit is contained in:
Jordan Rome 2024-02-28 08:03:01 -08:00
parent 4dfb898a08
commit 626e66686a
5 changed files with 36 additions and 8 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "libbpf"]
path = libbpf
url = https://github.com/libbpf/libbpf

View File

@ -198,7 +198,7 @@ repo](https://mesonbuild.com/Quick-guide.html#installation-from-source) and call
standard utilities including `awk`. standard utilities including `awk`.
- `clang`: >=16 required, >=17 recommended - `clang`: >=16 required, >=17 recommended
- `libbpf`: >=1.2.2 required, >=1.3 recommended (`RESIZE_ARRAY` support is - `libbpf`: >=1.2.2 required, >=1.3 recommended (`RESIZE_ARRAY` support is
new in 1.3) new in 1.3). It's preferred to link statically against the source from the libbpf git submodule.
- Rust toolchain: >=1.72 - Rust toolchain: >=1.72
- `libelf`, `libz`, `libzstd` if linking against staic `libbpf.a` - `libelf`, `libz`, `libzstd` if linking against staic `libbpf.a`
- `bpftool` (usually available in `linux-tools-common`) - `bpftool` (usually available in `linux-tools-common`)
@ -210,9 +210,21 @@ repo](https://mesonbuild.com/Quick-guide.html#installation-from-source) and call
commands in the root of the tree builds and installs all schedulers under commands in the root of the tree builds and installs all schedulers under
`~/bin`. `~/bin`.
#### Static linking against libbpf submodule (preferred)
```
$ cd $SCX
$ git submodule init
$ make -C libbpf/src
$ meson setup build --prefix ~
$ meson compile -C build
$ meson install -C build
```
#### Dynamic linking against libbpf
``` ```
$ cd $SCX $ cd $SCX
$ meson setup build --prefix ~ $ meson setup build --prefix ~ -D libbpf_a=disabled
$ meson compile -C build $ meson compile -C build
$ meson install -C build $ meson install -C build
``` ```

1
libbpf Submodule

@ -0,0 +1 @@
Subproject commit 20c0a9e3d7e7d4aeb283eae982543c9cacc29477

View File

@ -44,9 +44,21 @@ elif bpf_clang_maj < 17
.format(bpf_clang.full_path(), bpf_clang_ver)) .format(bpf_clang.full_path(), bpf_clang_ver))
endif endif
if get_option('libbpf_a') != '' libbpf_a = '@0@/libbpf/src/libbpf.a'.format(meson.current_source_dir())
if get_option('libbpf_a') == 'disabled'
libbpf_a = ''
elif get_option('libbpf_a') != ''
libbpf_a = get_option('libbpf_a')
endif
if libbpf_a != ''
if not fs.exists(libbpf_a)
error('@0@ does not exist. You need to build/make libbpf.'.format(libbpf_a))
endif
libbpf_dep = [declare_dependency( libbpf_dep = [declare_dependency(
link_args: get_option('libbpf_a'), link_args: libbpf_a,
include_directories: get_option('libbpf_h')), include_directories: get_option('libbpf_h')),
cc.find_library('elf'), cc.find_library('elf'),
cc.find_library('z'), cc.find_library('z'),
@ -98,7 +110,7 @@ message('cpu=@0@ bpf_base_cflags=@1@'.format(cpu, bpf_base_cflags))
libbpf_c_headers = [] libbpf_c_headers = []
if get_option('libbpf_a') != '' if libbpf_a != ''
foreach header: get_option('libbpf_h') foreach header: get_option('libbpf_h')
libbpf_c_headers += ['-I', header] libbpf_c_headers += ['-I', header]
endforeach endforeach
@ -134,14 +146,14 @@ foreach flag: bpf_base_cflags
cargo_env.append('BPF_BASE_CFLAGS', flag, separator: ' ') cargo_env.append('BPF_BASE_CFLAGS', flag, separator: ' ')
endforeach endforeach
if get_option('libbpf_a') != '' if libbpf_a != ''
foreach header: get_option('libbpf_h') foreach header: get_option('libbpf_h')
cargo_env.append('BPF_EXTRA_CFLAGS_PRE_INCL', '-I' + header, separator: ' ') cargo_env.append('BPF_EXTRA_CFLAGS_PRE_INCL', '-I' + header, separator: ' ')
endforeach endforeach
cargo_env.append('RUSTFLAGS', cargo_env.append('RUSTFLAGS',
'-C link-args=-lelf -C link-args=-lz -C link-args=-lzstd -L ' '-C link-args=-lelf -C link-args=-lz -C link-args=-lzstd -L '
+ fs.parent(get_option('libbpf_a'))) + fs.parent(libbpf_a))
# #
# XXX - scx_rusty's original Cargo.toml contained a dependency matching # XXX - scx_rusty's original Cargo.toml contained a dependency matching

View File

@ -3,7 +3,7 @@ option('bpf_clang', type: 'string', value: 'clang',
option('bpftool', type: 'string', value: 'bpftool', option('bpftool', type: 'string', value: 'bpftool',
description: 'bpftool to use when generating .bpf.skel.h') description: 'bpftool to use when generating .bpf.skel.h')
option('libbpf_a', type: 'string', option('libbpf_a', type: 'string',
description: 'Static libbpf.a to use') description: 'Static libbpf.a to use. Default is to use the one inside the libbpf submodule. Set this option to "disabled" to link libbpf dynamically.')
option('libbpf_h', type: 'array', option('libbpf_h', type: 'array',
description: 'libbpf header directories, only meaningful with libbpf_a option') description: 'libbpf header directories, only meaningful with libbpf_a option')
option('cargo', type: 'string', value: 'cargo', option('cargo', type: 'string', value: 'cargo',