Skip to content

Commit

Permalink
chore: Add FreeBSD to sys-info supported targets
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Silverstone <[email protected]>
  • Loading branch information
kinnison committed Jan 9, 2021
1 parent 053dd17 commit 981a419
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ license = "Apache-2.0"
cfg-if="0.1.10"
thiserror = "1.0.20"

[target.'cfg(any(windows, target_os="macos", target_os="linux"))'.dependencies]
sys-info = "0.6.1"
[target.'cfg(any(windows, target_os="macos", target_os="linux", target_os="freebsd"))'.dependencies]
sys-info = "0.7.0"

[target.'cfg(unix)'.dependencies]
libc = "0.2.78"
Expand Down
26 changes: 22 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ use std::cmp::min;
use cfg_if::cfg_if;

cfg_if! {
if #[cfg(any(windows, target_os="macos", target_os="linux"))] {
if #[cfg(any(windows,
target_os="macos",
target_os="linux",
target_os="freebsd",
))] {
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("sysinfo failure")]
Expand Down Expand Up @@ -152,7 +156,11 @@ fn ulimited_memory() -> Result<Option<u64>> {
/// a-priori selection of memory limits.
pub fn memory_limit() -> Result<u64> {
cfg_if! {
if #[cfg(any(windows, target_os="macos", target_os="linux"))] {
if #[cfg(any(windows,
target_os="macos",
target_os="linux",
target_os="freebsd",
))] {
let info = sys_info::mem_info()?;
let total_ram = info.total * 1024;
let ulimit_mem = ulimited_memory()?;
Expand Down Expand Up @@ -182,7 +190,12 @@ mod tests {

use super::*;

#[cfg(any(windows, target_os = "macos", target_os = "linux"))]
#[cfg(any(
windows,
target_os = "macos",
target_os = "linux",
target_os = "freebsd",
))]
#[test]
fn it_works() -> Result<()> {
assert_ne!(0, memory_limit()?);
Expand Down Expand Up @@ -384,7 +397,12 @@ mod tests {
Ok(limit)
}

#[cfg(any(windows, target_os = "macos", target_os = "linux"))]
#[cfg(any(
windows,
target_os = "macos",
target_os = "linux",
target_os = "freebsd",
))]
#[test]
fn test_no_ulimit() -> Result<()> {
// This test depends on the dev environment being run uncontained.
Expand Down

0 comments on commit 981a419

Please sign in to comment.