xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.01k stars 780 forks source link

cross build bpf for Android #2486

Open tiann opened 2 years ago

tiann commented 2 years ago

Is your feature request related to a problem? Please describe.

https://github.com/xmake-io/xmake/issues/1274 supports compile bpf on Linux, it is useful to do cross compile on macOS/Windows

Describe the solution you'd like

xmake f -p android wouldn't fail on macOS

Describe alternatives you've considered

No response

Additional context

use libbpf-bootstrap and use xmake to build it:

libbpf-bootstrap/examples/c on  master via △ v3.23.2 via 🌙 v5.4.4
❯ xmake f -p android --ndk=$NDK
checking for architecture ... armeabi-v7a
checking for Android SDK directory ... ~/Library/Android/sdk
checking for Build Tools Version of Android SDK ... %s
checking for NDK directory ... /Users/weishu/dev/env/android-sdk-macosx/ndk/22.0.7026061
checking for SDK version of NDK ... 21
note: install or modify (m) these packages (pass -y to skip confirm)?
in xmake-repo:
  -> libelf 0.8.13 [toolchains:"@ndk"]
  -> zlib v1.2.12 [toolchains:"@ndk"]
  -> argp-standalone 1.3 [toolchains:"@ndk"]
please input: y (y/n/m)
y
  => download https://www.lysator.liu.se/~nisse/misc/argp-standalone-1.3.tar.gz .. ok
  => install zlib v1.2.12 .. ok
  => install libelf 0.8.13 .. ok
  => install argp-standalone 1.3 .. ok
generating ../../libbpf/src/skel_internal.h ... cache
generating ../../libbpf/src/libbpf.h ... cache
generating ../../libbpf/src/str_error.h ... cache
generating ../../libbpf/src/nlattr.h ... cache
generating ../../libbpf/src/bpf_tracing.h ... cache
generating ../../libbpf/src/libbpf_version.h ... cache
generating ../../libbpf/src/usdt.bpf.h ... cache
generating ../../libbpf/src/xsk.h ... cache
generating ../../libbpf/src/libbpf_common.h ... cache
generating ../../libbpf/src/bpf_helpers.h ... cache
generating ../../libbpf/src/relo_core.h ... cache
generating ../../libbpf/src/libbpf_legacy.h ... cache
generating ../../libbpf/src/hashmap.h ... cache
generating ../../libbpf/src/strset.h ... cache
generating ../../libbpf/src/bpf_helper_defs.h ... cache
generating ../../libbpf/src/libbpf_internal.h ... cache
generating ../../libbpf/src/bpf_core_read.h ... cache
generating ../../libbpf/src/bpf_endian.h ... cache
generating ../../libbpf/src/bpf.h ... cache
generating ../../libbpf/src/bpf_gen_internal.h ... cache
generating ../../libbpf/src/btf.h ... cache
error: rule("platform.linux.bpf"): only supported on linux!
waruqi commented 2 years ago

It is dependent on the bpftool command, so we need port bpftool and get it's binary for macos and windows first.

https://github.com/xmake-io/xmake/blob/7c2a56b1b5e46abc2c0a9898943e897ba9b5a4ac/xmake/rules/platform/linux/bpf/xmake.lua#L53