Skip to content

Commit 3c4bdf0

Browse files
authored
style: uniform target family conditional compilation (#1831)
* chore: gate nix dependency to unix-only * style: use one variant of target_family conditional compilation #[cfg(unix)] and #[cfg(target_family = "unix")] are equivalent per the [docs](https://doc.rust-lang.org/reference/conditional-compilation.html#unix-and-windows). Let's stick to the most explicit of them.
1 parent a4d38b5 commit 3c4bdf0

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

agent-control/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ license-file.workspace = true
1313
[dependencies]
1414
clap = { workspace = true, features = ["derive"] }
1515
serde = { workspace = true, features = ["derive"] }
16-
1716
thiserror = { workspace = true }
18-
nix = { workspace = true, features = ["signal", "user", "hostname"] }
1917
tracing-subscriber = { workspace = true, features = ["env-filter", "chrono"] }
2018
tracing = { workspace = true, features = ["attributes"] }
2119
ctrlc = { version = "3.5.0", features = ["termination"] }
@@ -34,8 +32,7 @@ serde_json = { workspace = true }
3432
semver = { workspace = true, features = ["serde"] }
3533
chrono = { workspace = true }
3634
base64 = { version = "0.22.1" }
37-
# New Relic dependencies (private external repos)
38-
# IMPORTANT: GitHub deployment keys are used to access these repos on the CI/CD pipelines
35+
# New Relic dependencies (external repos)
3936
nr-auth = { git = "https://github.com/newrelic/newrelic-auth-rs.git", tag = "0.1.1" }
4037
opamp-client = { git = "https://github.com/newrelic/newrelic-opamp-rs.git", tag = "0.0.34" }
4138
# local dependencies
@@ -75,6 +72,9 @@ opentelemetry-appender-tracing = { version = "0.31.1", features = [
7572
] }
7673
async-trait = "0.1.89"
7774

75+
[target.'cfg(target_family = "unix")'.dependencies]
76+
nix = { workspace = true, features = ["signal", "user", "hostname"] }
77+
7878
[dev-dependencies]
7979
assert_cmd = { workspace = true }
8080
predicates = { workspace = true }

agent-control/src/sub_agent/on_host/command/command_os.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl CommandOSStarted {
124124
}
125125
}
126126

127-
#[cfg(unix)]
127+
#[cfg(target_family = "unix")]
128128
mod unix {
129129
use crate::sub_agent::on_host::command::{command_os::CommandOSStarted, error::CommandError};
130130

@@ -163,7 +163,7 @@ mod unix {
163163
}
164164

165165
//TODO Properly design unix/windows shutdown when Windows support is added
166-
#[cfg(windows)]
166+
#[cfg(target_family = "windows")]
167167
mod windows {
168168
use crate::sub_agent::on_host::command::{command_os::CommandOSStarted, error::CommandError};
169169

agent-control/tests/on_host/cli.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn print_debug_info() -> Result<(), Box<dyn std::error::Error>> {
4545
Ok(())
4646
}
4747

48-
#[cfg(unix)]
48+
#[cfg(target_family = "unix")]
4949
#[test]
5050
fn does_not_run_if_no_root() -> Result<(), Box<dyn std::error::Error>> {
5151
let dir = TempDir::new()?;
@@ -58,7 +58,7 @@ fn does_not_run_if_no_root() -> Result<(), Box<dyn std::error::Error>> {
5858
Ok(())
5959
}
6060

61-
#[cfg(unix)]
61+
#[cfg(target_family = "unix")]
6262
#[test]
6363
fn basic_startup() -> Result<(), Box<dyn std::error::Error>> {
6464
use std::time::Duration;
@@ -108,7 +108,7 @@ logs:
108108
Ok(())
109109
}
110110

111-
#[cfg(unix)]
111+
#[cfg(target_family = "unix")]
112112
#[test]
113113
fn custom_logging_format() -> Result<(), Box<dyn std::error::Error>> {
114114
use std::time::Duration;
@@ -158,7 +158,7 @@ server:
158158
Ok(())
159159
}
160160

161-
#[cfg(unix)]
161+
#[cfg(target_family = "unix")]
162162
#[test]
163163
#[ignore = "requires root"]
164164
fn custom_directory_overrides_as_root() -> Result<(), Box<dyn std::error::Error>> {
@@ -234,7 +234,7 @@ server:
234234
Ok(())
235235
}
236236

237-
#[cfg(unix)]
237+
#[cfg(target_family = "unix")]
238238
#[test]
239239
fn runs_with_no_config() -> Result<(), Box<dyn std::error::Error>> {
240240
use std::{env, time::Duration};

0 commit comments

Comments
 (0)