Skip to content

Commit

Permalink
Fix build for target_os android
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
flxo committed Sep 6, 2021
1 parent b23472e commit e5cdcca
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/memfd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exclude = [

[dependencies]
# Private dependencies.
libc = "0.2"
libc = "^0.2.99"

[package.metadata.release]
sign-commit = true
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/memfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit e5cdcca

Please sign in to comment.