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.

doctor: check minimum versions and PHP's FFI extension (#32)

chessMan27cdefa5cc70
diff --git a/src/doctor.rs b/src/doctor.rs
index 5a4dcd7..fe73090 100644
--- a/src/doctor.rs
+++ b/src/doctor.rs
@@ -11,6 +11,45 @@ fn version(program: &str, args: &[&str]) -> Option<String> {
Some(text.lines().next().unwrap_or("").trim().to_string())
}
+/// The oldest version fast-anything works with, as each backend checks it when it starts.
+fn minimum(name: &str) -> &'static [u32] {
+ match name {
+ "cargo" => &[1, 85], // ports use edition 2024
+ "python" => &[3, 10],
+ "node" => &[22],
+ "ruby" => &[3, 3],
+ "java" => &[22],
+ "go" => &[1, 22],
+ "php" => &[8, 1],
+ "dotnet" => &[8],
+ _ => &[],
+ }
+}
+
+/// The first number in a version line: "ruby 3.1.7p261 (...)" gives [3, 1, 7], "go1.22.3" [1, 22, 3].
+fn parse_version(line: &str) -> Vec<u32> {
+ let Some(start) = line.find(|c: char| c.is_ascii_digit()) else { return vec![] };
+ let digits: String = line[start..].chars().take_while(|c| c.is_ascii_digit() || *c == '.').collect();
+ digits.split('.').map_while(|p| p.parse().ok()).collect()
+}
+
+/// Why a runtime that's installed can't be used yet, if it can't.
+fn problem(name: &str, found: &str) -> Option<String> {
+ let min = minimum(name);
+ let version = parse_version(found);
+ if !min.is_empty() && !version.is_empty() && version.as_slice() < min {
+ let min: Vec<String> = min.iter().map(u32::to_string).collect();
+ return Some(format!("too old, {} or newer is needed", min.join(".")));
+ }
+ if name == "php" {
+ let modules = Command::new("php").arg("-m").output().ok()?;
+ if !String::from_utf8_lossy(&modules.stdout).lines().any(|l| l.trim() == "FFI") {
+ return Some("the FFI extension is off: add extension=ffi to php.ini".into());
+ }
+ }
+ None
+}
+
struct Check {
name: &'static str,
found: Option<String>,
@@ -80,9 +119,13 @@ pub fn run() -> Result<()> {
hint: "npm i -g @openai/codex",
},
];
+ let usable = |c: &Check| c.found.as_deref().is_some_and(|v| problem(c.name, v).is_none());
for c in &checks {
match &c.found {
- Some(v) => ui::line(format!(" {} {:<8} {}", green("✓"), bold(c.name), dim(v))),
+ Some(v) => match problem(c.name, v) {
+ None => ui::line(format!(" {} {:<8} {}", green("✓"), bold(c.name), dim(v))),
+ Some(why) => ui::line(format!(" {} {:<8} {} {}", red("✗"), bold(c.name), dim(v), why)),
+ },
None if c.need == "required" => {
ui::line(format!(" {} {:<8} missing, {}: {}", red("✗"), bold(c.name), c.need, c.hint))
}
@@ -94,11 +137,27 @@ pub fn run() -> Result<()> {
)),
}
}
- ensure!(checks[0].found.is_some(), "Rust is needed to build ports");
- ensure!(
- checks[1..9].iter().any(|c| c.found.is_some()),
- "install Python, Node.js, Ruby, Java, Go, PHP, .NET or a C compiler"
- );
+ ensure!(usable(&checks[0]), "Rust 1.85 or newer is needed to build ports");
+ ensure!(checks[1..9].iter().any(usable), "install Python, Node.js, Ruby, Java, Go, PHP, .NET or a C compiler");
ui::ok("ready");
Ok(())
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn versions_and_minimums() {
+ assert_eq!(parse_version("ruby 3.1.7p261 (2025-03-26 revision 0a3704f218) [aarch64-linux-gnu]"), [3, 1, 7]);
+ assert_eq!(parse_version("go version go1.22.3 linux/amd64"), [1, 22, 3]);
+ assert_eq!(parse_version("v24.22.3"), [24, 22, 3]);
+ assert_eq!(parse_version("openjdk 25 2025-09-16"), [25]);
+ assert_eq!(parse_version("no digits"), Vec::<u32>::new());
+ assert!(problem("ruby", "ruby 3.1.7p261").is_some_and(|p| p.contains("3.3 or newer")));
+ assert_eq!(problem("ruby", "ruby 3.4.1"), None);
+ assert_eq!(problem("node", "v22.0.0"), None);
+ assert!(problem("python", "Python 3.9.18").is_some());
+ assert_eq!(problem("clang", "Debian clang version 14.0.6"), None, "no minimum");
+ }
+}