Skip to content

Commit 4f5181a

Browse files
committed
build: gate utilities by target support
1 parent db7b8a6 commit 4f5181a

5 files changed

Lines changed: 17 additions & 4 deletions

File tree

build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub fn main() {
3737

3838
let out_dir = env::var("OUT_DIR").unwrap();
3939

40+
let target_os = env::var_os("CARGO_CFG_TARGET_OS").unwrap();
41+
let is_unix = env::var_os("CARGO_CFG_UNIX").is_some();
42+
4043
let mut crates = Vec::new();
4144
for (key, val) in env::vars() {
4245
if val == "1" && key.starts_with(ENV_FEATURE_PREFIX) {
@@ -48,6 +51,12 @@ pub fn main() {
4851
"chcon" | "runcon" => {
4952
continue;
5053
}
54+
"nohup" | "stdbuf" if !is_unix => {
55+
continue;
56+
}
57+
"who" if !(is_unix && target_os != "redox") => {
58+
continue;
59+
}
5160
"default" | "macos" | "unix" | "windows" | "selinux" | "zip" | "clap_complete"
5261
| "clap_mangen" | "fluent_syntax" => continue, // common/standard feature names
5362
"nightly" | "test_unimplemented" | "expensive_tests" | "test_risky_names" => {

src/uu/nohup/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ path = "src/nohup.rs"
1919
test = false
2020
doctest = false
2121

22-
[dependencies]
22+
[target.'cfg(unix)'.dependencies]
2323
clap = { workspace = true }
2424
libc = { workspace = true }
2525
rustix = { workspace = true, features = ["process", "stdio"] }
@@ -30,3 +30,4 @@ fluent = { workspace = true }
3030
[[bin]]
3131
name = "nohup"
3232
path = "src/main.rs"
33+
required-features = ["uucore/default"]

src/uu/nohup/src/nohup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// file that was distributed with this source code.
55

66
// spell-checker:ignore (ToDO) SIGHUP cproc vprocmgr homeout
7-
#[cfg(not(unix))]
8-
compile_error!("nohup is not supported on the target");
7+
8+
#![cfg(unix)]
99

1010
use clap::{Arg, ArgAction, Command};
1111
use rustix::stdio::{dup2_stderr, dup2_stdin, dup2_stdout, stdout};

src/uu/who/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ path = "src/who.rs"
2525
test = false
2626
doctest = false
2727

28-
[dependencies]
28+
[target.'cfg(all(unix, not(target_os = "redox")))'.dependencies]
2929
clap = { workspace = true }
3030
rustix = { workspace = true }
3131
uucore = { workspace = true, features = ["utmpx"] }
@@ -34,3 +34,4 @@ fluent = { workspace = true }
3434
[[bin]]
3535
name = "who"
3636
path = "src/main.rs"
37+
required-features = ["uucore/utmpx"]

src/uu/who/src/who.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
// spell-checker:ignore (ToDO) runlevel mesg
77

8+
#![cfg(all(unix, not(target_os = "redox")))]
9+
810
use clap::{Arg, ArgAction, Command};
911
use uucore::format_usage;
1012
use uucore::translate;

0 commit comments

Comments
 (0)