Skip to content
New issue

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

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

Already on GitHub? # to your account

Compile for Android #267

Open
kochia3 opened this issue Sep 8, 2022 · 3 comments
Open

Compile for Android #267

kochia3 opened this issue Sep 8, 2022 · 3 comments

Comments

@kochia3
Copy link

kochia3 commented Sep 8, 2022

How can I compile libbpf-rs based project for Android, x86_64 emulator or for arm64?

@insearchoflosttime
Copy link
Collaborator

Hi @kochia3, I'm not sure I fully understand your question. rustc is a cross-compiler, so it can generate targets for any architecture. Can you elaborate on your question?

@kochia3
Copy link
Author

kochia3 commented Sep 9, 2022

I was unable to do so, for example https://github.com/libbpf/libbpf-bootstrap uses xmake and ndk for that

@danielocfb
Copy link
Collaborator

arm64 can be done similarly as we already do in CI:

build-aarch64:
name: Build for aarch64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Add apt sources for arm64
run: |
dpkg --add-architecture arm64
release=$(. /etc/os-release && echo "$UBUNTU_CODENAME")
sed -i 's/^deb /deb [arch=amd64] /' /etc/apt/sources.list
printf 'deb [arch=arm64] http://ports.ubuntu.com/ %s main restricted\n' \
$release $release-updates $release-security \
>> /etc/apt/sources.list
shell: sudo sh -e {0}
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: aarch64-unknown-linux-gnu
override: true
- name: Install deps
run: |
sudo apt-get update
sudo apt-get install -y libelf-dev:arm64 zlib1g-dev:arm64 gcc-aarch64-linux-gnu
- uses: Swatinem/rust-cache@v2.2.0
- name: Build
env:
CARGO_BUILD_TARGET: aarch64-unknown-linux-gnu
RUSTFLAGS: -C linker=/usr/bin/aarch64-linux-gnu-gcc
run: cargo build --lib

Similar procedures will allow for compilation on different architectures. I don't believe we are familiar enough with Android to provide any guidance there. If you got something working, please feel free to open a pull request.

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

No branches or pull requests

3 participants