Skip to content

fix(windows): survive cmd.exe's 8191 character command line limit#1209

Merged
crazywhalecc merged 2 commits into
crazywhalecc:fable-v3-windowsfrom
m-this:fix/windows-long-command-lines
Jul 10, 2026
Merged

fix(windows): survive cmd.exe's 8191 character command line limit#1209
crazywhalecc merged 2 commits into
crazywhalecc:fable-v3-windowsfrom
m-this:fix/windows-long-command-lines

Conversation

@m-this

@m-this m-this commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This fixes the imagick [frankenphp] failure from #1207 (The command line is too long, run). Moving ImageMagick to C:\im couldn't help: the length comes from the lib list and the objects, not the base path.

Two things going on:

Verified on windows-latest with the failing combo (imagick --build-cli --build-frankenphp --enable-zts) plus imagick cli/cgi/micro and pdo_pgsql,pgsql: https://github.com/m-this/static-php-cli/actions/runs/29072901492

- with big extension stacks (imagick) the link command lines exceed what
  cmd.exe allows and fail with 'The command line is too long'
- pass the collected LIBS_CLI/LIBS_CGI/LIBS_MICRO lib lists to link.exe
  through @response files, like php-src already does for its object lists
- compile the frankenphp -mthreads shim instead of generating a .bat:
  batch files run through cmd.exe and cap cgo link lines at 8191 chars,
  a real executable gets the full 32K and past that go writes a response
  file by itself; still probe-gated, still a stopgap for golang/go#80290
@m-this m-this mentioned this pull request Jul 10, 2026
4 tasks
@crazywhalecc

Copy link
Copy Markdown
Owner

I haven't tried it yet. BTW if this also solves the long path build problem for ImageMagick, then it's best not to put ImageMagick in C:\im, otherwise you won't be able to reset the build using bin/spc reset.

- C:\im was outside the project so bin/spc reset could not clean it
- with the command line limit fixed a short base path is no longer
  needed; keep SPC_IMAGEMAGICK_BUILD_DIR as an override
@henderkes

Copy link
Copy Markdown
Collaborator

Silly question, but can't we just use powershell?

@crazywhalecc

crazywhalecc commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Silly question, but can't we just use powershell?

That's a good question, but I suspect we shouldn't switch to PowerShell, and seems no more benefits.

Looks like PowerShell would only address the cgo wrapper. It would not solve the separate oversized nmake LIBS_* command.

Also PowerShell is too slow. It takes 2 seconds to start on my vm for the first time.

@crazywhalecc

Copy link
Copy Markdown
Owner

But with AI, I wouldn't mind giving it a try, though it doesn't seem to make much sense.

@henderkes

Copy link
Copy Markdown
Collaborator

Looks like PowerShell would only address the cgo wrapper. It would not solve the separate oversized nmake LIBS_* command.

PowerShell has no 8k character limit

@m-this

m-this commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@crazywhalecc good point, tested it: with the command line fix the short path isn't needed anymore, both imagick combos build fine with the tree under source\imagemagick-win. Pushed a commit that makes that the default (override still available via SPC_IMAGEMAGICK_BUILD_DIR), so bin/spc reset cleans it like everything else 🙂 https://github.com/m-this/static-php-cli/actions/runs/29081160787

@henderkes I looked into it, powershell would work, it has no 8k limit. The problem is that cgo calls CC a few hundred times per build, and every call would start a new powershell, which takes 150-500ms each time:

Measure-Command { powershell -NoProfile -Command "" } | Select TotalMilliseconds

That adds a minute or more to every build. The compiled shim starts instantly. It also passes the command line through untouched, while powershell likes to re-quote arguments on its way to clang.

@henderkes

Copy link
Copy Markdown
Collaborator

No... I mean literally never using cmd at all and instead using powershell.

@m-this

m-this commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Oh ok. What about just calling CreateProcess directly everywhere instead of cmd/pwsh? cmd would only stay for the .bat scripts (configure.bat, vcvars).

@crazywhalecc

Copy link
Copy Markdown
Owner

I wouldn't very mind switching to PowerShell entirely, but switching to PowerShell might present us with many new problems, whereas currently cmd only has the issue of length.

Given that all our current build scripts' escaping, environment variable passing, quotes, and dependent vcvars batch files are written around cmd, switching to PowerShell will still call cmd unless we completely refactor. Moreover, even if we bypass cmd/pwsh and directly use proc_open(bypass_shell: true), I'm not sure if it will still match our current terminal input/output and logging functionality.

@crazywhalecc crazywhalecc merged commit 6144f7a into crazywhalecc:fable-v3-windows Jul 10, 2026
1 check passed
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.

3 participants