Repository: mesonbuild/meson

Issue:
Meson generates potentially invalid response files for MSVC's Linker (link.exe)
**Describe the bug**

When linking an absurd amount of object files (in my case around 4,000) a response file gets made, which is expected.

This file has one single line, which ends up invoking error LNK1170 in the MSVC Linker because the entire line is longer than 128KB. 

By replacing one variable in the build.ninja file post-configure this will work.

**Workaround**


Letting it configure, and changing

```
rule cpp_LINKER_RSP
 command = "link" @$out.rsp
 rspfile = $out.rsp
 rspfile_content = $ARGS /MACHINE:x64 /OUT:$out $in $LINK_ARGS
 description = Linking target $out
```

to this:

```
rule cpp_LINKER_RSP
 command = "link" @$out.rsp
 rspfile = $out.rsp
 rspfile_content = $ARGS /MACHINE:x64 /OUT:$out $in_newline $LINK_ARGS
 description = Linking target $out
 ```

in the build.ninja file. The build will work correctly (and is also what the [ninja docs say](https://ninja-build.org/manual.html))

>  in_newline: the same as $in except that multiple inputs are separated by newlines rather than spaces. (For use with $rspfile_content; this works around a bug in the MSVC linker where it uses a fixed-size buffer for processing input.) 

TL;DR change $in to $in_newline for _RSP rules when rsp file syntax is RSPFileSyntax.MSVC.

I initially considered making a pull request for this but I am not experienced enough with both python and the meson code-base to feel comfortable enough making this change without it looking like found VHS footage.

**To Reproduce**

- Have a project with a lot of paths or a few very long paths resulting in a single line .rsp file over 128KB
- Build and link a shared library using MSVC as the target toolchain.

**Expected behavior**

Shared library gets made.

**system parameters**
* no cross compiling.
* Windows 11 
* Python 3.11.6
* Meson 1.2.1
* Ninja 1.11.1



Discussion:
Seems like a potentially easy fix if you have a moment :)

Resolving patch:
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -237,8 +237,10 @@ def _quoter(x, qf = quote_func):
         return ninja_quote(qf(str(x)))
 
     def write(self, outfile: T.TextIO) -> None:
+        rspfile_args = self.args
         if self.rspfile_quote_style is RSPFileSyntax.MSVC:
             rspfile_quote_func = cmd_quote
+            rspfile_args = [NinjaCommandArg('$in_newline', arg.quoting) if arg.s == '$in' else arg for arg in rspfile_args]
         else:
             rspfile_quote_func = gcc_rsp_quote
 
@@ -253,7 +255,7 @@ def rule_iter():
             if rsp == '_RSP':
                 outfile.write(' command = {} @$out.rsp\n'.format(' '.join([self._quoter(x) for x in self.command])))
                 outfile.write(' rspfile = $out.rsp\n')
-                outfile.write(' rspfile_content = {}\n'.format(' '.join([self._quoter(x, rspfile_quote_func) for x in self.args])))
+                outfile.write(' rspfile_content = {}\n'.format(' '.join([self._quoter(x, rspfile_quote_func) for x in rspfile_args])))
             else:
                 outfile.write(' command = {}\n'.format(' '.join([self._quoter(x) for x in self.command + self.args])))
             if self.deps:


Test patch: