Skip to content

Add response-file support for large Windows workspaces - #7027

Closed
psandana wants to merge 1 commit into
rust-lang:mainfrom
psandana:fix/windows-response-files
Closed

Add response-file support for large Windows workspaces#7027
psandana wants to merge 1 commit into
rust-lang:mainfrom
psandana:fix/windows-response-files

Conversation

@psandana

@psandana psandana commented Aug 11, 2026

Copy link
Copy Markdown

Fixes #6934.

This revision implements the explicit argument-file option suggested in #6934 (comment).

Problem

cargo-fmt passes every target path for an edition directly to one rustfmt process. Windows limits the complete CreateProcessW command line to 32,767 UTF-16 code units, so large workspaces fail with OS error 206 before rustfmt starts.

The issue reproducer contains 918 targets and exceeds that limit under a typical absolute checkout path.

Solution

Rustfmt gains an explicit argument-file option:

rustfmt --args-file <path>
rustfmt --args-file=<path>

Argument files are UTF-8 with one argument per line. They may be nested up to 16 levels, and -- terminates option and argument-file expansion globally. Ordinary filenames beginning with @ retain their existing meaning; no existing positional syntax is reinterpreted.

On Windows, cargo-fmt calculates the command-line length using Rust's Windows quoting rules. Only when an invocation would reach 32,767 UTF-16 code units does it write the complete rustfmt argument vector to a temporary file and invoke rustfmt --args-file <temporary-path>.

Keeping one rustfmt process per edition preserves existing session, ordering, JSON, and checkstyle behavior. User-provided --args-file options are expanded before cargo-fmt creates its transport file, so behavior remains identical below and above the Windows threshold.

Compatibility

  • @source.rs remains an ordinary source filename.
  • Non-Windows behavior is unchanged.
  • Windows commands below the OS limit continue to use direct arguments.
  • Argument-file paths and contents must be valid UTF-8, consistent with rustfmt's existing Unicode CLI.
  • Embedded newlines are rejected because the format is one argument per line.
  • The temporary file remains alive until rustfmt exits.

Tests

  • Separated and = syntax, CRLF, blank arguments, missing files, nesting, and global -- termination.
  • An ordinary source filename beginning with @.
  • Windows command-line quoting and exact length calculation.
  • A generated 500-target Windows workspace exceeding the limit.
  • User-provided argument files across the cargo-fmt threshold.
  • The original cargo fmt failure on Windows, too many command line args #6934 918-target reproducer.

Expand rustc-style @argument files in rustfmt and have cargo-fmt use a temporary response file when a Windows command would reach the CreateProcessW limit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Aug 11, 2026
@ytmimi ytmimi added the S-on-hold Status: PR/issue is on hold (due to bandwidth/prioritization/need discussions etc.). label Aug 11, 2026
@ytmimi

ytmimi commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Going to close this one for now. I personally don't think we'll move forward with the response-file support since it doesn't feel right to me that carg-fmt would write a to a file and pass that along to rustfmt.

@ytmimi ytmimi closed this Aug 11, 2026
@rustbot rustbot removed the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Aug 11, 2026
@psandana

Copy link
Copy Markdown
Author

Updated the implementation to use the explicit --args-file option suggested in #6934 (comment). This removes the breaking interpretation of filenames beginning with @; @source.rs remains an ordinary positional filename.

@psandana

Copy link
Copy Markdown
Author

Replacement PR #7028 implements the suggested explicit --args-file design and leaves @-prefixed filenames unchanged.

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

Labels

S-on-hold Status: PR/issue is on hold (due to bandwidth/prioritization/need discussions etc.).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo fmt failure on Windows, too many command line args

3 participants