Skip to content
Open
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
52 changes: 23 additions & 29 deletions src/uu/stdbuf/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,6 @@ use std::fs;
use std::path::Path;
use std::process::Command;

#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "dragonfly"
))]
mod platform {
pub const DYLIB_EXT: &str = ".so";
}

#[cfg(target_vendor = "apple")]
mod platform {
pub const DYLIB_EXT: &str = ".dylib";
}

#[cfg(target_os = "cygwin")]
mod platform {
pub const DYLIB_EXT: &str = ".dll";
}

fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=src/libstdbuf/src/libstdbuf.rs");
Expand Down Expand Up @@ -58,14 +36,29 @@ fn main() {
let out_dir = env::var("OUT_DIR").expect("OUT_DIR not set");
let target = env::var("TARGET").unwrap_or_else(|_| "unknown".to_string());

let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").unwrap();

if target_family != "unix" {
return;
}
let dylib_ext = if target_vendor == "apple" {
".dylib"
} else if target_os == "cygwin" {
".dll"
} else {
".so"
};

// Check if we're building from the repository (where src/libstdbuf exists)
// or from crates.io (where it doesn't)
let libstdbuf_src = Path::new("src/libstdbuf");
if !libstdbuf_src.exists() {
// When building from crates.io, libstdbuf is already available as a dependency
// We can't build it here, so we'll need to handle this differently
// For now, we'll create a dummy library file to satisfy the include_bytes! macro
let lib_name = format!("libstdbuf{}", platform::DYLIB_EXT);
let lib_name = format!("libstdbuf{dylib_ext}");
let dest_path = Path::new(&out_dir).join(&lib_name);

// Create an empty file as a placeholder
Expand Down Expand Up @@ -108,11 +101,12 @@ fn main() {
assert!(status.success(), "Failed to build libstdbuf");

// Copy the built library to OUT_DIR for include_bytes! to find
#[cfg(target_os = "cygwin")]
let lib_name = format!("stdbuf{}", platform::DYLIB_EXT);
#[cfg(not(target_os = "cygwin"))]
let lib_name = format!("libstdbuf{}", platform::DYLIB_EXT);
let dest_path = Path::new(&out_dir).join(format!("libstdbuf{}", platform::DYLIB_EXT));
let lib_name = if target_os == "cygwin" {
format!("stdbuf{dylib_ext}")
} else {
format!("libstdbuf{dylib_ext}")
};
let dest_path = Path::new(&out_dir).join(format!("libstdbuf{dylib_ext}"));

// Check multiple possible locations for the built library
let possible_paths = if !target.is_empty() && target != "unknown" {
Expand Down Expand Up @@ -162,7 +156,7 @@ fn main() {
.and_then(|p| p.parent())
.and_then(|p| p.parent())
{
let lib_filename = format!("libstdbuf{}", platform::DYLIB_EXT);
let lib_filename = format!("libstdbuf{dylib_ext}");
let source = target_dir.join("deps").join(&lib_filename);
let dest = target_dir.join(&lib_filename);

Expand Down
1 change: 0 additions & 1 deletion src/uu/stdbuf/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ stdbuf-value-mode = MODE
stdbuf-error-line-buffering-stdin-meaningless = line buffering stdin is meaningless
stdbuf-error-invalid-mode = invalid mode {$error}
stdbuf-error-value-too-large = invalid mode '{$value}': Value too large for defined data type
stdbuf-error-command-not-supported = Command not supported for this operating system!
stdbuf-error-external-libstdbuf-not-found = External libstdbuf not found at configured path: {$path}
stdbuf-error-permission-denied = failed to execute process: Permission denied
stdbuf-error-no-such-file = failed to execute process: No such file or directory
Expand Down
1 change: 0 additions & 1 deletion src/uu/stdbuf/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ stdbuf-value-mode = MODE
stdbuf-error-line-buffering-stdin-meaningless = la mise en mémoire tampon par ligne de stdin n'a pas de sens
stdbuf-error-invalid-mode = mode invalide {$error}
stdbuf-error-value-too-large = mode invalide '{$value}' : Valeur trop grande pour le type de données défini
stdbuf-error-command-not-supported = Commande non prise en charge pour ce système d'exploitation !
stdbuf-error-external-libstdbuf-not-found = libstdbuf externe introuvable au chemin configuré : {$path}
stdbuf-error-permission-denied = échec de l'exécution du processus : Permission refusée
stdbuf-error-no-such-file = échec de l'exécution du processus : Aucun fichier ou répertoire de ce type
Expand Down
19 changes: 3 additions & 16 deletions src/uu/stdbuf/src/stdbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

// spell-checker:ignore (ToDO) tempdir dyld dylib optgrps libstdbuf

#[cfg(not(unix))]
compile_error!("stdbuf is not supported on the target");

use clap::{Arg, ArgAction, ArgMatches, Command};
use std::ffi::OsString;
#[cfg(unix)]
Expand Down Expand Up @@ -107,22 +110,6 @@ fn preload_strings() -> UResult<(&'static str, &'static str)> {
Ok(("DYLD_LIBRARY_PATH", "dylib"))
}

#[cfg(not(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "dragonfly",
target_vendor = "apple"
)))]
fn preload_strings() -> UResult<(&'static str, &'static str)> {
Err(USimpleError::new(
1,
translate!("stdbuf-error-command-not-supported"),
))
}

fn check_option(matches: &ArgMatches, name: &str) -> Result<BufferType, ProgramOptionsError> {
match matches.get_one::<String>(name) {
Some(value) => match value.as_str() {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/wc/src/wc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ fn is_stdin_small_file() -> bool {

matches!(
stat::fstat(io::stdin().as_fd()),
Ok(meta) if meta.st_mode & libc::S_IFMT == libc::S_IFREG && meta.st_size <= (10 << 20)
Ok(meta) if meta.st_mode as libc::mode_t & libc::S_IFMT == libc::S_IFREG && meta.st_size <= (10 << 20)
)
}

Expand Down
Loading