Skip to content
Merged
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
17 changes: 11 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ jobs:
- { os: 'macos-latest', target: 'x86_64-apple-darwin', cross: false }
- { os: 'windows-latest', target: 'x86_64-pc-windows-msvc', cross: false }
## iOS
- { os: 'macos-latest', target: 'aarch64-apple-ios', cross: false }
# x86_64 testing blocked on https://github.com/actions-rs/toolchain/issues/16
- { os: 'macos-latest', target: 'aarch64-apple-ios', cross: true }
- { os: 'macos-latest', target: 'x86_64-apple-ios', cross: true }
## ARM64
- { os: 'ubuntu-latest', target: 'aarch64-unknown-linux-gnu', cross: true }
- { os: 'ubuntu-latest', target: 'aarch64-unknown-linux-musl', cross: true }
Expand All @@ -72,10 +72,6 @@ jobs:
profile: minimal
toolchain: ${{ matrix.toolchain }}
override: true
# x86_64 testing blocked on https://github.com/actions-rs/toolchain/issues/16
# This only adds the extra target toolchain. This target will only be built for
# during its specified matrix job.
target: aarch64-apple-ios

- name: Check
uses: actions-rs/cargo@v1
Expand All @@ -84,6 +80,15 @@ jobs:
args: --target=${{ matrix.triple.target }} --manifest-path=Cargo.toml
use-cross: ${{ matrix.triple.cross }}

- name: Check (Apple app store restrictions)
if: matrix.triple.os == 'macos-latest'
uses: actions-rs/cargo@v1
with:
command: check
args: --features apple-app-store --target=${{ matrix.triple.target }} --manifest-path=Cargo.toml
use-cross: ${{ matrix.triple.cross }}


tests:
needs: [check]
name: Test ${{ matrix.os }} (rust ${{matrix.toolchain}})
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ crate_type = ["rlib", "cdylib"]

[features]
default = ["multithread"]
apple-app-store = []
c-interface = []
multithread = ["rayon"]
debug = ["libc/extra_traits"]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ It also compiles for Android but never been tested on it.

The minimum-supported version fo `rustc` is **1.45**.

### Use in binaries distributed on the MacOS App Store

Apple has restrictions as to which APIs can be used in binaries distributed through the app store.
Comment thread
complexspaces marked this conversation as resolved.
By default, `sysinfo` is not compatiable with these restrictions. You can use the `apple-app-store` feature
flag to disable the Apple prohibited features.
Comment thread
complexspaces marked this conversation as resolved.

### Running on Raspberry Pi

It'll be difficult to build on Raspberry Pi. A good way-around is to cross-build, then send the executable to your Raspberry Pi.
Expand Down
7 changes: 7 additions & 0 deletions src/apple/app_store/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// Sysinfo
//
// Copyright (c) 2021 Guillaume Gomez
//

pub mod process;
82 changes: 82 additions & 0 deletions src/apple/app_store/process.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// Sysinfo
//
// Copyright (c) 2021 Guillaume Gomez
//

use std::path::Path;

use crate::{DiskUsage, Pid, ProcessExt, ProcessStatus, Signal};

/// Dummy struct representing a process because iOS doesn't support
/// obtaining process information due to sandboxing.
///
/// MacOS apps in Apple's app store are also not able to access this information.
#[derive(Clone)]
pub struct Process;

impl ProcessExt for Process {
fn new(_pid: Pid, _parent: Option<Pid>, _start_time: u64) -> Process {
Process {}
}

fn kill(&self, _signal: Signal) -> bool {
false
}

fn name(&self) -> &str {
""
}

fn cmd(&self) -> &[String] {
&[]
}

fn exe(&self) -> &Path {
Path::new("/")
}

fn pid(&self) -> Pid {
0
}

fn environ(&self) -> &[String] {
&[]
}

fn cwd(&self) -> &Path {
Path::new("/")
}

fn root(&self) -> &Path {
Path::new("/")
}

fn memory(&self) -> u64 {
0
}

fn virtual_memory(&self) -> u64 {
0
}

fn parent(&self) -> Option<Pid> {
None
}

fn status(&self) -> ProcessStatus {
ProcessStatus::Unknown(0)
}

fn start_time(&self) -> u64 {
0
}

fn cpu_usage(&self) -> f32 {
0.0
}

fn disk_usage(&self) -> DiskUsage {
DiskUsage::default()
}
}
21 changes: 0 additions & 21 deletions src/apple/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@ use libc::{c_int, c_uchar, c_uint, c_ushort, c_void};
pub use crate::sys::inner::ffi::*;

extern "C" {
pub fn proc_pidinfo(
pid: c_int,
flavor: c_int,
arg: u64,
buffer: *mut c_void,
buffersize: c_int,
) -> c_int;
pub fn proc_listallpids(buffer: *mut c_void, buffersize: c_int) -> c_int;
//pub fn proc_listpids(kind: u32, x: u32, buffer: *mut c_void, buffersize: c_int) -> c_int;
//pub fn proc_name(pid: c_int, buffer: *mut c_void, buffersize: u32) -> c_int;
//pub fn proc_regionfilename(pid: c_int, address: u64, buffer: *mut c_void,
// buffersize: u32) -> c_int;
pub fn proc_pidpath(pid: c_int, buffer: *mut c_void, buffersize: u32) -> c_int;
pub fn proc_pid_rusage(pid: c_int, flavor: c_int, buffer: *mut c_void) -> c_int;

pub fn mach_absolute_time() -> u64;
//pub fn task_for_pid(host: u32, pid: pid_t, task: *mut task_t) -> u32;
pub fn mach_task_self() -> u32;
pub fn mach_host_self() -> u32;
Expand Down Expand Up @@ -248,14 +232,9 @@ pub const CPU_STATE_NICE: u32 = 3;
pub const CPU_STATE_MAX: usize = 4;
pub const HW_MEMSIZE: u32 = 24;

//pub const PROC_ALL_PIDS: c_uint = 1;
pub const PROC_PIDTBSDINFO: c_int = 3;

//pub const TASK_THREAD_TIMES_INFO: u32 = 3;
//pub const TASK_THREAD_TIMES_INFO_COUNT: u32 = 4;
//pub const TASK_BASIC_INFO_64: u32 = 5;
//pub const TASK_BASIC_INFO_64_COUNT: u32 = 10;
pub const HOST_VM_INFO64: u32 = 4;
pub const HOST_VM_INFO64_COUNT: u32 = 38;

pub const PROC_PIDPATHINFO_MAXSIZE: u32 = 4096;
1 change: 1 addition & 0 deletions src/apple/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

pub mod component;
pub mod ffi {}
pub use crate::sys::app_store::process;
37 changes: 37 additions & 0 deletions src/apple/macos/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,41 @@ use core_foundation_sys::dictionary::CFMutableDictionaryRef;
use core_foundation_sys::string::{CFStringEncoding, CFStringRef};
use core_foundation_sys::url::CFURLRef;

#[cfg(not(feature = "apple-app-store"))]
use libc::c_int;
use libc::{c_char, c_void, size_t};

pub(crate) use crate::sys::ffi::*;

extern "C" {
#[cfg(not(feature = "apple-app-store"))]
pub fn mach_absolute_time() -> u64;

// The proc_* PID functions are internal Apple APIs which are not
// allowed in App store releases as Apple blocks any binary using them.

#[cfg(not(feature = "apple-app-store"))]
pub fn proc_pidinfo(
pid: c_int,
flavor: c_int,
arg: u64,
buffer: *mut c_void,
buffersize: c_int,
) -> c_int;

#[cfg(not(feature = "apple-app-store"))]
pub fn proc_listallpids(buffer: *mut c_void, buffersize: c_int) -> c_int;
//pub fn proc_listpids(kind: u32, x: u32, buffer: *mut c_void, buffersize: c_int) -> c_int;
//pub fn proc_name(pid: c_int, buffer: *mut c_void, buffersize: u32) -> c_int;
//pub fn proc_regionfilename(pid: c_int, address: u64, buffer: *mut c_void,
// buffersize: u32) -> c_int;

#[cfg(not(feature = "apple-app-store"))]
pub fn proc_pidpath(pid: c_int, buffer: *mut c_void, buffersize: u32) -> c_int;

#[cfg(not(feature = "apple-app-store"))]
pub fn proc_pid_rusage(pid: c_int, flavor: c_int, buffer: *mut c_void) -> c_int;

// IOKit is only available on MacOS: https://developer.apple.com/documentation/iokit

pub fn IOMasterPort(a: i32, b: *mut mach_port_t) -> i32;
Expand Down Expand Up @@ -143,3 +173,10 @@ pub const SMC_CMD_READ_KEYINFO: u8 = 9;
pub const SMC_CMD_READ_BYTES: u8 = 5;

pub const KIO_RETURN_SUCCESS: i32 = 0;

//pub const PROC_ALL_PIDS: c_uint = 1;
#[cfg(not(feature = "apple-app-store"))]
pub const PROC_PIDTBSDINFO: c_int = 3;

#[cfg(not(feature = "apple-app-store"))]
pub const PROC_PIDPATHINFO_MAXSIZE: u32 = 4096;
6 changes: 6 additions & 0 deletions src/apple/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
pub mod component;
pub mod disk;
pub mod ffi;

#[cfg(not(feature = "apple-app-store"))]
pub mod process;

#[cfg(feature = "apple-app-store")]
pub use crate::sys::app_store::process;
Loading