Skip to content

Commit

Permalink
Make #[cfg()]s more specific (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylni committed Jan 15, 2022
1 parent 68ee305 commit dbcc8f6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
12 changes: 8 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ macro_rules! if_memory_limit {
( $($item:item)+ ) => {
$(
#[cfg(any(
target_env = "gnu",
target_env = "musl",
target_os = "android",
all(
target_os = "linux",
any(target_env = "gnu", target_env = "musl"),
),
windows,
))]
$item
Expand Down Expand Up @@ -265,9 +267,11 @@ pub trait Control: private::Sealed {
#[cfg_attr(
process_control_docs_rs,
doc(cfg(any(
target_env = "gnu",
target_env = "musl",
target_os = "android",
all(
target_os = "linux",
any(target_env = "gnu", target_env = "musl"),
),
windows,
)))
)]
Expand Down
27 changes: 18 additions & 9 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::process::Child;
use std::thread;
use std::time::Duration;

#[cfg(target_env = "gnu")]
#[cfg(all(target_env = "gnu", target_os = "linux"))]
use libc::__rlimit_resource_t;
use libc::pid_t;
use libc::CLD_EXITED;
Expand All @@ -31,9 +31,12 @@ if_memory_limit! {
use libc::RLIMIT_AS;
}

#[cfg(any(target_env = "musl", target_os = "android"))]
#[cfg(any(
all(target_env = "musl", target_os = "linux"),
target_os = "android",
))]
type LimitResource = c_int;
#[cfg(target_env = "gnu")]
#[cfg(all(target_env = "gnu", target_os = "linux"))]
type LimitResource = __rlimit_resource_t;

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -144,9 +147,11 @@ impl RawPid {
pub(super) struct SharedHandle {
pid: RawPid,
#[cfg(any(
target_env = "gnu",
target_env = "musl",
target_os = "android",
all(
target_os = "linux",
any(target_env = "gnu", target_env = "musl"),
),
))]
pub(super) memory_limit: Option<usize>,
pub(super) time_limit: Option<Duration>,
Expand All @@ -157,9 +162,11 @@ impl SharedHandle {
Self {
pid: RawPid::new(process),
#[cfg(any(
target_env = "gnu",
target_env = "musl",
target_os = "android",
all(
target_os = "linux",
any(target_env = "gnu", target_env = "musl"),
),
))]
memory_limit: None,
time_limit: None,
Expand Down Expand Up @@ -206,9 +213,11 @@ impl SharedHandle {
// https://github.com/rust-lang/rust/blob/49c68bd53f90e375bfb3cbba8c1c67a9e0adb9c0/src/libstd/sys/unix/process/process_unix.rs#L432-L441

#[cfg(any(
target_env = "gnu",
target_env = "musl",
target_os = "android",
all(
target_os = "linux",
any(target_env = "gnu", target_env = "musl"),
),
))]
if let Some(memory_limit) = self.memory_limit {
unsafe {
Expand Down
12 changes: 8 additions & 4 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ macro_rules! if_memory_limit {
( $($item:item)+ ) => {
$(
#[cfg(any(
target_env = "gnu",
target_env = "musl",
target_os = "android",
all(
target_os = "linux",
any(target_env = "gnu", target_env = "musl"),
),
windows,
))]
$item
Expand Down Expand Up @@ -136,9 +138,11 @@ macro_rules! test {
( @time_limit $control:expr , $limit:expr , $($token:tt)* ) => {{
test!(@strict_errors $control.time_limit($limit), $($token)*);
#[cfg(any(
target_env = "gnu",
target_env = "musl",
target_os = "android",
all(
target_os = "linux",
any(target_env = "gnu", target_env = "musl"),
),
windows,
))]
test!(
Expand Down

0 comments on commit dbcc8f6

Please sign in to comment.