bazelbuild / bazelbuild/bazel

C++ param files do not support file names with spaces

Open
#22,820 5 comments 0 reactions 0 assignees View on GitHub
not stale P3 team-Rules-CPP type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### 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 toolchain
`bazel.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 build

When we disable `compiler_param_file` feature
`bazel.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 build

Next, 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.lib

For 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 build

### Which operating system are you running Bazel on?

Windows

### What is the output of `bazel info release`?

release 7.0.2

### If `bazel info release` returns `development 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_

Contributor guide

Open the contributing guide

Research direction

The reproduction uses examples/cpp/BUILD and the compiler_param_file, archive_param_file, and linker_param_file features; start by running the listed Windows/MSVC commands with filenames containing spaces. Trace the generated parameter-file arguments for compile, archive, and link actions, then verify the affected builds succeed with those features enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.