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

Will you consider supporting it on Android? #73

Open
editso opened this issue Nov 28, 2023 · 6 comments
Open

Will you consider supporting it on Android? #73

editso opened this issue Nov 28, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@editso
Copy link

editso commented Nov 28, 2023

Hi, I tried to build for Android, but the build failed. Does it support Android? If possible, can I create a PR to support it?

@alexforster alexforster added the enhancement New feature or request label Dec 10, 2023
@alexforster
Copy link
Member

Hi – sounds fine theoretically, but I don't know anything about Android development. Does it mean adding lots of Android-specific build system stuff?

@editso
Copy link
Author

editso commented Dec 11, 2023

Hi – sounds fine theoretically, but I don't know anything about Android development. Does it mean adding lots of Android-specific build system stuff?
The main thing here is to solve the compilation of elfutils. On Android, it lacks some related macros. You only need to solve these problems. I referred to aosp/elfutils At this point, I successfully built for Android

@amirbou
Copy link

amirbou commented Jun 26, 2024

Hey, bumping this issue :)
I'm really hopeful we can think of a proper solution, so I'm listing my thoughts on the manner.
This is also relevant for libbpf/libbpf-rs#267

I personally managed to make it compile by specifying:

[target.aarch64-linux-android.libbpf]
rustc-link-lib = ["static=bpf", "static=elf", "z"]

[target.x86_64-linux-android.libbpf]
rustc-link-lib = ["static=bpf", "static=elf", "z"]

in my .cargo/config.toml, and compiling libelf and libbpf myself (as submodules) using make,
which is pretty annoying.

The main issues I had to solve:

  • config.toml should point to a valid NDK (Android's cross compile toolchains)
    • This should already be the case for anyone trying to compile for Android
    • It might be difficult to determine the "Minimum Supported NDK Version"
  • It's hard to build elfutils for Android

It seems to me that there are 3 possible solutions:

  1. Maintain libelf, libintl and argp-standalone as submodules and build them when targeting Android
  2. Maintain a set of patches to elfutils to make it compile only libelf, without the need of libintl and argp (that's what I did in my personal project)
  3. Use XMake to build the necessary libraries when targeting Android

IMHO the last solution would be the most reasonable one, and it can also be gated behind a crate feature to not interfere with "normal" builds

I'll try to work on a PR to see if there is anything that I missed.

I'd like to hear your thoughts on the idea :)

@editso
Copy link
Author

editso commented Jun 27, 2024

Hey, bumping this issue :) I'm really hopeful we can think of a proper solution, so I'm listing my thoughts on the manner. This is also relevant for libbpf/libbpf-rs#267

I personally managed to make it compile by specifying:

[target.aarch64-linux-android.libbpf]
rustc-link-lib = ["static=bpf", "static=elf", "z"]

[target.x86_64-linux-android.libbpf]
rustc-link-lib = ["static=bpf", "static=elf", "z"]

in my .cargo/config.toml, and compiling libelf and libbpf myself (as submodules) using make, which is pretty annoying.

The main issues I had to solve:

  • config.toml should point to a valid NDK (Android's cross compile toolchains)

    • This should already be the case for anyone trying to compile for Android
    • It might be difficult to determine the "Minimum Supported NDK Version"
  • It's hard to build elfutils for Android

It seems to me that there are 3 possible solutions:

  1. Maintain libelf, libintl and argp-standalone as submodules and build them when targeting Android
  2. Maintain a set of patches to elfutils to make it compile only libelf, without the need of libintl and argp (that's what I did in my personal project)
  3. Use XMake to build the necessary libraries when targeting Android

IMHO the last solution would be the most reasonable one, and it can also be gated behind a crate feature to not interfere with "normal" builds

I'll try to work on a PR to see if there is anything that I missed.

I'd like to hear your thoughts on the idea :)

My approach was just to add the missing macros and some header files, then it started working.
image

@amirbou
Copy link

amirbou commented Jun 28, 2024

That's awesome!
It seems like configure is only used to produce the config.h file, and then you compile the library yourself without make,
did you have any issues with config.h producing the wrong results (as configure is done without the --host flag)?
The AOSP repo uses a pre-generated config.h, which is updated every time the upstream version is merged.

As a side note, it seems that the XMake repo for libbpf is unmaintained for quite some time (it uses libbpf version 0.3) 👎

@editso
Copy link
Author

editso commented Jun 28, 2024

That's awesome! It seems like configure is only used to produce the config.h file, and then you compile the library yourself without make, did you have any issues with config.h producing the wrong results (as configure is done without the --host flag)? The AOSP repo uses a pre-generated config.h, which is updated every time the upstream version is merged.

As a side note, it seems that the XMake repo for libbpf is unmaintained for quite some time (it uses libbpf version 0.3) 👎

It seems that running ./configure directly does not have any impact. Yes, I removed the make-based compilation method and instead used the cc library for compilation. I have committed the code to a forked branch. Due to the significant changes I made, I am not sure if the pull request will be accepted

repo: https://github.com/editso/libbpf-sys-android/tree/android
ci: https://github.com/editso/libbpf-sys-android/actions/runs/9711879697

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

No branches or pull requests

3 participants