Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use xmake to port libbpf-bootstrap and support android bpf program #17

Closed
waruqi opened this issue Apr 8, 2021 · 7 comments
Closed

Comments

@waruqi
Copy link
Contributor

waruqi commented Apr 8, 2021

libbpf-bootstrap is a great project that allows beginners to quickly get started with bpf program development.

Now I used xmake to port the libbpf-bootstrap program and compiled it to the android platform.

xmake.lua

add_rules("mode.release", "mode.debug")
add_rules("platform.linux.bpf")

add_requires("linux-tools", {configs = {bpftool = true}})
add_requires("libbpf")
if is_plat("android") then
    add_requires("ndk >=22.x")
    set_toolchains("@ndk", {sdkver = "23"})
else
    add_requires("llvm >=10.x")
    set_toolchains("@llvm")
    add_requires("linux-headers")
end

target("minimal")
    set_kind("binary")
    add_files("src/*.c")
    add_packages("linux-tools", "linux-headers", "libbpf")
    set_license("GPL-2.0")

In addition, I ported the libbpf library and other dependent libraries to the android platform. All dependent packages and tool chains can be automatically downloaded and integrated by xmake.

We only need to execute xmake to compile linux bpf program, or use xmake f -p android; xmake to compile android bpf program.

If the user has installed the new version of llvm/clang and ndk r22, then xmake will also give priority to using them and will not download them automatically.

build on linux

It will download llvm toolchain and use it automatically if not found.

we can also install llvm manually. sudo apt install llvm and xmake will also use it.

$ xmake

build android on linux

It will download ndk toolchain and use it automatically

$ xmake f -p android
$ xmake

We can also set ndk toolchain manually (need ndk >= r22)

$ xmake f -p android --ndk=~/file/android-ndk-r22
$ xmake

Here is a libbpf-bootstrap project that I use xmake to ported. The project directory is very clean. We only need to keep the src source file and the xmake.lua project configuration file.

https://github.com/hack0z/libbpf-bootstrap

And I added libbpf package into our official repository, https://github.com/xmake-io/xmake-repo/blob/master/packages/l/libbpf/xmake.lua

If you are interested, I can open a pr and just add xmake.lua to your project, but I will not delete any other files, otherwise please ignore this issue.

Related issue: xmake-io/xmake#1274

Thanks!

@anakryiko
Copy link
Member

Let me take a look and get back to you next week. We plan to expand libbpf-bootstrap to have more examples across various platforms and languages (e.g., Rust-based examples), so this might be a good addition. But I need to see what and how all things are put together to make a decision.

@danobi
Copy link
Member

danobi commented Apr 12, 2021

My opinion (feel free to ignore me): xmake looks promising and easy to use. I'll probably try it out later for a personal project. But I'm not so sure about introducing non-standard tools to a "teaching" project. The purpose of this repo is to teach people about BPF -- any new tool / technology that isn't directly related to the goal of teaching about BPF is a distraction.

@anakryiko
Copy link
Member

@waruqi so after discussing with @danobi some more, I think this might be a good addition to existing Makefile, as well as CMake that we are going to add. Please see #19 for discussion around re-organizing libbpf-bootstrap to allow multiple languages (C and Rust for starters) and having multiple build system integrations. So let's wait for that reorg to be completed, and then work towards merging xmake stuff in. Does this sound good to you?

@waruqi
Copy link
Contributor Author

waruqi commented Apr 14, 2021

ok, thanks!

@anakryiko
Copy link
Member

@waruqi now that we have both C and Rust examples, as well as Makefile and CMake-based build scripts, can you take another look if you can adopt your xmake stuff to integrate nicely into this setup?

@waruqi
Copy link
Contributor Author

waruqi commented May 5, 2021

@waruqi now that we have both C and Rust examples, as well as Makefile and CMake-based build scripts, can you take another look if you can adopt your xmake stuff to integrate nicely into this setup?

ok, I will look at it later. thanks.

@waruqi
Copy link
Contributor Author

waruqi commented May 11, 2021

I have opened a pr to add xmake.lua for building linux/android program. #27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants