Open AlexanderGolovlev opened 5 months ago
It seems that the issue is in following code - https://github.com/bazelbuild/bazel/blob/dd48c1a766519b5ad95ffdb515d6097ef3739124/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java#L1324-L1330 As we can see, the GCC escaping method is applied for MSVC compiler. This adds backslash before space char in file name, which causes the error. Due to comment in code have found a related issue - #21029
ParameterFileType.WINDOWS was recently introudced, but it's not used for compilation. This using it there could fix the issue.
Description of the bug:
C++ param files (enabled by features
compiler_param_file
,archive_param_file
,linker_param_file
) do not support file names with spaces. Builds with param files fail with errors whereas builds without param files complete successfully.Which category does this issue belong to?
C++ Rules
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Rename files in "examples\cpp" folder: "hello-lib.cc" to "hello-lib .cc", "hello-world.cc" to "hello-world .cc" (note spaces before dots) Update file names in "examples\cpp\BUILD" file accordingly.
Run
build
on Windows platform with MSVC toolchainbazel.exe build //examples/cpp:hello-lib -s
This gives compiler error: ERROR: C:/projects/bazel/examples/cpp/BUILD:1:11: Compiling examples/cpp/hello-lib .cc failed: (Exit 2): cl.exe failed: error executing CppCompile command (from target //examples/cpp:hello-lib) C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX64\x64\cl.exe @bazel-out/x64_windows-fastbuild/bin/examples/cpp/_objs/hello-lib/hello-lib .obj.params cl : Command line warning D9027 : source file '.obj' ignored cl : Command line warning D9024 : unrecognized source file type 'examples/cpp/hello-lib\', object file assumed cl : Command line warning D9027 : source file 'examples/cpp/hello-lib\' ignored .cc c1xx: fatal error C1083: Cannot open source file: '.cc': No such file or directory Target //examples/cpp:hello-lib failed to buildWhen we disable
compiler_param_file
featurebazel.exe build //examples/cpp:hello-lib --features=-compiler_param_file -s
compiling action completes successfuly, but we receive a linker error: ERROR: C:/projects/bazel/examples/cpp/BUILD:1:11: Linking examples/cpp/hello-lib.lib failed: (Exit 1181): lib.exe failed: error executing CppArchive command (from target //examples/cpp:hello-lib) C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX64\x64\lib.exe @bazel-out/x64_windows-fastbuild/bin/examples/cpp/hello-lib.lib-2.params LINK : fatal error LNK1181: cannot open input file 'bazel-out\x64_windows-fastbuild\bin\examples\cpp_objs\hello-lib\hello-lib' Target //examples/cpp:hello-lib failed to buildNext, disable
archive_param_file
feature:bazel.exe build //examples/cpp:hello-lib --features=-compiler_param_file --features=-archive_param_file -s
The build completes successfuly: Target //examples/cpp:hello-lib up-to-date: bazel-bin/examples/cpp/hello-lib.libFor CppLink error run
bazel.exe build //examples/cpp:hello-world --features=-compiler_param_file -s
This gives error: ERROR: C:/projects/bazel/examples/cpp/BUILD:7:10: Linking examples/cpp/hello-world.exe failed: (Exit 1181): link.exe failed: error executing CppLink command (from target //examples/cpp:hello-world) C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX64\x64\link.exe @bazel-out/x64_windows-fastbuild/bin/examples/cpp/hello-world.exe-2.params LINK : fatal error LNK1181: cannot open input file '.obj' Target //examples/cpp:hello-world failed to buildWhich operating system are you running Bazel on?
Windows
What is the output of
bazel info release
?release 7.0.2
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse HEAD
?No response
If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response