Skip to content

cargo oxide new scaffolds a project that fails cargo oxide fmt --check #1192

Closed

Description

@vyncint

Both cargo oxide new templates emit use statements in an order rustfmt does not produce, so a freshly scaffolded project fails its own format check on code the user never wrote.

Repro

$ cargo oxide new demo && cd demo && cargo oxide fmt --check
Diff in /tmp/demo/src/main.rs:1:
-use cuda_device::{kernel, launch_bounds, launch_contract, thread, DisjointSlice};
-use cuda_host::cuda_module;
 use cuda_core::{CudaContext, DeviceBuffer, LaunchConfig1D};
+use cuda_device::{DisjointSlice, kernel, launch_bounds, launch_contract, thread};
+use cuda_host::cuda_module;

❌ Some files need formatting. Run: cargo oxide fmt

--async is wrong the same way, in two places rather than one:

$ cargo oxide new demo --async && cd demo && cargo fmt --check
Diff in /tmp/demo/src/main.rs:1:
-use cuda_device::{kernel, thread, DisjointSlice};
-use cuda_host::cuda_module;
 use cuda_async::device_context::init_device_contexts;
 use cuda_async::device_operation::DeviceOperation;
 use cuda_core::LaunchConfig;
Diff in /tmp/demo/src/main.rs:6:
+use cuda_device::{DisjointSlice, kernel, thread};
+use cuda_host::cuda_module;

Two independent orderings are wrong

  1. Crate order. cuda_device / cuda_host precede cuda_core (and, in the async template, cuda_async). rustfmt sorts the group.
  2. Order inside the braces. DisjointSlice trails the lowercase items; under the scaffold's edition = "2024" it sorts first.

Why it goes unnoticed

Nothing in CI runs cargo oxide new, so no gate ever formats the scaffold's output. The templates are string constants in commands/scaffold.rs, so the repo's own fmt job cannot see them either — cargo fmt formats the source holding the string, never its contents.

It is also load-bearing that the existing test pins the defect:

assert!(files.main_rs.starts_with(
    "use cuda_device::{kernel, launch_bounds, launch_contract, thread, DisjointSlice};"
));

so the unformatted line is currently an asserted invariant.

Why it matters

CONTRIBUTING tells contributors to run cargo oxide fmt rather than a bare cargo fmt, so this is the first thing a new project is told to do, and it fails. Anyone with format-on-save gets a spurious diff the moment they open the generated file.

Scope note

cuda-oxide-book/getting-started/hello-gpu.md presents one of these listings as "the generated async vecadd template". #548 was filed and fixed precisely to keep that listing in step with scaffold_main_rs(true), and there is no automated guard holding them together, so the fix has to move both or it silently re-opens #548.

The book's other use cuda_device::{...} blocks are hand-written examples rather than scaffold output, so they are a separate matter (book code blocks are not formatted by anything today). Happy to file that separately if it is wanted.

Independent of #1187, which is about fmt building the backend rather than about what the scaffold emits.

I have a fix and will open a PR.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions