Skip to content

Don't rewrite it in Rust. Rewrite the 5% that's slow: profile your app, port the hot functions with your coding agent, prove they behave the same. Python, JS/TS, Ruby, Java, Kotlin, Go, PHP, C/C++, C#, R.

cli: add clean subcommand to remove build cache or reset state

ashp152058f2a33f3ca39
diff --git a/README.md b/README.md
index 5ccadd8..43cd790 100644
--- a/README.md
+++ b/README.md
@@ -79,7 +79,7 @@ fast-anything ports the outermost loop it can, not the tiny function called insi
## Why not rewrite it all?
- **Compile time**: each port is a one-function crate. Seconds, not minutes.
-- **Cache**: every port shares one `.fast/target`. Delete it whenever you like.
+- **Cache**: every port shares one `.fast/target`. Delete it whenever you like (`fast-anything clean`).
- **Risk**: your code stays as it is. Rust is opt-in per function, checked against real behavior.
## Agents
diff --git a/src/main.rs b/src/main.rs
index b1eac2d..2b35af2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -105,6 +105,12 @@ enum Cmd {
},
/// Rebuild every port (after cloning, or a toolchain upgrade)
Build,
+ /// Remove compiler build cache (.fast/target) or all temporary state
+ Clean {
+ /// Remove all ports and reset .fast completely (disables any enabled ports first)
+ #[arg(long)]
+ all: bool,
+ },
/// Time your app with the originals vs the Rust ports
Bench {
#[arg(long, default_value_t = 5)]
@@ -198,6 +204,7 @@ fn run(cmd: Cmd, root: &Path) -> Result<()> {
Ok(())
}
Cmd::Build => pipeline::build_all(root),
+ Cmd::Clean { all } => pipeline::clean(root, all),
Cmd::Bench { runs } => {
show::bench(&pipeline::bench(root, runs)?);
show::next("fast-anything report");
@@ -229,6 +236,18 @@ mod tests {
assert!(Cli::try_parse_from(["fast-anything", "disable", "fuzzy.lev", "--all"]).is_err());
}
+ #[test]
+ fn clean_parses() {
+ assert!(matches!(
+ Cli::try_parse_from(["fast-anything", "clean"]).unwrap().cmd,
+ Cmd::Clean { all: false }
+ ));
+ assert!(matches!(
+ Cli::try_parse_from(["fast-anything", "clean", "--all"]).unwrap().cmd,
+ Cmd::Clean { all: true }
+ ));
+ }
+
#[test]
fn verify_all_parses() {
let cli = Cli::try_parse_from(["fast-anything", "verify", "--all"]).unwrap();
diff --git a/src/pipeline.rs b/src/pipeline.rs
index ceb53ff..65adf07 100644
--- a/src/pipeline.rs
+++ b/src/pipeline.rs
@@ -322,6 +322,41 @@ pub fn build_all(root: &Path) -> Result<()> {
Ok(())
}
+/// Remove the build cache (.fast/target) or reset the entire .fast directory.
+pub fn clean(root: &Path, all: bool) -> Result<()> {
+ let fast_dir = root.join(".fast");
+ if !fast_dir.exists() {
+ ui::ok("nothing to clean (.fast folder does not exist)");
+ return Ok(());
+ }
+
+ if all {
+ match disable_all(root) {
+ Ok(disabled) => {
+ for id in disabled {
+ ui::ok(format!("{} is back to the original code", ui::bold(&id)));
+ }
+ }
+ Err(e) => {
+ ui::warn(format!("could not disable all ports cleanly: {e:#}"));
+ }
+ }
+ if fast_dir.exists() {
+ fs::remove_dir_all(&fast_dir).with_context(|| format!("removing {}", fast_dir.display()))?;
+ }
+ ui::ok("removed .fast and reset all state");
+ } else {
+ let target_dir = fast_dir.join("target");
+ if target_dir.exists() {
+ fs::remove_dir_all(&target_dir).with_context(|| format!("removing {}", target_dir.display()))?;
+ ui::ok("removed .fast/target build cache");
+ } else {
+ ui::ok(".fast/target build cache is already clean");
+ }
+ }
+ Ok(())
+}
+
pub fn bench(root: &Path, runs: usize) -> Result<BenchResult> {
let mut ctx = Ctx::open(root)?;
for p in ctx.state.ports.values().filter(|p| p.enabled && ctx.stale(p)) {
@@ -696,4 +731,47 @@ mod tests {
assert!(!Ctx::open(&root).unwrap().state.ports[&id].enabled);
let _ = fs::remove_dir_all(root);
}
+
+ #[test]
+ fn clean_removes_target_cache() {
+ let root = std::env::temp_dir().join(format!("fa-clean-cache-{}", std::process::id()));
+ let _ = fs::remove_dir_all(&root);
+ let fast_dir = root.join(".fast");
+ let target_dir = fast_dir.join("target/release");
+ fs::create_dir_all(&target_dir).unwrap();
+ fs::write(target_dir.join("artifact"), "bytes").unwrap();
+ fs::write(fast_dir.join("state.json"), "{}").unwrap();
+
+ assert!(target_dir.exists());
+ clean(&root, false).unwrap();
+ assert!(!target_dir.exists());
+ assert!(fast_dir.exists());
+
+ // Calling clean again when target is already gone is a harmless no-op
+ clean(&root, false).unwrap();
+ assert!(!target_dir.exists());
+
+ let _ = fs::remove_dir_all(root);
+ }
+
+ #[test]
+ fn clean_all_disables_ports_and_removes_fast_dir() {
+ let (begin, end) = backend::markers("#", "demo");
+ let original = "def f():\n pass\n";
+ let text = format!("{original}\n{begin}\nf = rust\n{end}\n");
+ let (root, _id) = enabled_project("clean-all", &text);
+ let target_dir = root.join(".fast/target");
+ fs::create_dir_all(&target_dir).unwrap();
+ fs::write(target_dir.join("dummy.o"), "dummy").unwrap();
+
+ clean(&root, true).unwrap();
+ assert_eq!(fs::read_to_string(root.join("app.py")).unwrap(), original);
+ assert!(!root.join(".fast").exists());
+
+ // Calling clean on a non-existent .fast folder is a harmless no-op
+ clean(&root, true).unwrap();
+ assert!(!root.join(".fast").exists());
+
+ let _ = fs::remove_dir_all(root);
+ }
}