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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pkg-url = "{ repo }/releases/download/v{ version }/{ name }-v{ version }.{ targe
[dependencies]
anyhow = "1.0.53"
cargo-config2 = "0.1.4"
cargo-options = "0.7.6"
cargo-options = "0.8.1"
clap = { version = "4.3.0", features = [
"derive",
"env",
Expand Down
92 changes: 92 additions & 0 deletions src/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use std::env;
use std::ops::{Deref, DerefMut};
use std::path::PathBuf;
use std::process::{self, Command};

use anyhow::{Context, Result};
use clap::Parser;

use crate::options::XWinOptions;

/// Execute all benchmarks of a local package
#[derive(Clone, Debug, Default, Parser)]
#[command(
display_order = 1,
after_help = "Run `cargo help bench` for more detailed information."
)]
pub struct Bench {
#[command(flatten)]
pub xwin: XWinOptions,

#[command(flatten)]
pub cargo: cargo_options::Bench,
}

impl Bench {
/// Create a new bench from manifest path
#[allow(clippy::field_reassign_with_default)]
pub fn new(manifest_path: Option<PathBuf>) -> Self {
let mut build = Self::default();
build.manifest_path = manifest_path;
build
}

/// Execute `cargo bench` command
pub fn execute(&self) -> Result<()> {
let mut run = self.build_command()?;

for target in &self.cargo.target {
if target.contains("msvc") {
if env::var_os("WINEDEBUG").is_none() {
run.env("WINEDEBUG", "-all");
}
let env_target = target.to_uppercase().replace('-', "_");
let runner_env = format!("CARGO_TARGET_{}_RUNNER", env_target);
if env::var_os(&runner_env).is_none() {
run.env(runner_env, "wine");
}
}
}

let mut child = run.spawn().context("Failed to run cargo run")?;
let status = child.wait().expect("Failed to wait on cargo run process");
if !status.success() {
process::exit(status.code().unwrap_or(1));
}
Ok(())
}

/// Generate cargo subcommand
pub fn build_command(&self) -> Result<Command> {
let mut build = self.cargo.command();
self.xwin.apply_command_env(
self.manifest_path.as_deref(),
&self.cargo.common,
&mut build,
)?;
Ok(build)
}
}

impl Deref for Bench {
type Target = cargo_options::Bench;

fn deref(&self) -> &Self::Target {
&self.cargo
}
}

impl DerefMut for Bench {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.cargo
}
}

impl From<cargo_options::Bench> for Bench {
fn from(cargo: cargo_options::Bench) -> Self {
Self {
cargo,
..Default::default()
}
}
}
5 changes: 4 additions & 1 deletion src/bin/cargo-xwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;
use std::ffi::OsString;
use std::process::Command;

use cargo_xwin::{Build, Cache, Check, Clippy, Doc, Env, Run, Rustc, Test};
use cargo_xwin::{Bench, Build, Cache, Check, Clippy, Doc, Env, Run, Rustc, Test};
use clap::{Parser, Subcommand};

#[derive(Debug, Parser)]
Expand All @@ -26,6 +26,8 @@ pub enum Cli {
#[derive(Debug, Subcommand)]
#[command(version, display_order = 1)]
pub enum Opt {
#[command(name = "bench")]
Bench(Bench),
#[command(name = "build", alias = "b")]
Build(Build),
Check(Check),
Expand All @@ -49,6 +51,7 @@ fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
match cli {
Cli::Opt(opt) | Cli::Cargo(opt) => match opt {
Opt::Bench(bench) => bench.execute()?,
Opt::Build(build) => build.execute()?,
Opt::Run(run) => run.execute()?,
Opt::Rustc(rustc) => rustc.execute()?,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod bench;
mod cache;
mod compiler;
mod env;
Expand All @@ -6,6 +7,7 @@ mod options;
mod run;
mod test;

pub use bench::Bench;
pub use cache::Cache;
pub use env::Env;
pub use macros::{build::Build, check::Check, clippy::Clippy, doc::Doc, rustc::Rustc};
Expand Down
Loading