Skip to content

Commit

Permalink
Add Windows Support (#48)
Browse files Browse the repository at this point in the history
* Add Windows support

* Added conditional import for Windows

* Apply format

* Apply cargo format & debug output
  • Loading branch information
joewnga authored Jul 2, 2024
1 parent 02507c5 commit 695f074
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
29 changes: 25 additions & 4 deletions main/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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());
Expand All @@ -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);
}
14 changes: 13 additions & 1 deletion replay/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)?;
Expand Down

0 comments on commit 695f074

Please sign in to comment.