Skip to content

cargo cubuild to help debug Copper's compilation errors#365

Merged
gbin merged 7 commits into
masterfrom
gbin/cargo-cubuild
Jun 25, 2025
Merged

cargo cubuild to help debug Copper's compilation errors#365
gbin merged 7 commits into
masterfrom
gbin/cargo-cubuild

Conversation

@gbin

@gbin gbin commented Jun 24, 2025

Copy link
Copy Markdown
Collaborator

I don't know why it took me a year to finally just implement this :)

before

$ cargo build
error[E0277]: the trait bound `&[u8]: Reader` is not satisfied
  --> examples/cu_caterpillar/src/main.rs:6:1
   |
6  | #[copper_runtime(config = "copperconfig.ron")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Reader` is not implemented for `&[u8]`
   |
note: there are multiple different versions of crate `bincode` in the dependency graph
  --> /home/gbin/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bincode-2.0.1/src/de/read.rs:17:1

after

$ cargo cubuild
error[E0277]: the trait bound `&[u8]: Reader` is not satisfied
    --> examples/cu_caterpillar/src/main.rs:2629:48
     |
2629 |             let mut decoder = DecoderImpl::new(slice, config, ());
     |                               ---------------- ^^^^^ the trait `Reader` is not implemented for `&[u8]`
     |                               |
     |                               required by a bound introduced by this call
     |
note: there are multiple different versions of crate `bincode` in the dependency graph
[...]

ACTUAL error, on ACTUAL code. 🤯

Enjoy.

@gbin gbin changed the title cargo build replacement to debug copper cargo cubuild to help debug Copper's compilation errors Jun 24, 2025
@gbin gbin requested a review from Copilot June 25, 2025 20:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-cubuild CLI that backs up, injects, and checks expanded code.
  • Changes cu29_derive to emit raw formatted code under macro_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_expansion to 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 TODO or made part of README since commented-out guidance may be overlooked in code.
        // or simply use cargo expand

Comment on lines +25 to +26
fn try_main(main_rs: &PathBuf, backup: &PathBuf) -> Result<(), i32> {
fs::copy(main_rs, backup).expect("Failed to backup main.rs");

Copilot AI Jun 25, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using AsRef (e.g., main: impl AsRef<Path>) instead of &PathBuf for more flexible and idiomatic path handling.

Suggested change
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");

Copilot uses AI. Check for mistakes.
in_macro_block = true;
continue;
}
if in_macro_block && line.contains("struct") {

Copilot AI Jun 25, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
if in_macro_block && line.contains("struct") {
if in_macro_block && line.contains("// INSERT GENERATED CODE HERE") {

Copilot uses AI. Check for mistakes.
Comment thread support/cargo_cubuild/src/main.rs Outdated
Comment on lines 18 to 23
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 }

Copilot AI Jun 25, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Dependencies aren't in alphabetical order; consider sorting them (e.g., proc-macro2 before quote) for consistency.

Copilot uses AI. Check for mistakes.
gbin and others added 2 commits June 25, 2025 15:03
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@gbin gbin merged commit 4b8211f into master Jun 25, 2025
9 checks passed
@gbin gbin deleted the gbin/cargo-cubuild branch June 25, 2025 20:12
@makeecat makeecat added the enhancement New feature or request label Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants