Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

The build check says where a project made one folder down is, and the Rust steps say Cargo.toml goes in app/ itself (#751)

Tanish Manku5eb1b2f4758d
diff --git a/crates/ai/src/rebuild/check.rs b/crates/ai/src/rebuild/check.rs
index 8f35d584..b5433c3a 100644
--- a/crates/ai/src/rebuild/check.rs
+++ b/crates/ai/src/rebuild/check.rs
@@ -26,7 +26,7 @@ pub(super) fn build_check(app: &Path, place: &str, stack: &str, editor: Option<&
let result: Result<(bool, String), String> = match (engine_for(stack, app), editor) {
(Some(game::Builder::Unity), Some(ed)) => {
if !app.join("Assets").is_dir() {
- return (false, format!("No Unity project found in {place} yet."));
+ return (false, missing(app, place, format!("No Unity project found in {place} yet.")));
}
let args = ["-batchmode", "-quit", "-nographics", "-projectPath", &app_s, "-executeMethod", "CraftBuild.Build", "-logFile", "-"].map(String::from);
run(ed, &args, 4 * 60).map(|(ok, out)| {
@@ -39,7 +39,7 @@ pub(super) fn build_check(app: &Path, place: &str, stack: &str, editor: Option<&
}
(Some(game::Builder::Unreal), Some(ed)) => {
let Some(uproject) = uproject(app) else {
- return (false, format!("No Unreal project (.uproject) found in {place} yet."));
+ return (false, missing(app, place, format!("No Unreal project (.uproject) found in {place} yet.")));
};
// The editor is <engine>/Engine/Binaries/<platform>/UnrealEditor; its packager is beside it.
let Some(root) = ed.ancestors().nth(4) else { return (false, "Couldn't find Unreal's build tools.".into()) };
@@ -72,7 +72,7 @@ pub(super) fn build_check(app: &Path, place: &str, stack: &str, editor: Option<&
}
(Some(game::Builder::Godot), Some(ed)) => {
if !app.join("project.godot").is_file() {
- return (false, format!("No Godot project (project.godot) found in {place} yet."));
+ return (false, missing(app, place, format!("No Godot project (project.godot) found in {place} yet.")));
}
let import = ["--headless", "--path", &app_s, "--import"].map(String::from);
let play = ["--headless", "--path", &app_s, "--quit-after", "120"].map(String::from);
@@ -85,7 +85,7 @@ pub(super) fn build_check(app: &Path, place: &str, stack: &str, editor: Option<&
_ if app.join("Cargo.toml").is_file() => run(Path::new("cargo"), &["build".into(), "--quiet".into()], 2 * 60),
_ if app.join("package.json").is_file() => run(Path::new(if cfg!(windows) { "npm.cmd" } else { "npm" }), &["run".into(), "build".into()], 2 * 60),
(None, _) if static_site(app) => return (true, "Nothing to build: a static site.".into()),
- _ => return (false, format!("No project to build found in {place} yet.")),
+ _ => return (false, missing(app, place, format!("No project to build found in {place} yet."))),
};
match result {
Ok((true, _)) => (true, "Build succeeded.".into()),
@@ -114,6 +114,30 @@ fn static_site(app: &Path) -> bool {
!engine && site_dir(app).is_some_and(page)
}
+/// A missing-project note, saying where a project is when one was made a folder down (`cargo new
+/// app` run inside app/ makes app/app/), so the builder can move it instead of starting again.
+/// Only app/, which is the build's own, is told the files belong in it: a person's own project
+/// folder, edited in place, may hold projects of its own below it.
+fn missing(app: &Path, place: &str, none: String) -> String {
+ let Some((dir, manifest)) = nested_project(app) else { return none };
+ if place.ends_with('/') {
+ format!("{none} There's a {manifest} one folder down, in {place}{dir}/, but the build runs in {place} itself: its files belong there.")
+ } else {
+ format!("{none} There's a {manifest} one folder down, in {dir}/ in {place}; the build runs in {place} itself.")
+ }
+}
+
+/// The first folder directly inside `app` (by name, of the first 256 entries) that holds a cargo or
+/// npm project, and that project's manifest.
+fn nested_project(app: &Path) -> Option<(String, &'static str)> {
+ let mut dirs: Vec<PathBuf> = std::fs::read_dir(app).ok()?.flatten().take(256).map(|e| e.path()).filter(|p| p.is_dir()).collect();
+ dirs.sort();
+ dirs.iter().find_map(|d| {
+ let manifest = ["Cargo.toml", "package.json"].into_iter().find(|m| d.join(m).is_file())?;
+ Some((d.file_name()?.to_string_lossy().into_owned(), manifest))
+ })
+}
+
/// The Unreal project file in `app`, if there is one.
fn uproject(app: &Path) -> Option<PathBuf> {
std::fs::read_dir(app).into_iter().flatten().flatten().map(|e| e.path()).find(|p| p.extension().is_some_and(|x| x == "uproject"))
@@ -164,6 +188,35 @@ mod tests {
assert_eq!(engine_for("Rust + macroquad", app), None);
}
+ #[test]
+ fn a_project_one_folder_down_is_named() {
+ let d = tempfile::tempdir().unwrap();
+ let app = d.path();
+ let stop = CancelToken::default();
+ let check = |place| build_check(app, place, "Rust + egui (eframe)", None, &stop);
+ assert_eq!(check("app/"), (false, "No project to build found in app/ yet.".into()), "nothing anywhere");
+ std::fs::create_dir(app.join("notes")).unwrap();
+ assert_eq!(check("app/").1, "No project to build found in app/ yet.", "a folder without a project");
+ // What `cargo new app` run inside app/ leaves.
+ std::fs::create_dir_all(app.join("app/src")).unwrap();
+ std::fs::write(app.join("app/Cargo.toml"), "[package]").unwrap();
+ let (ok, note) = check("app/");
+ assert!(!ok);
+ assert_eq!(
+ note,
+ "No project to build found in app/ yet. There's a Cargo.toml one folder down, in app/app/, but the build runs in app/ itself: its files belong there."
+ );
+ // A person's own folder may hold projects below it: where, but no move.
+ assert_eq!(
+ check("the project folder").1,
+ "No project to build found in the project folder yet. There's a Cargo.toml one folder down, in app/ in the project folder; the build runs in the project folder itself."
+ );
+ // The engines' own missing-project notes say it too.
+ let unity = Path::new("C:/Engines/Unity/Editor/Unity.exe");
+ let note = build_check(app, "app/", "Unity", Some(unity), &stop).1;
+ assert!(note.starts_with("No Unity project found in app/ yet. There's a Cargo.toml one folder down, in app/app/"), "{note}");
+ }
+
#[test]
fn a_static_site_has_nothing_to_build() {
let d = tempfile::tempdir().unwrap();
diff --git a/crates/ai/src/rebuild/stacks.toml b/crates/ai/src/rebuild/stacks.toml
index 23c60e65..79c8f835 100644
--- a/crates/ai/src/rebuild/stacks.toml
+++ b/crates/ai/src/rebuild/stacks.toml
@@ -45,16 +45,16 @@ steps = "Use plain HTML, CSS and a little JavaScript only if the page needs it:
[[stack]]
name = "Rust (console)"
uses = []
-steps = "Use Rust for a console program: create a cargo project in app/ (Cargo.toml, src/main.rs), read its arguments (std::env::args, or clap if it has many options), print to standard output and standard error the way the original does, exit with the original's exit codes, and draw no window. Run `cargo build` until it succeeds."
+steps = "Use Rust for a console program: create a cargo project in app/ itself (app/Cargo.toml and app/src/main.rs, not a folder inside app/), read its arguments (std::env::args, or clap if it has many options), print to standard output and standard error the way the original does, exit with the original's exit codes, and draw no window. Run `cargo build` until it succeeds."
[[stack]]
name = "Rust + egui (eframe)"
-steps = "Use Rust with eframe/egui for the window and UI. Create a cargo project in app/ and run `cargo build` until it succeeds."
+steps = "Use Rust with eframe/egui for the window and UI. Create a cargo project in app/ itself (app/Cargo.toml, not a folder inside app/) and run `cargo build` until it succeeds."
[[stack]]
name = "Rust + macroquad"
engine = "rust"
-steps = "Use Rust with macroquad (a small game library). Create a cargo project in app/ (Cargo.toml, src/main.rs), keep assets procedural (shapes, colours) unless the person provides some, and run `cargo build` until it succeeds."
+steps = "Use Rust with macroquad (a small game library). Create a cargo project in app/ itself (app/Cargo.toml and app/src/main.rs, not a folder inside app/), keep assets procedural (shapes, colours) unless the person provides some, and run `cargo build` until it succeeds."
[[stack]]
name = "Unity"
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index d41d5d41..3167283f 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -243,9 +243,15 @@ been run live.
reads a reply that is only the JSON. Half the model's calls came this way and the turn ended
with nothing done. Run a reply that ends in one fenced call to an offered tool, and say in
the transcript that it was read from text
-- [ ] The model ran `cargo new app` in `app/` (commands run there), so the project landed in
- `app/app/` and every check said "No project to build found in app/ yet". Say in that check
- where a project was found one folder down, and have the Rust brief say `cargo init`
+- [x] The model ran `cargo new app` in `app/` (commands run there), so the project landed in
+ `app/app/` and every check said "No project to build found in app/ yet". The check now says
+ where a cargo or npm project one folder down is, and the Rust steps say `app/Cargo.toml`,
+ not a folder inside `app/` (a brief can't say `cargo init`: not every builder's commands
+ start in `app/`). Live, with calls after a sentence run too, the model then made
+ `app/Cargo.toml` and the build compiled (#751)
+- [ ] The model reads file paths from the project folder and commands from `app/` as one base:
+ it ran `cargo init app` and `cd app && cargo build` after writing `app/Cargo.toml`. Say the
+ folder in `build_command_run`'s result (or its description) so the two can't be mixed up
- [ ] `usage.json` after a local build says about 4,200 input tokens and 6.5 s of work, while
Ollama logged about six requests of 4,000-5,000 tokens each: find what it leaves out
- [x] An assistant turn with no text sends an empty string, not `content: null`, which Ollama