From ebd1f703f46d404027137742a3511204af3e9066 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 17 Feb 2026 15:17:54 +0000 Subject: [PATCH 01/10] id: add selinux/smack cfg alias --- Cargo.lock | 1 + src/uu/id/Cargo.toml | 3 +++ src/uu/id/build.rs | 11 +++++++++++ src/uu/id/src/id.rs | 27 ++++++++++----------------- 4 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 src/uu/id/build.rs diff --git a/Cargo.lock b/Cargo.lock index 3db6e437366..4fd09729394 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3703,6 +3703,7 @@ dependencies = [ name = "uu_id" version = "0.9.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "rustix", diff --git a/src/uu/id/Cargo.toml b/src/uu/id/Cargo.toml index 97ee5d75a35..d8d2cb979cb 100644 --- a/src/uu/id/Cargo.toml +++ b/src/uu/id/Cargo.toml @@ -22,6 +22,9 @@ rustix = { workspace = true } uucore = { workspace = true, features = ["entries", "process"] } fluent = { workspace = true } +[build-dependencies] +cfg_aliases = { workspace = true } + [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] selinux = { workspace = true, optional = true } diff --git a/src/uu/id/build.rs b/src/uu/id/build.rs new file mode 100644 index 00000000000..c0b5558f30e --- /dev/null +++ b/src/uu/id/build.rs @@ -0,0 +1,11 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +pub fn main() { + cfg_aliases::cfg_aliases! { + selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) }, + smack: { all(feature = "smack", target_os = "linux") }, + } +} diff --git a/src/uu/id/src/id.rs b/src/uu/id/src/id.rs index 5b54c4313cd..f40f8cf57dc 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -63,16 +63,9 @@ macro_rules! cstr2cow { } fn get_context_help_text() -> String { - #[cfg(any( - all(feature = "selinux", any(target_os = "android", target_os = "linux")), - all(feature = "smack", target_os = "linux"), - ))] + #[cfg(any(selinux, smack))] return translate!("id-context-help-enabled"); - - #[cfg(not(any( - all(feature = "selinux", any(target_os = "android", target_os = "linux")), - all(feature = "smack", target_os = "linux"), - )))] + #[cfg(not(any(selinux, smack)))] return translate!("id-context-help-disabled"); } @@ -106,9 +99,9 @@ struct State { rflag: bool, // --real zflag: bool, // --zero cflag: bool, // --context - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] selinux_supported: bool, - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] smack_supported: bool, ids: Option, // The behavior for calling GNU's `id` and calling GNU's `id $USER` is similar but different. @@ -147,9 +140,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { rflag: matches.get_flag(options::OPT_REAL_ID), zflag: matches.get_flag(options::OPT_ZERO), cflag: matches.get_flag(options::OPT_CONTEXT), - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] selinux_supported: uucore::selinux::is_selinux_enabled(), - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] smack_supported: uucore::smack::is_smack_enabled(), user_specified: !users.is_empty(), ids: None, @@ -185,7 +178,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if state.cflag { // SELinux context - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if state.selinux_supported { if let Ok(context) = selinux::SecurityContext::current(false) { let bytes = context.as_bytes(); @@ -199,7 +192,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } // SMACK label - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] if state.smack_supported { match uucore::smack::get_smack_label_for_self() { Ok(label) => { @@ -710,7 +703,7 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> { .join(",") )?; - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if state.selinux_supported && !state.user_specified && std::env::var_os("POSIXLY_CORRECT").is_none() @@ -722,7 +715,7 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> { } } - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] if state.smack_supported && !state.user_specified && std::env::var_os("POSIXLY_CORRECT").is_none() From 4659e433ec3a0921be9eaf710c0adf0f2f040b55 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 17 Feb 2026 15:19:32 +0000 Subject: [PATCH 02/10] mkdir: add selinux/smack cfg alias --- Cargo.lock | 1 + src/uu/mkdir/Cargo.toml | 3 +++ src/uu/mkdir/build.rs | 11 +++++++++++ src/uu/mkdir/src/mkdir.rs | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/uu/mkdir/build.rs diff --git a/Cargo.lock b/Cargo.lock index 4fd09729394..70f4296db60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3814,6 +3814,7 @@ dependencies = [ name = "uu_mkdir" version = "0.9.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "rustix", diff --git a/src/uu/mkdir/Cargo.toml b/src/uu/mkdir/Cargo.toml index 460c0f55a76..639014e4987 100644 --- a/src/uu/mkdir/Cargo.toml +++ b/src/uu/mkdir/Cargo.toml @@ -21,6 +21,9 @@ clap = { workspace = true } uucore = { workspace = true, features = ["fs", "mode", "fsxattr"] } fluent = { workspace = true } +[build-dependencies] +cfg_aliases = { workspace = true } + [target.'cfg(unix)'.dependencies] rustix = { workspace = true, features = ["process", "fs"] } diff --git a/src/uu/mkdir/build.rs b/src/uu/mkdir/build.rs new file mode 100644 index 00000000000..c0b5558f30e --- /dev/null +++ b/src/uu/mkdir/build.rs @@ -0,0 +1,11 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +pub fn main() { + cfg_aliases::cfg_aliases! { + selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) }, + smack: { all(feature = "smack", target_os = "linux") }, + } +} diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 138074c4ebc..3c750461e74 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -330,7 +330,7 @@ fn create_single_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<( } // Apply SMACK context if requested - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] if config.set_security_context { uucore::smack::set_smack_label_and_cleanup(path, config.context, |p| { std::fs::remove_dir(p) From b98928b86b94a5bc0e282a397879aaa398de061a Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 17 Feb 2026 15:26:31 +0000 Subject: [PATCH 03/10] mkfifo: add selinux/smack cfg alias --- Cargo.lock | 1 + src/uu/mkfifo/Cargo.toml | 3 +++ src/uu/mkfifo/build.rs | 11 +++++++++++ src/uu/mkfifo/src/mkfifo.rs | 4 ++-- 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/uu/mkfifo/build.rs diff --git a/Cargo.lock b/Cargo.lock index 70f4296db60..8702fb7d5ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3825,6 +3825,7 @@ dependencies = [ name = "uu_mkfifo" version = "0.9.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "libc", diff --git a/src/uu/mkfifo/Cargo.toml b/src/uu/mkfifo/Cargo.toml index 83301784d3c..03df41daa5c 100644 --- a/src/uu/mkfifo/Cargo.toml +++ b/src/uu/mkfifo/Cargo.toml @@ -21,6 +21,9 @@ clap = { workspace = true } uucore = { workspace = true, features = ["fs", "mode"] } fluent = { workspace = true } +[build-dependencies] +cfg_aliases = { workspace = true } + [target.'cfg(unix)'.dependencies] rustix = { workspace = true, features = ["fs", "process"] } diff --git a/src/uu/mkfifo/build.rs b/src/uu/mkfifo/build.rs new file mode 100644 index 00000000000..c0b5558f30e --- /dev/null +++ b/src/uu/mkfifo/build.rs @@ -0,0 +1,11 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +pub fn main() { + cfg_aliases::cfg_aliases! { + selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) }, + smack: { all(feature = "smack", target_os = "linux") }, + } +} diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index f7d11c90cb6..5ed3aeeacf5 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -44,7 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { for f in fifos { // Label the FIFO at creation, as GNU does; relabelling after leaves a window. - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] let _selinux_guard = { let set_security_context = matches.get_flag(options::SECURITY_CONTEXT); let context = matches.get_one::(options::CONTEXT); @@ -83,7 +83,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { )); } else { // Apply SMACK context if requested - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] { let set_security_context = matches.get_flag(options::SECURITY_CONTEXT); let context = matches.get_one::(options::CONTEXT); From 52729e682ed566989d8d66b0ccee71d07d585949 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 17 Feb 2026 15:28:16 +0000 Subject: [PATCH 04/10] mknod: add selinux/smack cfg alias --- Cargo.lock | 1 + src/uu/mkdir/src/mkdir.rs | 2 +- src/uu/mknod/Cargo.toml | 3 +++ src/uu/mknod/build.rs | 11 +++++++++++ src/uu/mknod/src/mknod.rs | 34 ++++++++-------------------------- 5 files changed, 24 insertions(+), 27 deletions(-) create mode 100644 src/uu/mknod/build.rs diff --git a/Cargo.lock b/Cargo.lock index 8702fb7d5ab..152ae1fb613 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3837,6 +3837,7 @@ dependencies = [ name = "uu_mknod" version = "0.9.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "nix", diff --git a/src/uu/mkdir/src/mkdir.rs b/src/uu/mkdir/src/mkdir.rs index 3c750461e74..7169f804dbe 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -308,7 +308,7 @@ fn create_single_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<( let (mkdir_mode, shaped_umask) = (config.mode.unwrap_or(DEFAULT_PERM), 0u32); // Label the directory at creation, as GNU does; relabelling after leaves a window. - #[cfg(all(feature = "selinux", any(target_os = "android", target_os = "linux")))] + #[cfg(selinux)] let _selinux_guard = if config.set_security_context && uucore::selinux::is_selinux_enabled() { let mode = uucore::libc::S_IFDIR | mkdir_mode as uucore::libc::mode_t; match uucore::selinux::FsCreateContext::new(path, Some(mode), config.context) { diff --git a/src/uu/mknod/Cargo.toml b/src/uu/mknod/Cargo.toml index d195140130e..2c260042939 100644 --- a/src/uu/mknod/Cargo.toml +++ b/src/uu/mknod/Cargo.toml @@ -23,6 +23,9 @@ uucore = { workspace = true, features = ["mode", "fs"] } fluent = { workspace = true } nix = { workspace = true } +[build-dependencies] +cfg_aliases = { workspace = true } + [features] selinux = ["uucore/selinux"] smack = ["uucore/smack"] diff --git a/src/uu/mknod/build.rs b/src/uu/mknod/build.rs new file mode 100644 index 00000000000..c0b5558f30e --- /dev/null +++ b/src/uu/mknod/build.rs @@ -0,0 +1,11 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +pub fn main() { + cfg_aliases::cfg_aliases! { + selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) }, + smack: { all(feature = "smack", target_os = "linux") }, + } +} diff --git a/src/uu/mknod/src/mknod.rs b/src/uu/mknod/src/mknod.rs index 2ad79bae9c1..cd1f329c238 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -58,23 +58,17 @@ struct Config { dev: u64, /// Set security context (SELinux/SMACK). - #[cfg(any( - all(feature = "selinux", any(target_os = "android", target_os = "linux")), - all(feature = "smack", target_os = "linux"), - ))] + #[cfg(any(selinux, smack))] set_security_context: bool, /// Specific security context (SELinux/SMACK). - #[cfg(any( - all(feature = "selinux", any(target_os = "android", target_os = "linux")), - all(feature = "smack", target_os = "linux"), - ))] + #[cfg(any(selinux, smack))] context: Option, } fn mknod(file_name: &str, config: Config) -> i32 { // Label the node at creation, as GNU does; relabelling after leaves a window. - #[cfg(all(feature = "selinux", any(target_os = "android", target_os = "linux")))] + #[cfg(selinux)] let _selinux_guard = if config.set_security_context { let mode = config.file_type.as_sflag().bits() | config.mode.bits(); match uucore::selinux::FsCreateContext::new( @@ -123,7 +117,7 @@ fn mknod(file_name: &str, config: Config) -> i32 { } // Apply SMACK context if requested - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] if config.set_security_context && let Err(e) = uucore::smack::set_smack_label_and_cleanup(file_name, config.context.as_ref(), |p| { @@ -158,15 +152,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .expect("Missing argument 'NAME'"); // Extract the security context related flags and options - #[cfg(any( - all(feature = "selinux", any(target_os = "android", target_os = "linux")), - all(feature = "smack", target_os = "linux"), - ))] + #[cfg(any(selinux, smack))] let set_security_context = matches.get_flag(options::SECURITY_CONTEXT); - #[cfg(any( - all(feature = "selinux", any(target_os = "android", target_os = "linux")), - all(feature = "smack", target_os = "linux"), - ))] + #[cfg(any(selinux, smack))] let context = matches.get_one::(options::CONTEXT).cloned(); let dev = match ( @@ -195,15 +183,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { file_type: file_type.clone(), use_umask, dev, - #[cfg(any( - all(feature = "selinux", any(target_os = "android", target_os = "linux")), - all(feature = "smack", target_os = "linux"), - ))] + #[cfg(any(selinux, smack))] set_security_context: set_security_context || context.is_some(), - #[cfg(any( - all(feature = "selinux", any(target_os = "android", target_os = "linux")), - all(feature = "smack", target_os = "linux"), - ))] + #[cfg(any(selinux, smack))] context, }; From 1fc9a621b08a87bee637a96f362f2e9f8a65a397 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 17 Feb 2026 16:09:16 +0000 Subject: [PATCH 05/10] ls: add selinux/smack cfg alias --- Cargo.lock | 1 + src/uu/ls/Cargo.toml | 3 +++ src/uu/ls/build.rs | 11 +++++++++++ src/uu/ls/src/config.rs | 8 ++++---- src/uu/ls/src/ls.rs | 4 ++-- 5 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 src/uu/ls/build.rs diff --git a/Cargo.lock b/Cargo.lock index 152ae1fb613..dc56268dc52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3785,6 +3785,7 @@ name = "uu_ls" version = "0.9.0" dependencies = [ "ansi-width", + "cfg_aliases", "clap", "codspeed-divan-compat", "fluent", diff --git a/src/uu/ls/Cargo.toml b/src/uu/ls/Cargo.toml index b1743c4c585..042670a6727 100644 --- a/src/uu/ls/Cargo.toml +++ b/src/uu/ls/Cargo.toml @@ -57,6 +57,9 @@ divan = { workspace = true } tempfile = { workspace = true } uucore = { workspace = true, features = ["benchmark"] } +[build-dependencies] +cfg_aliases = { workspace = true } + [[bench]] name = "ls_bench" harness = false diff --git a/src/uu/ls/build.rs b/src/uu/ls/build.rs new file mode 100644 index 00000000000..c0b5558f30e --- /dev/null +++ b/src/uu/ls/build.rs @@ -0,0 +1,11 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +pub fn main() { + cfg_aliases::cfg_aliases! { + selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) }, + smack: { all(feature = "smack", target_os = "linux") }, + } +} diff --git a/src/uu/ls/src/config.rs b/src/uu/ls/src/config.rs index 00e6eb766be..052b3513789 100644 --- a/src/uu/ls/src/config.rs +++ b/src/uu/ls/src/config.rs @@ -220,9 +220,9 @@ pub struct Config { pub(crate) time_format_recent: String, // Time format for recent dates pub(crate) time_format_older: Option, // Time format for older dates (optional, if not present, time_format_recent is used) pub(crate) context: bool, - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] pub(crate) selinux_supported: bool, - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] pub(crate) smack_supported: bool, pub(crate) group_directories_first: bool, pub(crate) line_ending: LineEnding, @@ -999,9 +999,9 @@ impl Config { time_format_recent, time_format_older, context, - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] selinux_supported: uucore::selinux::is_selinux_enabled(), - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] smack_supported: uucore::smack::is_smack_enabled(), group_directories_first: options.get_flag(options::GROUP_DIRECTORIES_FIRST), line_ending: LineEnding::from_zero_flag(options.get_flag(options::ZERO)), diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 424a3132bc1..61e4217ae9d 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1600,7 +1600,7 @@ fn get_security_context<'a>( return Cow::Borrowed(SUBSTITUTE_STRING); } - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if config.selinux_supported { use uucore::show_warning; @@ -1642,7 +1642,7 @@ fn get_security_context<'a>( } } - #[cfg(all(feature = "smack", target_os = "linux"))] + #[cfg(smack)] if config.smack_supported { // For SMACK, use the path to get the label // If must_dereference is true, we follow the symlink From 5f1a42c7532a2789df56bec2460e4d5dde78067b Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 17 Feb 2026 16:14:16 +0000 Subject: [PATCH 06/10] stat: add selinux cfg alias --- Cargo.lock | 1 + src/uu/stat/Cargo.toml | 3 +++ src/uu/stat/build.rs | 10 ++++++++++ src/uu/stat/src/stat.rs | 16 ++++------------ 4 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 src/uu/stat/build.rs diff --git a/Cargo.lock b/Cargo.lock index dc56268dc52..3e574990e54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4233,6 +4233,7 @@ dependencies = [ name = "uu_stat" version = "0.9.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "thiserror 2.0.19", diff --git a/src/uu/stat/Cargo.toml b/src/uu/stat/Cargo.toml index ef863228749..b13c947f467 100644 --- a/src/uu/stat/Cargo.toml +++ b/src/uu/stat/Cargo.toml @@ -29,6 +29,9 @@ uucore = { workspace = true, features = [ thiserror = { workspace = true } fluent = { workspace = true } +[build-dependencies] +cfg_aliases = { workspace = true } + [features] selinux = ["uucore/selinux"] diff --git a/src/uu/stat/build.rs b/src/uu/stat/build.rs new file mode 100644 index 00000000000..d681e67d433 --- /dev/null +++ b/src/uu/stat/build.rs @@ -0,0 +1,10 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +pub fn main() { + cfg_aliases::cfg_aliases! { + selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) }, + } +} diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index 8e1f76779a1..986132a4b50 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -1058,10 +1058,8 @@ impl Stater { file: &OsString, file_type: FileType, from_user: bool, - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] - follow_symbolic_links: bool, - #[cfg(not(all(feature = "selinux", any(target_os = "linux", target_os = "android"))))] - _: bool, + #[cfg(selinux)] follow_symbolic_links: bool, + #[cfg(not(selinux))] _: bool, ) -> Result<(), i32> { match *t { Token::Byte(byte) => print_raw_byte(byte), @@ -1087,10 +1085,7 @@ impl Stater { 'B' => OutputType::Unsigned(512), // SELinux security context string 'C' => { - #[cfg(all( - feature = "selinux", - any(target_os = "linux", target_os = "android") - ))] + #[cfg(selinux)] { if uucore::selinux::is_selinux_enabled() { match uucore::selinux::get_selinux_security_context( @@ -1106,10 +1101,7 @@ impl Stater { OutputType::Str(translate!("stat-selinux-unsupported-system")) } } - #[cfg(not(all( - feature = "selinux", - any(target_os = "linux", target_os = "android") - )))] + #[cfg(not(selinux))] { OutputType::Str(translate!("stat-selinux-unsupported-os")) } From a3d4f929ecce74656eb446256f8748a9a8414768 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Wed, 18 Feb 2026 18:55:46 +0000 Subject: [PATCH 07/10] cp: add selinux cfg alias --- Cargo.lock | 1 + src/uu/cp/Cargo.toml | 3 +++ src/uu/cp/build.rs | 10 ++++++++++ src/uu/cp/src/copydir.rs | 6 +++--- src/uu/cp/src/cp.rs | 12 ++++++------ 5 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 src/uu/cp/build.rs diff --git a/Cargo.lock b/Cargo.lock index 3e574990e54..5d97b0d95b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3428,6 +3428,7 @@ dependencies = [ name = "uu_cp" version = "0.9.0" dependencies = [ + "cfg_aliases", "clap", "codspeed-divan-compat", "exacl", diff --git a/src/uu/cp/Cargo.toml b/src/uu/cp/Cargo.toml index 43e6918cb65..d5c61429dd0 100644 --- a/src/uu/cp/Cargo.toml +++ b/src/uu/cp/Cargo.toml @@ -59,6 +59,9 @@ divan = { workspace = true } tempfile = { workspace = true } uucore = { workspace = true, features = ["benchmark"] } +[build-dependencies] +cfg_aliases = { workspace = true } + [[bench]] name = "cp_bench" harness = false diff --git a/src/uu/cp/build.rs b/src/uu/cp/build.rs new file mode 100644 index 00000000000..d681e67d433 --- /dev/null +++ b/src/uu/cp/build.rs @@ -0,0 +1,10 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +pub fn main() { + cfg_aliases::cfg_aliases! { + selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) }, + } +} diff --git a/src/uu/cp/src/copydir.rs b/src/uu/cp/src/copydir.rs index cafb33fbaab..a407b9c72d5 100644 --- a/src/uu/cp/src/copydir.rs +++ b/src/uu/cp/src/copydir.rs @@ -26,7 +26,7 @@ use uucore::translate; use uucore::uio_error; use walkdir::{DirEntry, WalkDir}; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] use crate::set_selinux_context; use crate::{ CopyMode, CopyResult, CpError, Options, aligned_ancestors, context_for, copy_attributes, @@ -585,7 +585,7 @@ pub(crate) fn copy_directory( options.set_selinux_context, )?; - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if options.set_selinux_context { set_selinux_context(&dir.dest, options.context.as_ref())?; } @@ -607,7 +607,7 @@ pub(crate) fn copy_directory( options.set_selinux_context, )?; - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if options.set_selinux_context { set_selinux_context(y, options.context.as_ref())?; } diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 75f79816a5a..95b32ebd65f 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -885,11 +885,11 @@ impl Attributes { mode: Preserve::Yes { required: true }, timestamps: Preserve::Yes { required: true }, context: { - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] { Preserve::Yes { required: false } } - #[cfg(not(all(feature = "selinux", any(target_os = "linux", target_os = "android"))))] + #[cfg(not(selinux))] { Preserve::No { explicit: false } } @@ -1183,7 +1183,7 @@ impl Options { } } - #[cfg(not(all(feature = "selinux", any(target_os = "linux", target_os = "android"))))] + #[cfg(not(selinux))] if let Preserve::Yes { required } = attributes.context { let selinux_disabled_error = CpError::Error(translate!("cp-error-selinux-not-enabled")); if required { @@ -1728,7 +1728,7 @@ fn handle_preserve CopyResult<()>>(p: Preserve, f: F) -> CopyResult<( Ok(()) } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] pub(crate) fn set_selinux_context(path: &Path, context: Option<&String>) -> CopyResult<()> { if !uucore::selinux::is_selinux_enabled() { return Ok(()); @@ -1930,7 +1930,7 @@ pub(crate) fn copy_attributes( Ok(()) })?; - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] handle_preserve(attributes.context, || -> CopyResult<()> { // Get the source context and apply it to the destination let context = selinux::SecurityContext::of_path(source, false, false).map_err(|_| { @@ -2742,7 +2742,7 @@ fn copy_file( fs::File::create(dest).map(|f| f.set_len(0)).ok(); })?; - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if options.set_selinux_context { set_selinux_context(dest, options.context.as_ref())?; } From aa283d097881d3e89db8cd14cb624761ef53659e Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 17 Feb 2026 16:18:15 +0000 Subject: [PATCH 08/10] uucore: add selinux/smack cfg alias --- Cargo.lock | 1 + fuzz/Cargo.lock | 5 +++-- src/uucore/Cargo.toml | 3 +++ src/uucore/build.rs | 5 +++++ src/uucore/src/lib/features.rs | 4 ++-- src/uucore/src/lib/lib.rs | 4 ++-- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5d97b0d95b4..91e41ee2de6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4561,6 +4561,7 @@ dependencies = [ "blake2b_simd", "blake3", "bstr", + "cfg_aliases", "clap", "codspeed-divan-compat", "crc-fast", diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 3ad2a7b57ff..bc26b7b7fb6 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -231,9 +231,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "cfg_aliases" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" [[package]] name = "chacha20" @@ -2108,6 +2108,7 @@ dependencies = [ "bigdecimal", "blake2b_simd", "blake3", + "cfg_aliases", "clap", "crc-fast", "data-encoding", diff --git a/src/uucore/Cargo.toml b/src/uucore/Cargo.toml index 3e96a3301ff..6aabf6dce0d 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -96,6 +96,9 @@ thiserror = { workspace = true } [dev-dependencies] tempfile = { workspace = true } +[build-dependencies] +cfg_aliases = { workspace = true } + [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] selinux = { workspace = true, optional = true } diff --git a/src/uucore/build.rs b/src/uucore/build.rs index 27c2dfb2832..a89517d1661 100644 --- a/src/uucore/build.rs +++ b/src/uucore/build.rs @@ -9,6 +9,11 @@ use std::io::Write; use std::path::{Path, PathBuf}; pub fn main() -> Result<(), Box> { + cfg_aliases::cfg_aliases! { + selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) }, + smack: { all(feature = "smack", target_os = "linux") }, + } + let out_dir = env::var("OUT_DIR")?; let mut embedded_file = File::create(Path::new(&out_dir).join("embedded_locales.rs"))?; diff --git a/src/uucore/src/lib/features.rs b/src/uucore/src/lib/features.rs index 33dcd17786f..facadc9e869 100644 --- a/src/uucore/src/lib/features.rs +++ b/src/uucore/src/lib/features.rs @@ -87,14 +87,14 @@ pub mod tty; pub mod fsxattr; #[cfg(feature = "hardware")] pub mod hardware; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] pub mod selinux; #[cfg(all( any(windows, all(unix, not(target_os = "fuchsia"))), feature = "signals" ))] pub mod signals; -#[cfg(all(feature = "smack", target_os = "linux"))] +#[cfg(smack)] pub mod smack; #[cfg(feature = "feat_systemd_logind")] pub mod systemd_logind; diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index aeacfe01fc6..f392396119a 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -131,10 +131,10 @@ pub use crate::features::fsext; #[cfg(all(unix, feature = "fsxattr"))] pub use crate::features::fsxattr; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] pub use crate::features::selinux; -#[cfg(all(feature = "smack", target_os = "linux"))] +#[cfg(smack)] pub use crate::features::smack; //## core functions From edfa2084f541b1a4c6eb4e0731eee99bc01f4950 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 17 Feb 2026 15:12:25 +0000 Subject: [PATCH 09/10] mv: add selinux cfg alias --- Cargo.lock | 1 + src/uu/mv/Cargo.toml | 3 +++ src/uu/mv/build.rs | 10 ++++++++++ src/uu/mv/src/mv.rs | 4 ++-- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 src/uu/mv/build.rs diff --git a/Cargo.lock b/Cargo.lock index 91e41ee2de6..e0ef3498ea0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3873,6 +3873,7 @@ dependencies = [ name = "uu_mv" version = "0.9.0" dependencies = [ + "cfg_aliases", "clap", "codspeed-divan-compat", "fluent", diff --git a/src/uu/mv/Cargo.toml b/src/uu/mv/Cargo.toml index a7a041c74e8..a1b6e73233d 100644 --- a/src/uu/mv/Cargo.toml +++ b/src/uu/mv/Cargo.toml @@ -57,6 +57,9 @@ divan = { workspace = true } tempfile = { workspace = true } uucore = { workspace = true, features = ["benchmark"] } +[build-dependencies] +cfg_aliases = { workspace = true } + [lints] workspace = true diff --git a/src/uu/mv/build.rs b/src/uu/mv/build.rs new file mode 100644 index 00000000000..d681e67d433 --- /dev/null +++ b/src/uu/mv/build.rs @@ -0,0 +1,10 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +pub fn main() { + cfg_aliases::cfg_aliases! { + selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) }, + } +} diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index af41cdd91d6..0ad7f60c076 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -46,7 +46,7 @@ use uucore::fs::{ }; #[cfg(all(unix, not(any(target_os = "macos", target_os = "redox"))))] use uucore::fsxattr; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] use uucore::selinux::set_selinux_security_context; use uucore::translate; use uucore::update_control; @@ -860,7 +860,7 @@ fn rename( rename_with_fallback(from, to, display_manager, opts.verbose, None, None)?; } - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if let Some(ref context) = opts.context { set_selinux_security_context(to, Some(context)) .map_err(|e| io::Error::other(e.to_string()))?; From ff464bce83dbc3a43f11ec70a250c79320c2cc55 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 17 Feb 2026 16:05:24 +0000 Subject: [PATCH 10/10] install: add selinux cfg alias --- Cargo.lock | 1 + src/uu/install/Cargo.toml | 3 +++ src/uu/install/build.rs | 10 +++++++++ src/uu/install/src/install.rs | 39 ++++++++++++++++------------------- 4 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 src/uu/install/build.rs diff --git a/Cargo.lock b/Cargo.lock index e0ef3498ea0..2701c194517 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3716,6 +3716,7 @@ dependencies = [ name = "uu_install" version = "0.9.0" dependencies = [ + "cfg_aliases", "clap", "file_diff", "filetime", diff --git a/src/uu/install/Cargo.toml b/src/uu/install/Cargo.toml index 3843d597949..80ed149573f 100644 --- a/src/uu/install/Cargo.toml +++ b/src/uu/install/Cargo.toml @@ -30,6 +30,9 @@ uucore = { workspace = true, default-features = true, features = [ ] } fluent = { workspace = true } +[build-dependencies] +cfg_aliases = { workspace = true } + [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] rustix = { workspace = true } selinux = { workspace = true, optional = true } diff --git a/src/uu/install/build.rs b/src/uu/install/build.rs new file mode 100644 index 00000000000..d681e67d433 --- /dev/null +++ b/src/uu/install/build.rs @@ -0,0 +1,10 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. + +pub fn main() { + cfg_aliases::cfg_aliases! { + selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) }, + } +} diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 34eb2c05900..19f6fd7e993 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -10,7 +10,7 @@ mod mode; use clap::{Arg, ArgAction, ArgMatches, Command}; use file_diff::diff; use filetime::{FileTime, set_file_times}; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] use selinux::SecurityContext; use std::ffi::OsString; use std::fmt::Debug; @@ -30,7 +30,7 @@ use uucore::perms::{Verbosity, VerbosityLevel, wrap_chown}; use uucore::process::{getegid, geteuid}; #[cfg(unix)] use uucore::safe_traversal::{DirFd, SymlinkBehavior, create_dir_all_safe}; -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] use uucore::selinux::{ SeLinuxError, contexts_differ, get_selinux_security_context, is_selinux_enabled, selinux_error_description, set_selinux_security_context, @@ -130,7 +130,7 @@ enum InstallError { #[error("{}", translate!("install-error-extra-operand", "operand" => .0.quote(), "usage" => .1.clone()))] ExtraOperand(OsString, String), - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] #[error("{}", .0)] SelinuxContextFailed(String), @@ -519,7 +519,7 @@ fn directory(paths: &[OsString], b: &Behavior) -> UResult<()> { } // Set SELinux context for all created directories if needed - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if should_set_selinux_context(b) { let context = get_context_for_selinux(b); set_selinux_context_for_directories_install(path_to_create.as_path(), context); @@ -545,7 +545,7 @@ fn directory(paths: &[OsString], b: &Behavior) -> UResult<()> { } // Set SELinux context for directory if needed - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if b.privileged { if b.default_context { show_if_err!(set_selinux_default_context(path)); @@ -716,10 +716,7 @@ fn standard(mut paths: Vec, b: &Behavior) -> UResult<()> { } // Set SELinux context for all created directories if needed - #[cfg(all( - feature = "selinux", - any(target_os = "linux", target_os = "android") - ))] + #[cfg(selinux)] if should_set_selinux_context(b) { let context = get_context_for_selinux(b); set_selinux_context_for_directories_install(to_create, context); @@ -1139,7 +1136,7 @@ fn finalize_installed_file( preserve_timestamps(from, to)?; } - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if b.privileged { if b.preserve_context { uucore::selinux::preserve_security_context(from, to) @@ -1194,7 +1191,7 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> UResult<()> { finalize_installed_file(from, to, b, backup_path) } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] fn get_context_for_selinux(b: &Behavior) -> Option<&String> { if b.default_context { None @@ -1203,7 +1200,7 @@ fn get_context_for_selinux(b: &Behavior) -> Option<&String> { } } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] fn should_set_selinux_context(b: &Behavior) -> bool { b.privileged && (b.context.is_some() || b.default_context) } @@ -1305,7 +1302,7 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool { } if b.privileged { - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if b.preserve_context && contexts_differ(from, to) { return true; } @@ -1334,7 +1331,7 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool { false } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] /// Sets the `SELinux` security context for install's -Z flag behavior. /// /// This function implements the specific behavior needed for install's -Z flag, @@ -1368,7 +1365,7 @@ pub fn set_selinux_default_context(path: &Path) -> Result<(), SeLinuxError> { } } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] /// Gets the default `SELinux` context for a path based on the system's security policy. /// /// This function attempts to determine what the "correct" `SELinux` context should be @@ -1423,7 +1420,7 @@ fn get_default_context_for_path(path: &Path) -> Result, SeLinuxEr Ok(None) } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] /// Derives an appropriate `SELinux` context based on a parent directory context. /// /// This is a heuristic function that attempts to generate an appropriate @@ -1456,7 +1453,7 @@ fn derive_context_from_parent(parent_context: &str) -> String { } } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] /// Helper function to collect paths that need `SELinux` context setting. /// /// Traverses from the given starting path up to existing parent directories. @@ -1470,7 +1467,7 @@ fn collect_paths_for_context_setting(starting_path: &Path) -> Vec<&Path> { paths } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] /// Sets the `SELinux` security context for a directory hierarchy. /// /// This function traverses from the given starting path up to existing parent directories @@ -1510,7 +1507,7 @@ fn set_selinux_context_for_directories(target_path: &Path, context: Option<&Stri } } -#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] +#[cfg(selinux)] /// Sets `SELinux` context for created directories using install's -Z default behavior. /// /// Similar to `set_selinux_context_for_directories` but uses install's @@ -1534,10 +1531,10 @@ pub fn set_selinux_context_for_directories_install(target_path: &Path, context: #[cfg(test)] mod tests { - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] use super::derive_context_from_parent; - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] #[test] fn test_derive_context_from_parent() { // Test cases: (input_context, file_type, expected_output, description)