From 27f7014f38a06e69f62b7983f3ba1a4fffedc802 Mon Sep 17 00:00:00 2001 From: joewnga <66113453+joewnga@users.noreply.github.com> Date: Mon, 24 Jun 2024 09:38:37 +0300 Subject: [PATCH 1/4] Add Windows support --- main/src/main.rs | 29 +++++++++++++++++++++++++---- replay/src/main.rs | 10 +++++++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/main/src/main.rs b/main/src/main.rs index 601afb0..e48851f 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")] @@ -102,8 +109,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()); @@ -126,6 +140,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..1f4aaf8 100644 --- a/replay/src/main.rs +++ b/replay/src/main.rs @@ -6,10 +6,15 @@ 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 +use std::{ env, path::{Path, PathBuf}}; use tokio::runtime::Builder; mod hostio; @@ -127,9 +132,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)?; From b7c58e86034c21dcb6c405d03efe7920808bfc19 Mon Sep 17 00:00:00 2001 From: joewnga <66113453+joewnga@users.noreply.github.com> Date: Mon, 24 Jun 2024 10:55:13 +0300 Subject: [PATCH 2/4] Added conditional import for Windows --- replay/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/replay/src/main.rs b/replay/src/main.rs index 1f4aaf8..3dcdb3c 100644 --- a/replay/src/main.rs +++ b/replay/src/main.rs @@ -14,6 +14,7 @@ use std::{ }; // Conditional import for Windows +#[cfg(windows)] use std::{ env, path::{Path, PathBuf}}; use tokio::runtime::Builder; From f6feb9fa16bb3c2c6aae2a0ee6e6c4473088a897 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 24 Jun 2024 20:17:50 +0300 Subject: [PATCH 3/4] Apply format --- main/src/main.rs | 8 ++++---- replay/src/main.rs | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/main/src/main.rs b/main/src/main.rs index e48851f..025ffa6 100644 --- a/main/src/main.rs +++ b/main/src/main.rs @@ -144,9 +144,9 @@ fn main() -> Result<()> { 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 + #[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 3dcdb3c..e74b465 100644 --- a/replay/src/main.rs +++ b/replay/src/main.rs @@ -15,7 +15,10 @@ use std::{ // Conditional import for Windows #[cfg(windows)] -use std::{ env, path::{Path, PathBuf}}; +use std::{ + env, + path::{Path, PathBuf}, +}; use tokio::runtime::Builder; mod hostio; From 54f33fca686d6313e7a663a10e826d194b28ea8e Mon Sep 17 00:00:00 2001 From: joewnga <66113453+joewnga@users.noreply.github.com> Date: Mon, 24 Jun 2024 21:07:20 +0300 Subject: [PATCH 4/4] Apply cargo format & debug output --- main/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/src/main.rs b/main/src/main.rs index 025ffa6..2eab882 100644 --- a/main/src/main.rs +++ b/main/src/main.rs @@ -148,5 +148,5 @@ fn main() -> Result<()> { let err = command.exec(); // Unix-specific execution #[cfg(windows)] let err = command.status(); // Windows-specific execution - bail!("failed to invoke {}: {:?}", name.red(), err); + bail!("failed to invoke {:?}: {:?}", name.red(), err); }