From 626e66686a2f6c599dd03732cd0cb528b6d43f17 Mon Sep 17 00:00:00 2001 From: Jordan Rome Date: Wed, 28 Feb 2024 08:03:01 -0800 Subject: [PATCH] Add libbpf as a submodule This is to potentinally reduce issues with folks using different versions of libbpf at runtime. --- .gitmodules | 3 +++ README.md | 16 ++++++++++++++-- libbpf | 1 + meson.build | 22 +++++++++++++++++----- meson.options | 2 +- 5 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 .gitmodules create mode 160000 libbpf diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e606d2b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libbpf"] + path = libbpf + url = https://github.com/libbpf/libbpf diff --git a/README.md b/README.md index 778387c..b8f6e6d 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ repo](https://mesonbuild.com/Quick-guide.html#installation-from-source) and call standard utilities including `awk`. - `clang`: >=16 required, >=17 recommended - `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 - `libelf`, `libz`, `libzstd` if linking against staic `libbpf.a` - `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 `~/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 -$ meson setup build --prefix ~ +$ meson setup build --prefix ~ -D libbpf_a=disabled $ meson compile -C build $ meson install -C build ``` diff --git a/libbpf b/libbpf new file mode 160000 index 0000000..20c0a9e --- /dev/null +++ b/libbpf @@ -0,0 +1 @@ +Subproject commit 20c0a9e3d7e7d4aeb283eae982543c9cacc29477 diff --git a/meson.build b/meson.build index 3fec887..d6eb572 100644 --- a/meson.build +++ b/meson.build @@ -44,9 +44,21 @@ elif bpf_clang_maj < 17 .format(bpf_clang.full_path(), bpf_clang_ver)) 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( - link_args: get_option('libbpf_a'), + link_args: libbpf_a, include_directories: get_option('libbpf_h')), cc.find_library('elf'), cc.find_library('z'), @@ -98,7 +110,7 @@ message('cpu=@0@ bpf_base_cflags=@1@'.format(cpu, bpf_base_cflags)) libbpf_c_headers = [] -if get_option('libbpf_a') != '' +if libbpf_a != '' foreach header: get_option('libbpf_h') libbpf_c_headers += ['-I', header] endforeach @@ -134,14 +146,14 @@ foreach flag: bpf_base_cflags cargo_env.append('BPF_BASE_CFLAGS', flag, separator: ' ') endforeach -if get_option('libbpf_a') != '' +if libbpf_a != '' foreach header: get_option('libbpf_h') cargo_env.append('BPF_EXTRA_CFLAGS_PRE_INCL', '-I' + header, separator: ' ') endforeach cargo_env.append('RUSTFLAGS', '-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 diff --git a/meson.options b/meson.options index 6cd9260..9f6208a 100644 --- a/meson.options +++ b/meson.options @@ -3,7 +3,7 @@ option('bpf_clang', type: 'string', value: 'clang', option('bpftool', type: 'string', value: 'bpftool', description: 'bpftool to use when generating .bpf.skel.h') 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', description: 'libbpf header directories, only meaningful with libbpf_a option') option('cargo', type: 'string', value: 'cargo',