| 1 | // Default allocator: mimalloc. `--no-default-features --features rusty-alloc` |
| 2 | // selects the Rust allocator without building the C allocator (#5872). |
| 3 | // With neither feature the standard library system allocator is used. |
| 4 | #[cfg(all(feature = "mimalloc-allocator", not(feature = "rusty-alloc")))] |
| 5 | #[global_allocator] |
| 6 | static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; |
| 7 | |
| 8 | #[cfg(feature = "rusty-alloc")] |
| 9 | #[global_allocator] |
| 10 | static GLOBAL: rusty_alloc_api::RustyAlloc = rusty_alloc_api::RustyAlloc; |
| 11 | |
| 12 | fn main() -> std::process::ExitCode { |
| 13 | // Reset SIGPIPE to SIG_DFL so piping codewhale output into a command that |
| 14 | // exits early (e.g. `codewhale doctor | head`) terminates the process |
| 15 | // cleanly with exit code 141 instead of panicking on the broken-pipe |
| 16 | // write. Many execution environments (systemd, Docker, some shells) |
| 17 | // inherit SIGPIPE set to SIG_IGN, which makes write(2) return EPIPE; |
| 18 | // Rust's `println!` then treats that io::Error as fatal and panics. |
| 19 | // See issue #4030. |
| 20 | // SAFETY: process entry; no threads or handlers yet. |
| 21 | #[cfg(unix)] |
| 22 | unsafe { |
| 23 | libc::signal(libc::SIGPIPE, libc::SIG_DFL); |
| 24 | } |
| 25 | |
| 26 | // Single-binary argv0 dispatch: `codew` is now an alias for `codewhale` |
| 27 | // without a second compiled artifact. Checking the binary basename keeps |
| 28 | // the install surface at one file while preserving the six-keystroke save. |
| 29 | let _ = std::env::args().next().and_then(|argv0| { |
| 30 | let base = std::path::Path::new(&argv0) |
| 31 | .file_name() |
| 32 | .and_then(|s| s.to_str()) |
| 33 | .unwrap_or(""); |
| 34 | let trimmed = base |
| 35 | .strip_suffix(std::env::consts::EXE_SUFFIX) |
| 36 | .unwrap_or(base); |
| 37 | if trimmed == "codew" { |
| 38 | // No-op: the single `codewhale` binary handles both names. |
| 39 | } |
| 40 | None::<()> |
| 41 | }); |
| 42 | |
| 43 | codewhale_cli::run_cli() |
| 44 | } |
| 45 |