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: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v6
- name: Cargo sort
run: cargo install cargo-sort && cargo sort --check --check-format
run: cargo install cargo-sort && cargo sort --check --check-format --workspace
- name: Format
run: cargo fmt --check
- name: Clippy
Expand Down
48 changes: 7 additions & 41 deletions Cargo.lock

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

8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ cli = [
"tempfile",
"thread_local",
"time-humanize",
"tokio",
"twox-hash",
"wait-timeout",
]
coverage = []

Expand All @@ -64,12 +64,8 @@ target-triple = { version = "1.0.0", optional = true }
tempfile = { version = "3.27.0", optional = true }
thread_local = { version = "1.1.9", optional = true }
time-humanize = { version = "0.1.3", optional = true }
tokio = { version = "1.50.0", features = [
"process",
"rt",
"time",
], optional = true }
twox-hash = { version = "2.1.2", optional = true }
wait-timeout = { version = "0.2.1", optional = true }

[lints.clippy]
needless_doctest_main = "allow"
6 changes: 3 additions & 3 deletions examples/unstable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2024"
publish = false

[dependencies]
ziggy = { path = "../../", default-features = false }

[features]
fuzzing = []

[dependencies]
ziggy = { path = "../../", default-features = false }
6 changes: 3 additions & 3 deletions examples/url/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2024"
publish = false

[features]
fuzzing = []

[dependencies]
url = "2.5.0"
ziggy = { path = "../../", default-features = false }

[features]
fuzzing = []
11 changes: 0 additions & 11 deletions src/bin/cargo-ziggy/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ pub struct Common {
terminate: Arc<AtomicBool>,
sigs_done: Option<()>,
pub cargo_path: PathBuf,
runtime: OnceLock<tokio::runtime::Runtime>,
metadata: OnceLock<Option<cargo_metadata::Metadata>>,
}

Expand All @@ -431,7 +430,6 @@ impl Common {
cargo_path: std::env::var("CARGO")
.unwrap_or_else(|_| String::from("cargo"))
.into(),
runtime: OnceLock::new(),
metadata: OnceLock::new(),
}
}
Expand Down Expand Up @@ -471,15 +469,6 @@ impl Common {
cmd
}

fn async_runtime(&self) -> &tokio::runtime::Runtime {
self.runtime.get_or_init(|| {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Failed building tokio runtime")
})
}

/// Cached `cargo metadata`
fn metadata(&self) -> Option<&cargo_metadata::Metadata> {
self.metadata
Expand Down
62 changes: 29 additions & 33 deletions src/bin/cargo-ziggy/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
os::unix::process::ExitStatusExt,
path::{Path, PathBuf},
};
use wait_timeout::ChildExt;

impl Run {
// Run inputs
Expand Down Expand Up @@ -100,10 +101,9 @@ impl Run {
};

let runner = Runner::new(
common.async_runtime(),
runner_path.as_std_path(),
self.timeout
.map(|s| tokio::time::Duration::from_secs(u64::from(s))),
.map(|s| std::time::Duration::from_secs(u64::from(s))),
);

for file in input_files {
Expand Down Expand Up @@ -154,47 +154,43 @@ fn collect_dirs_recursively(
}

struct Runner<'a> {
rt: &'a tokio::runtime::Runtime,
path: &'a Path,
timeout: Option<tokio::time::Duration>,
timeout: Option<std::time::Duration>,
}

impl<'a> Runner<'a> {
fn new(
rt: &'a tokio::runtime::Runtime,
path: &'a Path,
timeout: Option<tokio::time::Duration>,
) -> Self {
Self { rt, path, timeout }
fn new(path: &'a Path, timeout: Option<std::time::Duration>) -> Self {
Self { path, timeout }
}

fn run(&self, seed: &Path) -> Status {
self.rt.block_on(async {
let mut child = match tokio::process::Command::new(self.path)
.arg(seed)
.env("RUST_BACKTRACE", "full")
.spawn()
.context("⚠️ couldn't spawn the runner process")
{
Ok(child) => child,
Err(e) => return e.into(),
};
let res = if let Some(duration) = self.timeout {
if let Ok(res) = tokio::time::timeout(duration, child.wait()).await {
res
} else {
let _ = child.start_kill();
let mut child = match std::process::Command::new(self.path)
.arg(seed)
.env("RUST_BACKTRACE", "full")
.spawn()
.context("⚠️ couldn't spawn the runner process")
{
Ok(child) => child,
Err(e) => return e.into(),
};
let res = if let Some(timeout) = self.timeout {
match child.wait_timeout(timeout) {
Ok(None) => {
// timed out
let _ = child.kill();
return Status::Timeout;
}
} else {
child.wait().await
}
.context("⚠️ couldn't wait for the runner process");
match res {
Ok(status) => Status::Ok(status),
Err(e) => e.into(),
Ok(Some(status)) => Ok(status),
Err(e) => Err(e),
}
})
} else {
child.wait()
}
.context("⚠️ couldn't wait for the runner process");
match res {
Ok(status) => Status::Ok(status),
Err(e) => e.into(),
}
}
}

Expand Down