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

Support for building Android platforms #90

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,61 @@ jobs:
- run: cargo test ${{ matrix.args }}
shell: alpine.sh {0}

test-android:
name: Test on Android
strategy:
matrix:
include:
- rust-target: aarch64-linux-android
os-arch: amd64

runs-on: ubuntu-20.04

env:
CARGO_BUILD_TARGET: ${{ matrix.rust-target }}
CARGO_TERM_VERBOSE: 'true'

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get -y install \
gawk \
flex \
bison \
clang \
automake \
autopoint \
gcc-multilib \
build-essential

- name: Install Rust stable for ${{ matrix.rust-target }}
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.rust-target }}

- name: Install Android NDK
uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r26d
# local-cache: true
# add-to-path: false

- name: Cargo test no run
run: cargo test --no-run
if: matrix.rust-target == 'aarch64-linux-android'
env:
RUSTFLAGS: -C linker=${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang
AR_aarch64_linux_android: ${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
CC_aarch64_linux_android: ${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang
CXX_aarch64_linux_android: ${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang++

test-libbpf-rs:
# check that libbpf-rs, one of the main consumers of the library, works with
# this version of libbpf-sys
Expand Down Expand Up @@ -174,6 +229,7 @@ jobs:
needs:
- test-gnu
- test-musl
- test-android
- test-libbpf-rs
runs-on: ubuntu-22.04
steps:
Expand Down
28 changes: 28 additions & 0 deletions android/AndroidFixup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2013, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_FIXUP_H
#define ANDROID_FIXUP_H
static inline void *rawmemchr(const void *s, int c) {
const unsigned char *ptr = s;
while (1) {
if (*ptr == c)
return (void *)ptr;
ptr++;
}
}
/* workaround for canonicalize_file_name */
#define canonicalize_file_name(path) realpath(path, NULL)
#endif /* ANDROID_FIXUP_H */
4 changes: 4 additions & 0 deletions android/android.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once
#define __user
#define __force
typedef unsigned __poll_t;
21 changes: 21 additions & 0 deletions android/argp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2013, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ELFUTILS_ARGP_H
#define ELFUTILS_ARGP_H
// We don't have an implementation, but elfutils unconditionally includes this,
// and relies on its transitive includes in places.
#include <errno.h>
#endif /* ELFUTILS_ARGP_H */
21 changes: 21 additions & 0 deletions android/libintl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2013, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ELFUTILS_LIBINTL_H
#define ELFUTILS_LIBINTL_H
/* no internalization */
#define gettext(x) (x)
#define dgettext(x, y) (y)
#endif /* ELFUTILS_LIBINTL_H */
5 changes: 5 additions & 0 deletions bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
#include "libbpf/src/btf.h"
#include "libbpf/src/libbpf.h"
#endif /* __LIBBPF_SYS_NOVENDOR */

#if defined (__aarch64__) || defined (__arm__)
#include <stdarg.h>
typedef va_list __va_list_tag;
#endif
Loading
Loading