Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ pub fn main() {

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

let target_os = env::var_os("CARGO_CFG_TARGET_OS").unwrap();
let is_feat_selinux = env::var_os("CARGO_FEATURE_FEAT_SELINUX").is_some();

let mut crates = Vec::new();
for (key, val) in env::vars() {
if val == "1" && key.starts_with(ENV_FEATURE_PREFIX) {
let krate = key[ENV_FEATURE_PREFIX.len()..].to_lowercase();
// Allow this as we have a bunch of info in the comments
#[allow(clippy::match_same_arms)]
match krate.as_ref() {
#[cfg(not(any(target_os = "linux", target_os = "android")))]
"chcon" | "runcon" => {
"chcon" | "runcon"
if !(is_feat_selinux && (target_os == "linux" || target_os == "android")) =>
{
continue;
}
"default" | "macos" | "unix" | "windows" | "selinux" | "zip" | "clap_complete"
Expand Down
31 changes: 23 additions & 8 deletions src/uu/chcon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,30 @@ path = "src/chcon.rs"
test = false
doctest = false

# TODO: block fetching crates without feat_selinux
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
clap = { workspace = true }
uucore = { workspace = true, features = ["entries", "fs", "perms"] }
selinux = { workspace = true }
thiserror = { workspace = true }
libc = { workspace = true }
fts-sys = { workspace = true }
fluent = { workspace = true }
clap = { workspace = true, optional = true }
fluent = { workspace = true, optional = true }
fts-sys = { workspace = true, optional = true }
libc = { workspace = true, optional = true }
selinux = { workspace = true, optional = true }
thiserror = { workspace = true, optional = true }
uucore = { workspace = true, features = [
"entries",
"fs",
"perms",
], optional = true }

[features]
feat_selinux = ["selinux"]
selinux = [
"dep:clap",
"dep:fluent",
"dep:fts-sys",
"dep:libc",
"dep:selinux",
"dep:thiserror",
"dep:uucore",
]

[[bin]]
name = "chcon"
Expand Down
2 changes: 1 addition & 1 deletion src/uu/chcon/src/chcon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// spell-checker:ignore (vars) RFILE

#![cfg(any(target_os = "linux", target_os = "android"))]
#![cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
#![allow(clippy::upper_case_acronyms)]

use clap::builder::ValueParser;
Expand Down
2 changes: 0 additions & 2 deletions src/uu/chcon/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

#![cfg(any(target_os = "linux", target_os = "android"))]

use std::ffi::OsString;
use std::fmt::Write;
use std::io;
Expand Down
2 changes: 0 additions & 2 deletions src/uu/chcon/src/fts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

#![cfg(any(target_os = "linux", target_os = "android"))]

use std::ffi::{CStr, CString, OsStr};
use std::marker::PhantomData;
use std::os::raw::{c_int, c_long, c_short};
Expand Down
4 changes: 2 additions & 2 deletions src/uu/chcon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
//! entirely (via #![cfg(...)]), which can break tooling and cross builds that
//! expect this binary to exist even when it's a no-op off Linux.

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
uucore::bin!(uu_chcon);

#[cfg(not(any(target_os = "linux", target_os = "android")))]
#[cfg(not(all(feature = "selinux", any(target_os = "linux", target_os = "android"))))]
fn main() {
eprintln!("chcon: SELinux is not supported on this platform");
std::process::exit(1);
Expand Down
29 changes: 22 additions & 7 deletions src/uu/runcon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,29 @@ path = "src/runcon.rs"
test = false
doctest = false

# TODO: block fetching crates without feat_selinux
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
clap = { workspace = true }
uucore = { workspace = true, features = ["entries", "fs", "perms", "selinux"] }
selinux = { workspace = true }
thiserror = { workspace = true }
libc = { workspace = true }
fluent = { workspace = true }
clap = { workspace = true, optional = true }
fluent = { workspace = true, optional = true }
libc = { workspace = true, optional = true }
selinux = { workspace = true, optional = true }
thiserror = { workspace = true, optional = true }
uucore = { workspace = true, features = [
"entries",
"fs",
"perms",
"selinux",
], optional = true }

[features]
feat_selinux = ["selinux"]
selinux = [
"dep:clap",
"dep:fluent",
"dep:libc",
"dep:selinux",
"dep:thiserror",
"dep:uucore",
]

[[bin]]
name = "runcon"
Expand Down
2 changes: 0 additions & 2 deletions src/uu/runcon/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

#![cfg(any(target_os = "linux", target_os = "android"))]

use std::ffi::OsString;
use std::fmt::{Display, Formatter, Write};
use std::io;
Expand Down
4 changes: 2 additions & 2 deletions src/uu/runcon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
//! entirely (via #![cfg(...)]), which can break tooling and cross builds that
//! expect this binary to exist even when it's a no-op off Linux.

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
uucore::bin!(uu_runcon);

#[cfg(not(any(target_os = "linux", target_os = "android")))]
#[cfg(not(all(feature = "selinux", any(target_os = "linux", target_os = "android"))))]
fn main() {
eprintln!("runcon: SELinux is not supported on this platform");
std::process::exit(1);
Expand Down
2 changes: 1 addition & 1 deletion src/uu/runcon/src/runcon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// spell-checker:ignore (vars) RFILE execv execvp

#![cfg(any(target_os = "linux", target_os = "android"))]
#![cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]

use clap::builder::ValueParser;
use uucore::error::{UError, UResult};
Expand Down
Loading