Skip to content

Add args-file support for large Windows workspaces - #7028

Open
psandana wants to merge 3 commits into
rust-lang:mainfrom
psandana:fix/windows-args-file
Open

Add args-file support for large Windows workspaces#7028
psandana wants to merge 3 commits into
rust-lang:mainfrom
psandana:fix/windows-args-file

Conversation

@psandana

Copy link
Copy Markdown

Fixes #6934.

This implements the explicit argument-file option suggested in #6934 (comment) and replaces the closed #7027 approach.

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.

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.

Pato Sandaña and others added 2 commits August 11, 2026 13:19
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>
Replace @response-file parsing with --args-file so source files beginning with @ retain their existing meaning.

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
@riverar

riverar commented Aug 11, 2026

Copy link
Copy Markdown

May want to verify a UTF-8 args file starting with a byte-order mark (EF BB BF) is readable too.

Strip a leading UTF-8 byte-order mark before parsing the first argument line and cover both rustfmt and cargo-fmt paths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@psandana

Copy link
Copy Markdown
Author

Added UTF-8 BOM coverage in b7922a7. Argument-file readers now strip a leading EF BB BF, with unit coverage for both rustfmt and cargo-fmt plus BOM-enabled integration tests.

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

Labels

S-waiting-on-review Status: awaiting review from the assignee but also interested parties.

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