cargo cubuild to help debug Copper's compilation errors#365
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new Cargo subcommand cargo cubuild to expand #[copper_runtime] macros in-place and surface real compilation errors, updates the derive macro to output unhighlighted code for this tool, and registers the new crate in the workspace.
- Adds
cargo-cubuildCLI that backs up, injects, and checks expanded code. - Changes
cu29_deriveto emit raw formatted code undermacro_debug. - Updates workspace and dependency ordering for the derive crate.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| support/cargo_cubuild/src/main.rs | CLI implementation for backing up, expanding, and checking code |
| support/cargo_cubuild/README.md | Documentation and usage examples for cargo cubuild |
| support/cargo_cubuild/Cargo.toml | Defines the cargo-cubuild package |
| core/cu29_derive/src/lib.rs | Removes syntax highlighting and prints raw formatted expansion |
| core/cu29_derive/Cargo.toml | Reorders and pins derive-macro dependencies |
| Cargo.toml | Adds support/cargo_cubuild to workspace members |
Comments suppressed due to low confidence (2)
support/cargo_cubuild/src/main.rs:70
- Add unit tests for
extract_expansionto verify that start/end tags are correctly located and trimmed under various stderr scenarios.
fn extract_expansion(stderr: &str) -> Option<String> {
core/cu29_derive/src/lib.rs:1353
- [nitpick] This inline comment is helpful but could be converted to a
TODOor made part of README since commented-out guidance may be overlooked in code.
// or simply use cargo expand
| fn try_main(main_rs: &PathBuf, backup: &PathBuf) -> Result<(), i32> { | ||
| fs::copy(main_rs, backup).expect("Failed to backup main.rs"); |
There was a problem hiding this comment.
[nitpick] Consider using AsRef (e.g., main: impl AsRef<Path>) instead of &PathBuf for more flexible and idiomatic path handling.
| fn try_main(main_rs: &PathBuf, backup: &PathBuf) -> Result<(), i32> { | |
| fs::copy(main_rs, backup).expect("Failed to backup main.rs"); | |
| fn try_main(main_rs: impl AsRef<Path>, backup: impl AsRef<Path>) -> Result<(), i32> { | |
| fs::copy(main_rs.as_ref(), backup.as_ref()).expect("Failed to backup main.rs"); |
| in_macro_block = true; | ||
| continue; | ||
| } | ||
| if in_macro_block && line.contains("struct") { |
There was a problem hiding this comment.
[nitpick] Matching on the literal "struct" is brittle and may misplace the expansion; consider using a more precise marker or AST-based parsing to locate the injection point.
| if in_macro_block && line.contains("struct") { | |
| if in_macro_block && line.contains("// INSERT GENERATED CODE HERE") { |
| cu29-runtime = { workspace = true } | ||
| cu29-traits = { workspace = true } | ||
| syn = { workspace = true } | ||
| convert_case = "0.8.0" | ||
| itertools = "0.14.0" | ||
| quote = { workspace = true } | ||
| proc-macro2 = { workspace = true } |
There was a problem hiding this comment.
[nitpick] Dependencies aren't in alphabetical order; consider sorting them (e.g., proc-macro2 before quote) for consistency.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
I don't know why it took me a year to finally just implement this :)
before
after
ACTUAL error, on ACTUAL code. 🤯
Enjoy.