From 48033eec091f6e17e21c711ac112d8987a179191 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Fri, 23 Jan 2026 00:10:12 +0000 Subject: [PATCH 01/11] deps: add rust crate cfg_aliases --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 1aa3892798e..4df212023b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -318,6 +318,7 @@ binary-heap-plus = "0.5.0" bstr = "1.9.1" bytecount = "0.6.8" byteorder = "1.5.0" +cfg_aliases = "0.2.1" clap = { version = "4.5", features = ["wrap_help", "cargo", "color"] } clap_complete = "4.4" clap_mangen = "0.2" From b33cc1d9e7563e04e3fc011217ace9ba448baef7 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 02/11] id: add selinux/smack cfg alias --- Cargo.lock | 1 + src/uu/id/Cargo.toml | 3 +++ src/uu/id/build.rs | 13 +++++++++++++ src/uu/id/src/id.rs | 20 ++++++++++---------- 4 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 src/uu/id/build.rs diff --git a/Cargo.lock b/Cargo.lock index 478e55e0b08..02e98374237 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3563,6 +3563,7 @@ dependencies = [ name = "uu_id" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "selinux", diff --git a/src/uu/id/Cargo.toml b/src/uu/id/Cargo.toml index ce31a65f5e9..8e585ff4f6b 100644 --- a/src/uu/id/Cargo.toml +++ b/src/uu/id/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/id.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } uucore = { workspace = true, features = ["entries", "process"] } diff --git a/src/uu/id/build.rs b/src/uu/id/build.rs new file mode 100644 index 00000000000..bbb41ab4715 --- /dev/null +++ b/src/uu/id/build.rs @@ -0,0 +1,13 @@ +// 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. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + 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 d15101a46a4..b6814a6f92e 100644 --- a/src/uu/id/src/id.rs +++ b/src/uu/id/src/id.rs @@ -63,9 +63,9 @@ macro_rules! cstr2cow { } fn get_context_help_text() -> String { - #[cfg(not(any(feature = "selinux", feature = "smack")))] + #[cfg(not(any(selinux, smack)))] return translate!("id-context-help-disabled"); - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] return translate!("id-context-help-enabled"); } @@ -99,9 +99,9 @@ struct State { rflag: bool, // --real zflag: bool, // --zero cflag: bool, // --context - #[cfg(feature = "selinux")] + #[cfg(selinux)] selinux_supported: bool, - #[cfg(feature = "smack")] + #[cfg(smack)] smack_supported: bool, ids: Option, // The behavior for calling GNU's `id` and calling GNU's `id $USER` is similar but different. @@ -141,9 +141,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { zflag: matches.get_flag(options::OPT_ZERO), cflag: matches.get_flag(options::OPT_CONTEXT), - #[cfg(feature = "selinux")] + #[cfg(selinux)] selinux_supported: uucore::selinux::is_selinux_enabled(), - #[cfg(feature = "smack")] + #[cfg(smack)] smack_supported: uucore::smack::is_smack_enabled(), user_specified: !users.is_empty(), ids: None, @@ -179,7 +179,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if state.cflag { // SELinux context - #[cfg(feature = "selinux")] + #[cfg(selinux)] if state.selinux_supported { if let Ok(context) = selinux::SecurityContext::current(false) { let bytes = context.as_bytes(); @@ -193,7 +193,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } // SMACK label - #[cfg(feature = "smack")] + #[cfg(smack)] if state.smack_supported { match uucore::smack::get_smack_label_for_self() { Ok(label) => { @@ -702,7 +702,7 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> { .join(",") )?; - #[cfg(feature = "selinux")] + #[cfg(selinux)] if state.selinux_supported && !state.user_specified && std::env::var_os("POSIXLY_CORRECT").is_none() @@ -714,7 +714,7 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> { } } - #[cfg(feature = "smack")] + #[cfg(smack)] if state.smack_supported && !state.user_specified && std::env::var_os("POSIXLY_CORRECT").is_none() From 0b25334824395319b895b799e5f619644fcb4548 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 03/11] mkdir: add selinux/smack cfg alias --- Cargo.lock | 1 + src/uu/mkdir/Cargo.toml | 3 +++ src/uu/mkdir/build.rs | 13 +++++++++++++ src/uu/mkdir/src/mkdir.rs | 4 ++-- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/uu/mkdir/build.rs diff --git a/Cargo.lock b/Cargo.lock index 02e98374237..3962a5b8cb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3669,6 +3669,7 @@ dependencies = [ name = "uu_mkdir" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "uucore", diff --git a/src/uu/mkdir/Cargo.toml b/src/uu/mkdir/Cargo.toml index 6e2e082d044..5495c10c1d3 100644 --- a/src/uu/mkdir/Cargo.toml +++ b/src/uu/mkdir/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/mkdir.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } uucore = { workspace = true, features = ["fs", "mode", "fsxattr"] } diff --git a/src/uu/mkdir/build.rs b/src/uu/mkdir/build.rs new file mode 100644 index 00000000000..bbb41ab4715 --- /dev/null +++ b/src/uu/mkdir/build.rs @@ -0,0 +1,13 @@ +// 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. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + 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 3d0a9bc33c9..9bdc5467493 100644 --- a/src/uu/mkdir/src/mkdir.rs +++ b/src/uu/mkdir/src/mkdir.rs @@ -333,7 +333,7 @@ fn create_single_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<( } // Apply SELinux context if requested - #[cfg(feature = "selinux")] + #[cfg(selinux)] if config.set_security_context && uucore::selinux::is_selinux_enabled() { if let Err(e) = uucore::selinux::set_selinux_security_context(path, config.context) { @@ -343,7 +343,7 @@ fn create_single_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<( } // Apply SMACK context if requested - #[cfg(feature = "smack")] + #[cfg(smack)] if config.set_security_context { uucore::smack::set_smack_label_and_cleanup(path, config.context, |p| { std::fs::remove_dir(p) From d5f10d6a0ef892604fa9bc43bc3008189bed8640 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 04/11] mkfifo: add selinux/smack cfg alias --- Cargo.lock | 1 + src/uu/mkfifo/Cargo.toml | 3 +++ src/uu/mkfifo/build.rs | 13 +++++++++++++ src/uu/mkfifo/src/mkfifo.rs | 4 ++-- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/uu/mkfifo/build.rs diff --git a/Cargo.lock b/Cargo.lock index 3962a5b8cb4..30ef0a97dae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3679,6 +3679,7 @@ dependencies = [ name = "uu_mkfifo" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "nix", diff --git a/src/uu/mkfifo/Cargo.toml b/src/uu/mkfifo/Cargo.toml index 594b91ae764..e9ec8320e26 100644 --- a/src/uu/mkfifo/Cargo.toml +++ b/src/uu/mkfifo/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/mkfifo.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } uucore = { workspace = true, features = ["fs", "mode"] } diff --git a/src/uu/mkfifo/build.rs b/src/uu/mkfifo/build.rs new file mode 100644 index 00000000000..bbb41ab4715 --- /dev/null +++ b/src/uu/mkfifo/build.rs @@ -0,0 +1,13 @@ +// 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. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + 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 a70d140c7c6..ede515beb5c 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -65,7 +65,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } // Apply SELinux context if requested - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] { // Extract the SELinux related flags and options let set_security_context = matches.get_flag(options::SECURITY_CONTEXT); @@ -83,7 +83,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } // Apply SMACK context if requested - #[cfg(feature = "smack")] + #[cfg(smack)] { let set_security_context = matches.get_flag(options::SECURITY_CONTEXT); let context = matches.get_one::(options::CONTEXT); From d712bc12ecd97b501b087805b530bae74a482fd6 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 05/11] mknod: add selinux/smack cfg alias --- Cargo.lock | 1 + src/uu/mknod/Cargo.toml | 3 +++ src/uu/mknod/build.rs | 13 +++++++++++++ src/uu/mknod/src/mknod.rs | 16 ++++++++-------- 4 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 src/uu/mknod/build.rs diff --git a/Cargo.lock b/Cargo.lock index 30ef0a97dae..0ee90174a87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3690,6 +3690,7 @@ dependencies = [ name = "uu_mknod" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "nix", diff --git a/src/uu/mknod/Cargo.toml b/src/uu/mknod/Cargo.toml index 2bdcfe5ad91..59bd12242b3 100644 --- a/src/uu/mknod/Cargo.toml +++ b/src/uu/mknod/Cargo.toml @@ -19,6 +19,9 @@ workspace = true name = "uu_mknod" path = "src/mknod.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } uucore = { workspace = true, features = ["mode", "fs"] } diff --git a/src/uu/mknod/build.rs b/src/uu/mknod/build.rs new file mode 100644 index 00000000000..bbb41ab4715 --- /dev/null +++ b/src/uu/mknod/build.rs @@ -0,0 +1,13 @@ +// 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. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + 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 9b6ab45f648..37c08cf173c 100644 --- a/src/uu/mknod/src/mknod.rs +++ b/src/uu/mknod/src/mknod.rs @@ -57,11 +57,11 @@ struct Config { dev: u64, /// Set security context (SELinux/SMACK). - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] set_security_context: bool, /// Specific security context (SELinux/SMACK). - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] context: Option, } @@ -96,7 +96,7 @@ fn mknod(file_name: &str, config: Config) -> i32 { } // Apply SELinux context if requested - #[cfg(feature = "selinux")] + #[cfg(selinux)] if config.set_security_context { if let Err(e) = uucore::selinux::set_selinux_security_context( std::path::Path::new(file_name), @@ -110,7 +110,7 @@ fn mknod(file_name: &str, config: Config) -> i32 { } // Apply SMACK context if requested - #[cfg(feature = "smack")] + #[cfg(smack)] if config.set_security_context { if let Err(e) = uucore::smack::set_smack_label_and_cleanup(file_name, config.context.as_ref(), |p| { @@ -146,9 +146,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .expect("Missing argument 'NAME'"); // Extract the security context related flags and options - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] let set_security_context = matches.get_flag(options::SECURITY_CONTEXT); - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] let context = matches.get_one::(options::CONTEXT).cloned(); let dev = match ( @@ -177,9 +177,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { file_type: file_type.clone(), use_umask, dev, - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] set_security_context: set_security_context || context.is_some(), - #[cfg(any(feature = "selinux", feature = "smack"))] + #[cfg(any(selinux, smack))] context, }; From 598222a1edbde6ed811d8c8e8a4bb681c194b451 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 06/11] ls: add selinux/smack cfg alias --- Cargo.lock | 1 + src/uu/ls/Cargo.toml | 3 +++ src/uu/ls/build.rs | 13 +++++++++++++ src/uu/ls/src/ls.rs | 12 ++++++------ 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 src/uu/ls/build.rs diff --git a/Cargo.lock b/Cargo.lock index 0ee90174a87..af9d7c5a116 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3640,6 +3640,7 @@ name = "uu_ls" version = "0.6.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 a82ad13c397..4ab2d3bb1da 100644 --- a/src/uu/ls/Cargo.toml +++ b/src/uu/ls/Cargo.toml @@ -20,6 +20,9 @@ workspace = true [lib] path = "src/ls.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] ansi-width = { workspace = true } clap = { workspace = true, features = ["env"] } diff --git a/src/uu/ls/build.rs b/src/uu/ls/build.rs new file mode 100644 index 00000000000..bbb41ab4715 --- /dev/null +++ b/src/uu/ls/build.rs @@ -0,0 +1,13 @@ +// 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. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + 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/ls.rs b/src/uu/ls/src/ls.rs index afbd8f307a1..1c695618184 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -375,9 +375,9 @@ pub struct Config { time_format_recent: String, // Time format for recent dates time_format_older: Option, // Time format for older dates (optional, if not present, time_format_recent is used) context: bool, - #[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, group_directories_first: bool, line_ending: LineEnding, @@ -1237,9 +1237,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)), @@ -3595,7 +3595,7 @@ fn get_security_context<'a>( } } - #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] + #[cfg(selinux)] if config.selinux_supported { match selinux::SecurityContext::of_path(path, must_dereference, false) { Err(_r) => { @@ -3633,7 +3633,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 d55424d543a97b6c19b6d75611096773d7895e13 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 07/11] stat: add selinux cfg alias --- Cargo.lock | 1 + src/uu/stat/Cargo.toml | 3 +++ src/uu/stat/build.rs | 12 ++++++++++++ src/uu/stat/src/stat.rs | 16 ++++------------ 4 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 src/uu/stat/build.rs diff --git a/Cargo.lock b/Cargo.lock index af9d7c5a116..eec02455495 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4078,6 +4078,7 @@ dependencies = [ name = "uu_stat" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "fluent", "thiserror 2.0.18", diff --git a/src/uu/stat/Cargo.toml b/src/uu/stat/Cargo.toml index d01a713ec3c..d777ec95ccc 100644 --- a/src/uu/stat/Cargo.toml +++ b/src/uu/stat/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/stat.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } uucore = { workspace = true, features = [ diff --git a/src/uu/stat/build.rs b/src/uu/stat/build.rs new file mode 100644 index 00000000000..843ded9e78c --- /dev/null +++ b/src/uu/stat/build.rs @@ -0,0 +1,12 @@ +// 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. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + 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 e91e0f3eb93..0f1207c681c 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -1033,10 +1033,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) => write_raw_byte(byte), @@ -1062,10 +1060,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( @@ -1081,10 +1076,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 538038b1779c5a20e8295bb32fed27b138946fd7 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 08/11] cp: add selinux cfg alias --- Cargo.lock | 1 + src/uu/cp/Cargo.toml | 3 +++ src/uu/cp/build.rs | 12 ++++++++++++ src/uu/cp/src/copydir.rs | 6 +++--- src/uu/cp/src/cp.rs | 12 ++++++------ 5 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 src/uu/cp/build.rs diff --git a/Cargo.lock b/Cargo.lock index eec02455495..a80773b57d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3296,6 +3296,7 @@ dependencies = [ name = "uu_cp" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "codspeed-divan-compat", "exacl", diff --git a/src/uu/cp/Cargo.toml b/src/uu/cp/Cargo.toml index 79e00d6bb0b..c7b35aa7219 100644 --- a/src/uu/cp/Cargo.toml +++ b/src/uu/cp/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/cp.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } filetime = { workspace = true } diff --git a/src/uu/cp/build.rs b/src/uu/cp/build.rs new file mode 100644 index 00000000000..843ded9e78c --- /dev/null +++ b/src/uu/cp/build.rs @@ -0,0 +1,12 @@ +// 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. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + 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 8241d1310b4..72655842849 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", target_os = "linux"))] +#[cfg(selinux)] use crate::set_selinux_context; use crate::{ CopyMode, CopyResult, CpError, Options, aligned_ancestors, context_for, copy_attributes, @@ -562,7 +562,7 @@ pub(crate) fn copy_directory( options.set_selinux_context, )?; - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if options.set_selinux_context { set_selinux_context(&dir.dest, options.context.as_ref())?; } @@ -582,7 +582,7 @@ pub(crate) fn copy_directory( options.set_selinux_context, )?; - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[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 3c3b057098e..65071d7fe65 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -896,11 +896,11 @@ impl Attributes { mode: Preserve::Yes { required: true }, timestamps: Preserve::Yes { required: true }, context: { - #[cfg(feature = "feat_selinux")] + #[cfg(selinux)] { Preserve::Yes { required: false } } - #[cfg(not(feature = "feat_selinux"))] + #[cfg(not(selinux))] { Preserve::No { explicit: false } } @@ -1141,7 +1141,7 @@ impl Options { } } - #[cfg(not(feature = "selinux"))] + #[cfg(not(selinux))] if let Preserve::Yes { required } = attributes.context { let selinux_disabled_error = CpError::Error(translate!("cp-error-selinux-not-enabled")); if required { @@ -1692,7 +1692,7 @@ fn handle_preserve CopyResult<()>>(p: Preserve, f: F) -> CopyResult<( Ok(()) } -#[cfg(all(feature = "selinux", target_os = "linux"))] +#[cfg(selinux)] pub(crate) fn set_selinux_context(path: &Path, context: Option<&String>) -> CopyResult<()> { if !uucore::selinux::is_selinux_enabled() { return Ok(()); @@ -1846,7 +1846,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 if let Ok(context) = selinux::SecurityContext::of_path(source, false, false) { @@ -2658,7 +2658,7 @@ fn copy_file( fs::File::create(dest).map(|f| f.set_len(0)).ok(); })?; - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if options.set_selinux_context { set_selinux_context(dest, options.context.as_ref())?; } From e748dbebb131b18397445dadc36e6960ad96bfae 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 09/11] uucore: add selinux/smack cfg alias --- Cargo.lock | 1 + fuzz/Cargo.lock | 1 + src/uucore/Cargo.toml | 3 +++ src/uucore/build.rs | 6 ++++++ src/uucore/src/lib/features.rs | 4 ++-- src/uucore/src/lib/lib.rs | 4 ++-- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a80773b57d0..4c1619602d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4392,6 +4392,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 520fd775028..a3764139978 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -1933,6 +1933,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 29a7189d444..66f3dd19416 100644 --- a/src/uucore/Cargo.toml +++ b/src/uucore/Cargo.toml @@ -22,6 +22,9 @@ workspace = true [lib] path = "src/lib/lib.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] bstr = { workspace = true, optional = true } clap = { workspace = true } diff --git a/src/uucore/build.rs b/src/uucore/build.rs index 15068f28aab..389a0d523c1 100644 --- a/src/uucore/build.rs +++ b/src/uucore/build.rs @@ -3,12 +3,18 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. +use cfg_aliases::cfg_aliases; use std::env; use std::fs::File; use std::io::Write; use std::path::{Path, PathBuf}; pub fn main() -> Result<(), Box> { + 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 03d4101607b..677251a1cce 100644 --- a/src/uucore/src/lib/features.rs +++ b/src/uucore/src/lib/features.rs @@ -81,11 +81,11 @@ 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(unix, not(target_os = "fuchsia"), feature = "signals"))] pub mod signals; -#[cfg(all(target_os = "linux", feature = "smack"))] +#[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 4b2cb9b502b..ee9af7872c0 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -122,10 +122,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(target_os = "linux", feature = "smack"))] +#[cfg(smack)] pub use crate::features::smack; //## core functions From a0ac0ff916704befce21c6c3639c22b7c1fb5f22 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 10/11] mv: add selinux cfg alias --- Cargo.lock | 1 + src/uu/mv/Cargo.toml | 3 +++ src/uu/mv/build.rs | 12 ++++++++++++ src/uu/mv/src/mv.rs | 4 ++-- 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/uu/mv/build.rs diff --git a/Cargo.lock b/Cargo.lock index 4c1619602d1..2dda10162c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3726,6 +3726,7 @@ dependencies = [ name = "uu_mv" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "codspeed-divan-compat", "fluent", diff --git a/src/uu/mv/Cargo.toml b/src/uu/mv/Cargo.toml index 5cba2d472ae..84d5f0ffbef 100644 --- a/src/uu/mv/Cargo.toml +++ b/src/uu/mv/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/mv.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } fs_extra = { workspace = true } diff --git a/src/uu/mv/build.rs b/src/uu/mv/build.rs new file mode 100644 index 00000000000..843ded9e78c --- /dev/null +++ b/src/uu/mv/build.rs @@ -0,0 +1,12 @@ +// 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. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + 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 42e1a9f127e..85b0da724cc 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -47,7 +47,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; @@ -770,7 +770,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 0fcde2dfa969f0cf484278728490a4099ac50f5b 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 11/11] install: add selinux cfg alias --- Cargo.lock | 1 + src/uu/install/Cargo.toml | 3 +++ src/uu/install/build.rs | 12 +++++++++++ src/uu/install/src/install.rs | 38 +++++++++++++++++------------------ 4 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 src/uu/install/build.rs diff --git a/Cargo.lock b/Cargo.lock index 2dda10162c9..90d7c0881f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3575,6 +3575,7 @@ dependencies = [ name = "uu_install" version = "0.6.0" dependencies = [ + "cfg_aliases", "clap", "file_diff", "filetime", diff --git a/src/uu/install/Cargo.toml b/src/uu/install/Cargo.toml index 41d1af3d1eb..7b41254ecf1 100644 --- a/src/uu/install/Cargo.toml +++ b/src/uu/install/Cargo.toml @@ -18,6 +18,9 @@ workspace = true [lib] path = "src/install.rs" +[build-dependencies] +cfg_aliases.workspace = true + [dependencies] clap = { workspace = true } filetime = { workspace = true } diff --git a/src/uu/install/build.rs b/src/uu/install/build.rs new file mode 100644 index 00000000000..843ded9e78c --- /dev/null +++ b/src/uu/install/build.rs @@ -0,0 +1,12 @@ +// 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. + +use cfg_aliases::cfg_aliases; + +pub fn main() { + 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 1277e822a42..1aa583bb7c0 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, @@ -121,7 +121,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), } @@ -492,7 +492,7 @@ fn directory(paths: &[OsString], b: &Behavior) -> UResult<()> { } // Set SELinux context for all created directories if needed - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[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); @@ -517,7 +517,7 @@ fn directory(paths: &[OsString], b: &Behavior) -> UResult<()> { show_if_err!(chown_optional_user_group(path, b)); // Set SELinux context for directory if needed - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if b.default_context { show_if_err!(set_selinux_default_context(path)); } else if b.context.is_some() { @@ -689,7 +689,7 @@ fn standard(mut paths: Vec, b: &Behavior) -> UResult<()> { } // Set SELinux context for all created directories if needed - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if should_set_selinux_context(b) { let context = get_context_for_selinux(b); set_selinux_context_for_directories_install(to_create, context); @@ -723,7 +723,7 @@ fn standard(mut paths: Vec, b: &Behavior) -> UResult<()> { } // Set SELinux context for all created directories if needed - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if should_set_selinux_context(b) { let context = get_context_for_selinux(b); set_selinux_context_for_directories_install(to_create, context); @@ -1096,7 +1096,7 @@ fn finalize_installed_file( preserve_timestamps(from, to)?; } - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if !b.unprivileged { if b.preserve_context { uucore::selinux::preserve_security_context(from, to) @@ -1155,7 +1155,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 @@ -1164,7 +1164,7 @@ fn get_context_for_selinux(b: &Behavior) -> Option<&String> { } } -#[cfg(all(feature = "selinux", target_os = "linux"))] +#[cfg(selinux)] fn should_set_selinux_context(b: &Behavior) -> bool { !b.unprivileged && (b.context.is_some() || b.default_context) } @@ -1259,7 +1259,7 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool { return true; } - #[cfg(all(feature = "selinux", target_os = "linux"))] + #[cfg(selinux)] if !b.unprivileged && b.preserve_context && contexts_differ(from, to) { return true; } @@ -1290,7 +1290,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, @@ -1324,7 +1324,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 @@ -1380,7 +1380,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 @@ -1418,7 +1418,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. @@ -1432,7 +1432,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 @@ -1472,7 +1472,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 @@ -1496,10 +1496,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)