Skip to content

refactor: Switch to cargo-xtask for building the project#77

Open
ruben-etu wants to merge 2 commits intomainfrom
refactor/xtask
Open

refactor: Switch to cargo-xtask for building the project#77
ruben-etu wants to merge 2 commits intomainfrom
refactor/xtask

Conversation

@ruben-etu
Copy link
Copy Markdown
Collaborator

@ruben-etu ruben-etu commented Mar 17, 2026

Summary by CodeRabbit

  • New Features

    • Added an xtask command set for simplified build/run workflows (e.g., cargo xtask build, cargo xtask run-backend).
    • Added option to enable guest console logging.
  • Documentation

    • Quickstart and backend docs updated with xtask-based workflows, prerequisites, troubleshooting, and language examples.
  • Chores

    • Registered xtask in the workspace.
    • Ignored temporary build directory and added a sample environment configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

Adds an xtask Rust crate and a cargo alias to the workspace; registers xtask as a workspace member; provides CLI subcommands to build artifacts, run the backend/CLI, and reset initramfs; updates docs, sample backend env, and gitignore to integrate the new workflow. (43 words)

Changes

Cohort / File(s) Summary
Cargo & Alias
.cargo/config.toml, Cargo.toml
Adds a cargo alias xtask and registers xtask as a workspace member.
xtask crate
xtask/Cargo.toml, xtask/src/main.rs
New xtask binary crate implementing subcommands: build, run-backend, run-cli, reset-initramfs; handles env loading, subprocess orchestration, paths, and error messages.
Docs & Guides
QUICKSTART.md, backend/README.md
Replaces manual build/run steps with cargo xtask commands; updates prerequisites, troubleshooting, and examples for running sample code.
Env & Ignore
.gitignore, backend/.env.exemple
Adds tmp_build/ to .gitignore; extends backend sample env with AGENT_BINARY_PATH, INIT_SCRIPT_PATH, VM_KERNEL_PATH, VM_INITRAMFS_DIR, VM_LOG_GUEST_CONSOLE.

Sequence Diagrams

sequenceDiagram
    actor User
    participant Cargo as Cargo Alias
    participant xtask as xtask CLI
    participant Env as .env Config
    participant Backend as Backend Build
    participant Agent as Agent Build
    participant CLI as CLI Build

    User->>Cargo: cargo xtask build
    Cargo->>xtask: run --package xtask --
    xtask->>Env: load .env (if present)
    Env-->>xtask: config values
    xtask->>Backend: cargo build --package backend
    Backend-->>xtask: backend artifact
    xtask->>Agent: cargo build --package agent (musl)
    Agent-->>xtask: agent artifact
    xtask->>CLI: cargo build --package cli
    CLI-->>xtask: cli artifact
    xtask->>xtask: copy & chmod agent -> tmps
    xtask-->>User: Build complete
Loading
sequenceDiagram
    actor User
    participant Cargo as Cargo Alias
    participant xtask as xtask CLI
    participant Env as .env Config
    participant BackendProc as Backend Process

    User->>Cargo: cargo xtask run-backend
    Cargo->>xtask: run --package xtask --
    xtask->>Env: load .env (if present)
    Env-->>xtask: runtime env vars
    xtask->>BackendProc: sudo env [...] cargo run --package backend
    BackendProc->>BackendProc: initialize VMs & network
    BackendProc-->>User: logs / running state
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • Proxyfil

Poem

🐰 Hopping in with a cheerful task,
Cargo xtask now does the heavy ask,
Build, run, reset — all in one stride,
A tidy workflow, snug and wide,
I twitch my nose — devs rejoice! 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main change: introducing a cargo-xtask system to replace manual build/run commands across the project.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/xtask
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.

Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@xtask/src/main.rs`:
- Around line 179-182: The extension check.compare in the loop is wrong because
Path::extension() only returns the suffix after the last dot; update the test
that currently compares path.extension() to Some("cpio.gz") (used in the
reset_initramfs/remove loop) to instead inspect the file name string and check
if it ends_with(".cpio.gz") (e.g. via path.file_name().and_then(|n|
n.to_str()).map(|s| s.ends_with(".cpio.gz")) or by using
to_string_lossy().ends_with), then keep the same println!("Removing: {:?}",
path) and remove_file(&path)? behavior when the predicate matches. Ensure you
reference the same variable name path used in the snippet.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8fcd1fdc-ecbb-42b7-8ae7-666983244edb

📥 Commits

Reviewing files that changed from the base of the PR and between 98fd126 and 5e0151a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • .cargo/config.toml
  • .gitignore
  • Cargo.toml
  • QUICKSTART.md
  • backend/.env.exemple
  • backend/README.md
  • xtask/Cargo.toml
  • xtask/src/main.rs

Comment thread xtask/src/main.rs
Comment on lines +179 to +182
if path.extension().and_then(|e| e.to_str()) == Some("cpio.gz") {
println!("Removing: {:?}", path);
std::fs::remove_file(&path)?;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Bug: Extension check will never match .cpio.gz files.

Path::extension() returns only the part after the last dot. For a file like foo.cpio.gz, it returns "gz", not "cpio.gz". This means the current filter will never match any initramfs files, and reset_initramfs will silently do nothing.

🐛 Proposed fix using file_name() instead of extension()
-            if path.extension().and_then(|e| e.to_str()) == Some("cpio.gz") {
+            if path
+                .file_name()
+                .and_then(|n| n.to_str())
+                .is_some_and(|name| name.ends_with(".cpio.gz"))
+            {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if path.extension().and_then(|e| e.to_str()) == Some("cpio.gz") {
println!("Removing: {:?}", path);
std::fs::remove_file(&path)?;
}
if path
.file_name()
.and_then(|n| n.to_str())
.is_some_and(|name| name.ends_with(".cpio.gz"))
{
println!("Removing: {:?}", path);
std::fs::remove_file(&path)?;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@xtask/src/main.rs` around lines 179 - 182, The extension check.compare in the
loop is wrong because Path::extension() only returns the suffix after the last
dot; update the test that currently compares path.extension() to Some("cpio.gz")
(used in the reset_initramfs/remove loop) to instead inspect the file name
string and check if it ends_with(".cpio.gz") (e.g. via
path.file_name().and_then(|n| n.to_str()).map(|s| s.ends_with(".cpio.gz")) or by
using to_string_lossy().ends_with), then keep the same println!("Removing:
{:?}", path) and remove_file(&path)? behavior when the predicate matches. Ensure
you reference the same variable name path used in the snippet.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/README.md`:
- Around line 37-43: The README currently claims VM guest-console logging is
enabled by setting VM_LOG_GUEST_CONSOLE=true but the sample output only shows
the normal startup line; update the backend/README.md to either (a) add an
example guest-console log line (e.g. prefixed with backend::vm or
[guest-console]) immediately after the "INFO backend: Starting Backend
server..." line, or (b) add a single clarifying sentence stating that the extra
guest-console logs (tagged like backend::vm or [guest-console]) only appear once
a VM job starts; reference the VM_LOG_GUEST_CONSOLE env var and the
backend::vm/[guest-console] tag so readers know what to look for.

In `@QUICKSTART.md`:
- Around line 28-34: Update the "Start backend (terminal A)" section to use a
single canonical start location by changing the text to "From repository root"
(matching earlier steps) and ensure the command shown is "cargo xtask
run-backend"; also add a brief note that the backend requires root privileges
and that the `run-backend` xtask will invoke sudo to set up network interfaces
and VMs. Make the same location/privilege clarification for the similar
occurrence around line 36 so both instances consistently state "From repository
root" and mention sudo/automatic sudo usage by `cargo xtask run-backend`.
- Line 13: Update QUICKSTART.md to replace the placeholder line about needing a
VM kernel at `backend/vmlinux` with concrete, actionable steps: either provide
shell commands to build the vmlinux (e.g., clone kernel source, configure, and
build steps) or include a direct external link to official build/download
instructions, and add a brief note on where to place the resulting `vmlinux`
file (the `backend/` directory) and any expected filename/permissions; ensure
the text references `backend/vmlinux` so readers can find the target location
and remove the “instructions to come” placeholder.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dd9e7a65-bfd2-4ae3-a71f-e1e9a4a8bf7c

📥 Commits

Reviewing files that changed from the base of the PR and between 5e0151a and 9fa12f5.

📒 Files selected for processing (2)
  • QUICKSTART.md
  • backend/README.md

Comment thread backend/README.md
Comment on lines +37 to 43
To enable verbose VM guest console logging, add `VM_LOG_GUEST_CONSOLE=true` to the `backend/.env` file.

Expected log:

```text
INFO backend: Starting Backend server on 127.0.0.1:8080
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Clarify what output changes when VM_LOG_GUEST_CONSOLE=true.

On Line 37 you describe verbose guest-console logging, but the Line 42 sample shows only the standard backend startup log. Please either add a guest-console example line or state that extra logs appear only after a VM job starts.

Suggested doc patch
-To enable verbose VM guest console logging, add `VM_LOG_GUEST_CONSOLE=true` to the `backend/.env` file.
+To enable verbose VM guest console logging, add `VM_LOG_GUEST_CONSOLE=true` to the `backend/.env` file.
+Additional guest kernel/init logs appear when a VM is started (not at backend boot).
 
 Expected log:
 
 ```text
 INFO backend: Starting Backend server on 127.0.0.1:8080
+INFO backend::vm: [guest-console] ... 
</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @backend/README.md around lines 37 - 43, The README currently claims VM
guest-console logging is enabled by setting VM_LOG_GUEST_CONSOLE=true but the
sample output only shows the normal startup line; update the backend/README.md
to either (a) add an example guest-console log line (e.g. prefixed with
backend::vm or [guest-console]) immediately after the "INFO backend: Starting
Backend server..." line, or (b) add a single clarifying sentence stating that
the extra guest-console logs (tagged like backend::vm or [guest-console]) only
appear once a VM job starts; reference the VM_LOG_GUEST_CONSOLE env var and the
backend::vm/[guest-console] tag so readers know what to look for.


</details>

<!-- fingerprinting:phantom:triton:hawk -->

<!-- This is an auto-generated comment by CodeRabbit -->

Comment thread QUICKSTART.md
Comment thread QUICKSTART.md
Comment on lines +28 to 34
## 2) Start backend (terminal A)

Run backend as root from its project folder:

```bash
cd backend
sudo LANGUAGES_CONFIG_PATH=./config/languages.json \
AGENT_BINARY_PATH=./cloude-agentd \
INIT_SCRIPT_PATH=./init.sh \
VM_KERNEL_PATH=./vmlinux \
VM_INITRAMFS_DIR=./tmp \
VM_LOG_GUEST_CONSOLE=false \
../target/debug/backend
cargo xtask run-backend
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Make backend start location explicit and consistent.

There’s a mismatch between “From repository root” earlier and “from its project folder” on Line 30 while Line 33 uses cargo xtask run-backend (which is root-oriented in this doc). Please keep one canonical location to avoid confusion.

Suggested doc patch
-## 2) Start backend (terminal A)
-
-Run backend as root from its project folder:
+## 2) Start backend (terminal A)
+
+From repository root, run:
 
 ```bash
 cargo xtask run-backend

Note: The backend requires root privileges (sudo) to setup network interfaces and run VMs. The run-backend command will automatically use sudo to start the backend.

</details>


Also applies to: 36-36

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @QUICKSTART.md around lines 28 - 34, Update the "Start backend (terminal A)"
section to use a single canonical start location by changing the text to "From
repository root" (matching earlier steps) and ensure the command shown is "cargo
xtask run-backend"; also add a brief note that the backend requires root
privileges and that the run-backend xtask will invoke sudo to set up network
interfaces and VMs. Make the same location/privilege clarification for the
similar occurrence around line 36 so both instances consistently state "From
repository root" and mention sudo/automatic sudo usage by cargo xtask run-backend.


</details>

<!-- fingerprinting:phantom:triton:hawk -->

<!-- This is an auto-generated comment by CodeRabbit -->

Comment thread backend/README.md
Comment on lines 49 to 66
### Required in practice

- `VM_KERNEL_PATH` (default `./vmlinux`): Linux kernel used to boot each VM.
- `AGENT_BINARY_PATH` (default `./cloude-agentd`): binary injected into initramfs.
- `INIT_SCRIPT_PATH` (default `./init.sh`): init script injected as `/init`.

### Common runtime settings

- `BACKEND_SERVER_ADDR` (default `127.0.0.1:8080`)
- `BRIDGE_NAME` (default `cloudebr0`)
- `IP_RANGE` (default `10.39.1.0`)
- `IP_MASK` (default `24`, must be `<= 30`)
- `LANGUAGES_CONFIG_PATH` (default `./config/languages.json`)
- `VM_INITRAMFS_DIR` (default `./tmp`)
- `IP_ALLOCATIONS_PATH` (default `./tmp/ip_allocations.json`)
- `VM_LOG_GUEST_CONSOLE` (default `false`)
- `true/1/yes/on`: print guest kernel+init logs in backend terminal
- `false`: keep backend logs clean
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.

Maybe remove that if it is already documented in .env.example ?

Comment thread backend/README.md

## Environment variables

Configuration is read from `backend/.env` (create from `.env.exemple` if needed).
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.

Maybe move that line above cargo xtask run-backend, since it is a requirement (?)

Comment thread xtask/src/main.rs
Comment on lines +84 to +88
println!("Making agent binary executable...");
let status = Command::new("chmod").arg("+x").arg(&agent_dst).status()?;
if !status.success() {
return Err("Failed to make agent binary executable".into());
}
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.

No need, binaries produced by cargo are executable by default

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, this was a direct translation of the quickstart but is unneccessary

Comment thread xtask/src/main.rs
Comment on lines +110 to +113
.arg(format!(
"PATH=/usr/sbin:{}",
env::var("PATH").unwrap_or_default()
))
Copy link
Copy Markdown
Contributor

@ThomasRubini ThomasRubini Mar 17, 2026

Choose a reason for hiding this comment

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

PATH not needed, was removed from QUICKSTART, but backend/README.md duplicated the info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants