Skip to content

Commit d47a410

Browse files
fmeumcopybara-github
authored andcommitted
Enable compiler_param_file in Windows MSVC toolchain
Fixes #5163 Closes #17135. PiperOrigin-RevId: 501212729 Change-Id: I6b4371a5521230c4c89f92321933b578bf5c3051
1 parent 4c57def commit d47a410

2 files changed

Lines changed: 73 additions & 35 deletions

File tree

‎src/test/py/bazel/bazel_windows_cpp_test.py‎

Lines changed: 72 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def testBuildCcBinaryFromDifferentPackage(self):
219219
' name = "main",',
220220
' srcs = ["main.cc"],',
221221
' deps = ["//:B"],',
222-
' linkstatic = 0,'
222+
' linkstatic = 0,',
223223
')',
224224
])
225225
bazel_bin = self.getBazelInfo('bazel-bin')
@@ -247,7 +247,7 @@ def testBuildCcBinaryDependsOnConflictDLLs(self):
247247
' name = "main",',
248248
' srcs = ["main.cc"],',
249249
' deps = ["//:B", "//lib:A"],', # Transitively depends on //:A
250-
' linkstatic = 0,'
250+
' linkstatic = 0,',
251251
')',
252252
])
253253
bazel_bin = self.getBazelInfo('bazel-bin')
@@ -278,14 +278,14 @@ def testBuildDifferentCcBinariesDependOnConflictDLLs(self):
278278
' name = "main",',
279279
' srcs = ["main.cc"],',
280280
' deps = ["//:B"],', # Transitively depends on //:A
281-
' linkstatic = 0,'
281+
' linkstatic = 0,',
282282
')',
283283
'',
284284
'cc_binary(',
285285
' name = "other_main",',
286286
' srcs = ["other_main.cc"],',
287287
' deps = ["//lib:A"],',
288-
' linkstatic = 0,'
288+
' linkstatic = 0,',
289289
')',
290290
])
291291
bazel_bin = self.getBazelInfo('bazel-bin')
@@ -386,24 +386,32 @@ def testDynamicLinkingMSVCRT(self):
386386
# By default, it should link to msvcrt dynamically.
387387
exit_code, _, stderr = self.RunBazel(
388388
['build', '//:A', '--output_groups=dynamic_library', '-s'])
389-
paramfile = os.path.join(bazel_output,
390-
'x64_windows-fastbuild/bin/A_0.dll-2.params')
389+
compile_params = os.path.join(
390+
bazel_output, 'x64_windows-fastbuild/bin/_objs/A/a.obj.params'
391+
)
392+
link_params = os.path.join(
393+
bazel_output, 'x64_windows-fastbuild/bin/A_0.dll-2.params'
394+
)
391395
self.AssertExitCode(exit_code, 0, stderr)
392-
self.assertIn('/MD', ''.join(stderr))
393-
self.AssertFileContentContains(paramfile, '/DEFAULTLIB:msvcrt.lib')
394-
self.assertNotIn('/MT', ''.join(stderr))
395-
self.AssertFileContentNotContains(paramfile, '/DEFAULTLIB:libcmt.lib')
396+
self.AssertFileContentContains(compile_params, '/MD')
397+
self.AssertFileContentContains(link_params, '/DEFAULTLIB:msvcrt.lib')
398+
self.AssertFileContentNotContains(compile_params, '/MT')
399+
self.AssertFileContentNotContains(link_params, '/DEFAULTLIB:libcmt.lib')
396400

397401
# Test build in debug mode.
398402
exit_code, _, stderr = self.RunBazel(
399403
['build', '-c', 'dbg', '//:A', '--output_groups=dynamic_library', '-s'])
400-
paramfile = os.path.join(bazel_output,
401-
'x64_windows-dbg/bin/A_0.dll-2.params')
404+
compile_params = os.path.join(
405+
bazel_output, 'x64_windows-dbg/bin/_objs/A/a.obj.params'
406+
)
407+
link_params = os.path.join(
408+
bazel_output, 'x64_windows-dbg/bin/A_0.dll-2.params'
409+
)
402410
self.AssertExitCode(exit_code, 0, stderr)
403-
self.assertIn('/MDd', ''.join(stderr))
404-
self.AssertFileContentContains(paramfile, '/DEFAULTLIB:msvcrtd.lib')
405-
self.assertNotIn('/MTd', ''.join(stderr))
406-
self.AssertFileContentNotContains(paramfile, '/DEFAULTLIB:libcmtd.lib')
411+
self.AssertFileContentContains(compile_params, '/MDd')
412+
self.AssertFileContentContains(link_params, '/DEFAULTLIB:msvcrtd.lib')
413+
self.AssertFileContentNotContains(compile_params, '/MTd')
414+
self.AssertFileContentNotContains(link_params, '/DEFAULTLIB:libcmtd.lib')
407415

408416
def testStaticLinkingMSVCRT(self):
409417
self.createProjectFiles()
@@ -414,26 +422,34 @@ def testStaticLinkingMSVCRT(self):
414422
'build', '//:A', '--output_groups=dynamic_library',
415423
'--features=static_link_msvcrt', '-s'
416424
])
417-
paramfile = os.path.join(bazel_output,
418-
'x64_windows-fastbuild/bin/A_0.dll-2.params')
425+
compile_params = os.path.join(
426+
bazel_output, 'x64_windows-fastbuild/bin/_objs/A/a.obj.params'
427+
)
428+
link_params = os.path.join(
429+
bazel_output, 'x64_windows-fastbuild/bin/A_0.dll-2.params'
430+
)
419431
self.AssertExitCode(exit_code, 0, stderr)
420-
self.assertNotIn('/MD', ''.join(stderr))
421-
self.AssertFileContentNotContains(paramfile, '/DEFAULTLIB:msvcrt.lib')
422-
self.assertIn('/MT', ''.join(stderr))
423-
self.AssertFileContentContains(paramfile, '/DEFAULTLIB:libcmt.lib')
432+
self.AssertFileContentNotContains(compile_params, '/MD')
433+
self.AssertFileContentNotContains(link_params, '/DEFAULTLIB:msvcrt.lib')
434+
self.AssertFileContentContains(compile_params, '/MT')
435+
self.AssertFileContentContains(link_params, '/DEFAULTLIB:libcmt.lib')
424436

425437
# Test build in debug mode.
426438
exit_code, _, stderr = self.RunBazel([
427439
'build', '-c', 'dbg', '//:A', '--output_groups=dynamic_library',
428440
'--features=static_link_msvcrt', '-s'
429441
])
430-
paramfile = os.path.join(bazel_output,
431-
'x64_windows-dbg/bin/A_0.dll-2.params')
442+
compile_params = os.path.join(
443+
bazel_output, 'x64_windows-dbg/bin/_objs/A/a.obj.params'
444+
)
445+
link_params = os.path.join(
446+
bazel_output, 'x64_windows-dbg/bin/A_0.dll-2.params'
447+
)
432448
self.AssertExitCode(exit_code, 0, stderr)
433-
self.assertNotIn('/MDd', ''.join(stderr))
434-
self.AssertFileContentNotContains(paramfile, '/DEFAULTLIB:msvcrtd.lib')
435-
self.assertIn('/MTd', ''.join(stderr))
436-
self.AssertFileContentContains(paramfile, '/DEFAULTLIB:libcmtd.lib')
449+
self.AssertFileContentNotContains(compile_params, '/MDd')
450+
self.AssertFileContentNotContains(link_params, '/DEFAULTLIB:msvcrtd.lib')
451+
self.AssertFileContentContains(compile_params, '/MTd')
452+
self.AssertFileContentContains(link_params, '/DEFAULTLIB:libcmtd.lib')
437453

438454
def testBuildSharedLibraryFromCcBinaryWithStaticLink(self):
439455
self.createProjectFiles()
@@ -444,8 +460,8 @@ def testBuildSharedLibraryFromCcBinaryWithStaticLink(self):
444460
' name = "main.dll",',
445461
' srcs = ["main.cc"],',
446462
' deps = ["//:B"],', # Transitively depends on //:A
447-
' linkstatic = 1,'
448-
' linkshared = 1,'
463+
' linkstatic = 1,',
464+
' linkshared = 1,',
449465
' features=["windows_export_all_symbols"]',
450466
')',
451467
])
@@ -479,8 +495,8 @@ def testBuildSharedLibraryFromCcBinaryWithDynamicLink(self):
479495
' name = "main.dll",',
480496
' srcs = ["main.cc"],',
481497
' deps = ["//:B"],', # Transitively depends on //:A
482-
' linkstatic = 0,'
483-
' linkshared = 1,'
498+
' linkstatic = 0,',
499+
' linkshared = 1,',
484500
' features=["windows_export_all_symbols"]',
485501
')',
486502
'',
@@ -528,8 +544,8 @@ def testGetDefFileOfSharedLibraryFromCcBinary(self):
528544
' name = "main.dll",',
529545
' srcs = ["main.cc"],',
530546
' deps = ["//:B"],', # Transitively depends on //:A
531-
' linkstatic = 1,'
532-
' linkshared = 1,'
547+
' linkstatic = 1,',
548+
' linkshared = 1,',
533549
')',
534550
])
535551
bazel_bin = self.getBazelInfo('bazel-bin')
@@ -681,7 +697,7 @@ def testCopyDLLAsSource(self):
681697
' shared_library = "A.dll",',
682698
' visibility = ["//:__subpackages__"],',
683699
')',
684-
''
700+
'',
685701
'filegroup(',
686702
' name = "bin_src",',
687703
' srcs = ["bin.cc"],',
@@ -1071,6 +1087,27 @@ def testBuildArm64CppBinaryWithMsvcCLAndCpuArm64Windows(self):
10711087
self.AssertExitCode(exit_code, 0, stderr)
10721088
self.assertIn('arm64\\cl.exe', ''.join(stderr))
10731089

1090+
def testLongCompileCommandLines(self):
1091+
self.CreateWorkspaceWithDefaultRepos('WORKSPACE')
1092+
self.ScratchFile(
1093+
'BUILD',
1094+
[
1095+
'cc_binary(',
1096+
' name = "long",',
1097+
' srcs = ["long.cc"],',
1098+
# Creates a command that is longer than 32767 characters, which is
1099+
# the maximum length of a command line on Windows.
1100+
' includes = [str(i) + 450 * "a" for i in range(120)],',
1101+
')',
1102+
],
1103+
)
1104+
self.ScratchFile('long.cc', ['int main() { return 0; }'])
1105+
1106+
exit_code, _, stderr = self.RunBazel(
1107+
['build', '--verbose_failures', '//:long']
1108+
)
1109+
self.AssertExitCode(exit_code, 0, stderr)
1110+
10741111

10751112
if __name__ == '__main__':
10761113
unittest.main()

‎tools/cpp/windows_cc_toolchain_config.bzl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ def _impl(ctx):
377377

378378
compiler_param_file_feature = feature(
379379
name = "compiler_param_file",
380+
enabled = True,
380381
)
381382

382383
copy_dynamic_libraries_to_binary_feature = feature(

0 commit comments

Comments
 (0)