diff --git a/.cargo/config.toml b/.cargo/config.toml index d3364a54b2a..b2b00df3cc2 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -10,7 +10,3 @@ linker = "aarch64-linux-gnu-gcc" rustflags = ["-C", "target-feature=+crt-static"] [target.'cfg(target_env = "msvc")'] rustflags = ["-C", "target-feature=+crt-static"] - -[env] -# See feat_external_libstdbuf in src/uu/stdbuf/Cargo.toml -LIBSTDBUF_DIR = "/usr/local/libexec/coreutils" diff --git a/src/uu/stdbuf/build.rs b/src/uu/stdbuf/build.rs index 81a1e052b6d..b7687f77d95 100644 --- a/src/uu/stdbuf/build.rs +++ b/src/uu/stdbuf/build.rs @@ -18,26 +18,6 @@ fn main() { println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=src/libstdbuf/src/libstdbuf.rs"); - // Check for external stdbuf feature requirements - #[cfg(feature = "feat_external_libstdbuf")] - { - if env::var("LIBSTDBUF_DIR").is_err() { - eprintln!( - "\n\x1b[31mError:\x1b[0m The 'feat_external_libstdbuf' feature requires the LIBSTDBUF_DIR environment variable to be set." - ); - eprintln!( - "\x1b[33mUsage:\x1b[0m LIBSTDBUF_DIR=/path/to/lib/directory cargo build --features feat_external_libstdbuf" - ); - eprintln!( - "\x1b[33mExample:\x1b[0m LIBSTDBUF_DIR=/usr/lib cargo build --features feat_external_libstdbuf" - ); - eprintln!( - "\nThis directory should point to where libstdbuf.so / libstdbuf.dylib will be installed on the target system." - ); - std::process::exit(1); - } - } - let out_dir = env::var("OUT_DIR").expect("OUT_DIR not set"); let target = env::var("TARGET").unwrap_or_else(|_| "unknown".to_string()); diff --git a/src/uu/stdbuf/src/stdbuf.rs b/src/uu/stdbuf/src/stdbuf.rs index 3ff36885b9c..3fad3ab4cd2 100644 --- a/src/uu/stdbuf/src/stdbuf.rs +++ b/src/uu/stdbuf/src/stdbuf.rs @@ -148,8 +148,11 @@ fn get_preload_env(tmp_dir: &TempDir) -> UResult<(String, PathBuf)> { #[cfg(feature = "feat_external_libstdbuf")] fn get_preload_env(_tmp_dir: &TempDir) -> UResult<(String, PathBuf)> { // Use the directory provided at compile time via LIBSTDBUF_DIR environment variable - // This will fail to compile if LIBSTDBUF_DIR is not set, which is the desired behavior - const LIBSTDBUF_DIR: &str = env!("LIBSTDBUF_DIR"); + // cannot use unwrap_or + const LIBSTDBUF_DIR: &str = match option_env!("LIBSTDBUF_DIR") { + Some(v) => v, + None => "/usr/local/libexec/coreutils", + }; let (preload, extension) = preload_strings();