Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion distutils/compilers/C/msvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

import contextlib
import os
from pathlib import Path
import subprocess
import tempfile
import unittest.mock as mock
import warnings
from collections.abc import Iterable
Expand Down Expand Up @@ -551,7 +553,17 @@ def link(
self.mkpath(output_dir)
try:
log.debug('Executing "%s" %s', self.linker, ' '.join(ld_args))
self.spawn([self.linker] + ld_args)
# The maximum length of the commandline is 32,767
# we must pass in the arguments through a file if it is longer
# https://learn.microsoft.com/en-us/cpp/build/reference/linking?view=msvc-170#linker-command-files
# https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa#parameters
if len(' '.join(ld_args)) > 30000:
Comment thread
astrelsky marked this conversation as resolved.
Outdated
with tempfile.TemporaryDirectory() as tmpdir:
Comment thread
astrelsky marked this conversation as resolved.
Outdated
cmdline = Path(tmpdir) / 'cmdline.txt'
cmdline.write_text('\n'.join(f'"{item}"' for item in ld_args))
Comment thread
astrelsky marked this conversation as resolved.
Outdated
self.spawn([self.linker, '@'+str(cmdline)])
Comment thread
astrelsky marked this conversation as resolved.
Outdated
else:
self.spawn([self.linker] + ld_args)
except DistutilsExecError as msg:
raise LinkError(msg)
else:
Expand Down