diff --git a/main/src/main.rs b/main/src/main.rs index 47e285d..7ffa008 100644 --- a/main/src/main.rs +++ b/main/src/main.rs @@ -4,8 +4,15 @@ use cargo_stylus_util::{color::Color, sys}; use clap::Parser; use eyre::{bail, Result}; + +// Conditional import for Unix-specific `CommandExt` +#[cfg(unix)] use std::{env, os::unix::process::CommandExt}; +// Conditional import for Windows +#[cfg(windows)] +use std::env; + #[derive(Parser, Debug)] #[command(name = "stylus")] #[command(bin_name = "cargo stylus")] @@ -124,8 +131,15 @@ fn main() -> Result<()> { // see if custom extension exists let custom = format!("cargo-stylus-{arg}"); if sys::command_exists(&custom) { - let err = sys::new_command(&custom).arg(arg).args(args).exec(); - bail!("failed to invoke {}: {err}", custom.red()); + let mut command = sys::new_command(&custom); + command.arg(arg).args(args); + + // Execute command conditionally based on the platform + #[cfg(unix)] + let err = command.exec(); // Unix-specific execution + #[cfg(windows)] + let err = command.status(); // Windows-specific execution + bail!("failed to invoke {:?}: {:?}", custom.red(), err); } eprintln!("Unknown subcommand {}.", arg.red()); @@ -148,6 +162,13 @@ fn main() -> Result<()> { } // should never return - let err = sys::new_command(name).arg(arg).args(args).exec(); - bail!("failed to invoke {}: {err}", name.red()); + let mut command = sys::new_command(name); + command.arg(arg).args(args); + + // Execute command conditionally based on the platform + #[cfg(unix)] + let err = command.exec(); // Unix-specific execution + #[cfg(windows)] + let err = command.status(); // Windows-specific execution + bail!("failed to invoke {:?}: {:?}", name.red(), err); } diff --git a/replay/src/main.rs b/replay/src/main.rs index 485d822..e74b465 100644 --- a/replay/src/main.rs +++ b/replay/src/main.rs @@ -6,10 +6,19 @@ use alloy_primitives::TxHash; use cargo_stylus_util::{color::Color, sys}; use clap::{Args, Parser}; use eyre::{bail, eyre, Context, Result}; +// Conditional import for Unix-specific `CommandExt` +#[cfg(unix)] use std::{ os::unix::process::CommandExt, path::{Path, PathBuf}, }; + +// Conditional import for Windows +#[cfg(windows)] +use std::{ + env, + path::{Path, PathBuf}, +}; use tokio::runtime::Builder; mod hostio; @@ -127,9 +136,12 @@ async fn replay(args: ReplayArgs) -> Result<()> { cmd.arg(arg); } cmd.arg("--child"); + #[cfg(unix)] let err = cmd.exec(); + #[cfg(windows)] + let err = cmd.status(); - bail!("failed to exec gdb {}", err); + bail!("failed to exec gdb {:?}", err); } let provider = sys::new_provider(&args.endpoint)?;