From e5cdccae41a4845b5c3199df7d11fdb0964dec6a Mon Sep 17 00:00:00 2001 From: Felix Obenhuber Date: Wed, 1 Sep 2021 10:46:55 +0200 Subject: [PATCH] Fix build for target_os android Add `target_os = android` to the conditional compilation flags. Add targets `aarch64-linux-android` and `arm-linux-androideabi` with the use of `cross` the the GH action. --- .github/workflows/memfd.yml | 22 ++++++++++++++++++++++ Cargo.toml | 2 +- src/lib.rs | 4 ++-- src/memfd.rs | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.github/workflows/memfd.yml b/.github/workflows/memfd.yml index ab266c2..db6952b 100644 --- a/.github/workflows/memfd.yml +++ b/.github/workflows/memfd.yml @@ -79,3 +79,25 @@ jobs: with: command: build args: --manifest-path=Cargo.toml + cross: + runs-on: ubuntu-latest + strategy: + matrix: + target: + - arm-linux-androideabi + - aarch64-linux-android + steps: + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: ${{ matrix.target }} + override: true + - name: Checkout + uses: actions/checkout@v2 + - name: Build + uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --target=${{ matrix.target }} --manifest-path=Cargo.toml diff --git a/Cargo.toml b/Cargo.toml index 41453f3..4461c4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ exclude = [ [dependencies] # Private dependencies. -libc = "0.2" +libc = "^0.2.99" [package.metadata.release] sign-commit = true diff --git a/src/lib.rs b/src/lib.rs index 16e79db..bfcee6f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,10 +36,10 @@ unused, )] #![cfg_attr(docsrs, feature(doc_cfg))] -#![cfg_attr(docsrs, doc(cfg(target_os="linux")))] +#![cfg_attr(docsrs, doc(cfg(any(target_os = "android", target_os= "linux" ))))] // No-op crate on platforms that do not support memfd_create, instead of failing to link, or at // runtime. -#![cfg(target_os="linux")] +#![cfg(any(target_os = "android", target_os= "linux"))] mod errors; mod memfd; diff --git a/src/memfd.rs b/src/memfd.rs index b9e974c..8a019ee 100644 --- a/src/memfd.rs +++ b/src/memfd.rs @@ -2,7 +2,7 @@ use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use std::{ffi, fs, os::raw}; use crate::{nr, sealing}; -#[cfg(target_os="linux")] +#[cfg(any(target_os = "android", target_os="linux"))] unsafe fn memfd_create(name: *const raw::c_char, flags: raw::c_uint) -> raw::c_int { libc::syscall(libc::SYS_memfd_create, name, flags) as raw::c_int }