rust_builder: fix workspace binary discovery and add cargo test/check/clean/fmt support #3

Open
opened 2026-03-30 13:33:24 +00:00 by timur · 0 comments
Owner

Problem

1. Workspace binary discovery fails with all_bins()

rust_builder_from(workspace_root).release().all_bins().copy_to_hero_bin().build() fails with "Artifact not found" even though cargo build succeeds (exit code 0).

Root cause: parse_cargo_toml() in hero_lib/crates/code/src/rust_builder/cargo.rs (lines 206-212) only parses explicit [[bin]] sections from the workspace root Cargo.toml. In a workspace, the root has no [[bin]] entries — those are in member crate Cargo.toml files. So metadata.binaries is empty, and find_artifacts() returns empty.

Workaround: Use .bin("specific_name") per binary instead of .all_bins(). This bypasses metadata lookup and searches for the named file directly in target/release/.

Fix needed in parse_cargo_toml():

  1. For workspaces, also scan member crate Cargo.toml files for [[bin]] entries
  2. Detect implicit binaries (src/main.rs → package name, src/bin/*.rs → file name)

Files:

  • hero_lib/crates/code/src/rust_builder/cargo.rsparse_cargo_toml() function
  • hero_lib/crates/code/src/rust_builder/mod.rsfind_artifacts() at line 455-460

2. Missing cargo operations in rust_builder

Currently rust_builder only supports cargo build. For Rhai-based build automation (replacing Makefiles), we need native support for:

Operation Cargo Command Status
build() cargo build Exists
test() cargo test --workspace Missing
check() cargo check --workspace Missing
clean() cargo clean Missing
fmt() cargo fmt --all Missing
fmt_check() cargo fmt --all --check Missing
clippy() cargo clippy --workspace Missing
doc() cargo doc --no-deps Missing

These could be additional methods on the builder, e.g.:

rust_builder_from(path).test();      // cargo test
rust_builder_from(path).check();     // cargo check
rust_builder_from(path).clean();     // cargo clean
rust_builder_from(path).fmt();       // cargo fmt
rust_builder_from(path).clippy();    // cargo clippy

Or a more general approach:

rust_builder_from(path).command("test").arg("--workspace").execute();

Context

This is needed for the Rhai-as-Makefile paradigm (hero_proc issue #29). Currently test.rhai and clean.rhai fall back to execute("cargo test/clean") shell commands because native Rhai functions don't exist.

Acceptance Criteria

  • rust_builder_from(workspace).all_bins().build() correctly discovers binaries from workspace members
  • rust_builder_from(path).test() runs cargo test and returns result
  • rust_builder_from(path).check() runs cargo check
  • rust_builder_from(path).clean() runs cargo clean
  • rust_builder_from(path).fmt() and .fmt_check() run cargo fmt
  • rust_builder_from(path).clippy() runs cargo clippy
  • All new methods return structured results (success, exit_code, stdout, stderr)
## Problem ### 1. Workspace binary discovery fails with `all_bins()` `rust_builder_from(workspace_root).release().all_bins().copy_to_hero_bin().build()` fails with "Artifact not found" even though cargo build succeeds (exit code 0). **Root cause:** `parse_cargo_toml()` in `hero_lib/crates/code/src/rust_builder/cargo.rs` (lines 206-212) only parses explicit `[[bin]]` sections from the workspace root `Cargo.toml`. In a workspace, the root has no `[[bin]]` entries — those are in member crate Cargo.toml files. So `metadata.binaries` is empty, and `find_artifacts()` returns empty. **Workaround:** Use `.bin("specific_name")` per binary instead of `.all_bins()`. This bypasses metadata lookup and searches for the named file directly in `target/release/`. **Fix needed in `parse_cargo_toml()`:** 1. For workspaces, also scan member crate `Cargo.toml` files for `[[bin]]` entries 2. Detect implicit binaries (`src/main.rs` → package name, `src/bin/*.rs` → file name) **Files:** - `hero_lib/crates/code/src/rust_builder/cargo.rs` — `parse_cargo_toml()` function - `hero_lib/crates/code/src/rust_builder/mod.rs` — `find_artifacts()` at line 455-460 ### 2. Missing cargo operations in rust_builder Currently `rust_builder` only supports `cargo build`. For Rhai-based build automation (replacing Makefiles), we need native support for: | Operation | Cargo Command | Status | |-----------|--------------|--------| | `build()` | `cargo build` | ✅ Exists | | `test()` | `cargo test --workspace` | ❌ Missing | | `check()` | `cargo check --workspace` | ❌ Missing | | `clean()` | `cargo clean` | ❌ Missing | | `fmt()` | `cargo fmt --all` | ❌ Missing | | `fmt_check()` | `cargo fmt --all --check` | ❌ Missing | | `clippy()` | `cargo clippy --workspace` | ❌ Missing | | `doc()` | `cargo doc --no-deps` | ❌ Missing | These could be additional methods on the builder, e.g.: ```rhai rust_builder_from(path).test(); // cargo test rust_builder_from(path).check(); // cargo check rust_builder_from(path).clean(); // cargo clean rust_builder_from(path).fmt(); // cargo fmt rust_builder_from(path).clippy(); // cargo clippy ``` Or a more general approach: ```rhai rust_builder_from(path).command("test").arg("--workspace").execute(); ``` ## Context This is needed for the Rhai-as-Makefile paradigm (hero_proc issue #29). Currently `test.rhai` and `clean.rhai` fall back to `execute("cargo test/clean")` shell commands because native Rhai functions don't exist. ## Acceptance Criteria - [ ] `rust_builder_from(workspace).all_bins().build()` correctly discovers binaries from workspace members - [ ] `rust_builder_from(path).test()` runs cargo test and returns result - [ ] `rust_builder_from(path).check()` runs cargo check - [ ] `rust_builder_from(path).clean()` runs cargo clean - [ ] `rust_builder_from(path).fmt()` and `.fmt_check()` run cargo fmt - [ ] `rust_builder_from(path).clippy()` runs cargo clippy - [ ] All new methods return structured results (success, exit_code, stdout, stderr)
despiegk added this to the later milestone 2026-04-05 17:39:20 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_lib_rhai#3
No description provided.