Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub enum Commands {
#[arg(value_enum)]
shell: Shell,
},
/// Show platform information
Platform {},
/// Update gitclaw itself
SelfUpdate {
/// Only check for updates, don't install
Expand Down
20 changes: 20 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ async fn main() {

let cli = Cli::parse();

// Check for platform mismatch (e.g., Darwin binary on Linux)
if let Some(warning) = platform::check_target_mismatch() {
eprintln!("{}", warning);
}

// Load configuration and merge with CLI args
let config = match Config::load() {
Ok(cfg) => cfg,
Expand Down Expand Up @@ -85,6 +90,21 @@ async fn run(cli: Cli, config: Config) -> anyhow::Result<()> {
let name = cmd.get_name().to_string();
generate(shell, &mut cmd, name, &mut std::io::stdout());
}
Commands::Platform {} => {
let (os, arch) = gitclaw::platform::current_platform()?;
println!("Detected platform: {} {}", os, arch);
#[cfg(target_os = "macos")]
println!("Compiled for: macOS");
#[cfg(target_os = "linux")]
println!("Compiled for: Linux");
#[cfg(target_os = "windows")]
println!("Compiled for: Windows");
println!("OS aliases: {:?}", os.aliases());
println!("Arch aliases: {:?}", arch.aliases());
if let Some(warning) = gitclaw::platform::check_target_mismatch() {
println!("\n{}", warning);
}
}
Commands::SelfUpdate { check } => {
if check {
self_update::check_for_update(&config).await?
Expand Down
43 changes: 43 additions & 0 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,49 @@ pub fn current_platform() -> Result<(OS, Arch), PlatformError> {
Ok((detect_os()?, detect_arch()?))
}

/// Check if the binary's compile target matches runtime platform
/// This catches cross-compiled binaries run under emulation
pub fn check_target_mismatch() -> Option<String> {
// Use conditional compilation to detect the compiled target
let compiled_for_macos = cfg!(target_os = "macos");
let compiled_for_linux = cfg!(target_os = "linux");
let compiled_for_windows = cfg!(target_os = "windows");

let runtime_os = std::env::consts::OS;

// If compiled for macOS but running on Linux (e.g., under Rosetta or emulation)
if compiled_for_macos && runtime_os == "linux" {
return Some(
"Warning: This gitclaw binary was compiled for macOS but is running on Linux.\n\
This will cause incorrect package selection.\n\
Please install the Linux version or build from source: cargo install --path ."
.to_string(),
);
}

// If compiled for Linux but running on macOS
if compiled_for_linux && runtime_os == "macos" {
return Some(
"Warning: This gitclaw binary was compiled for Linux but is running on macOS.\n\
This will cause incorrect package selection.\n\
Please install the macOS version or build from source: cargo install --path ."
.to_string(),
);
}

// If compiled for Windows but running on Unix
if compiled_for_windows && (runtime_os == "linux" || runtime_os == "macos") {
return Some(
"Warning: This gitclaw binary was compiled for Windows but is running on a Unix system.\n\
This will cause incorrect package selection.\n\
Please install the correct version for your OS."
.to_string(),
);
}

None
}

pub fn score_asset(name: &str, os: OS, arch: Arch) -> i32 {
let lower = name.to_lowercase();
let mut score = 0;
Expand Down
Loading