Skip to content

Using --features=external_include_paths on MSVC breaks compilation in Bazel 7 due to extra newlines in .params #22614

@stephen-ryan-ansys

Description

@stephen-ryan-ansys

Description of the bug:

The external_include_paths feature is breaking with MSVC in Bazel >7.0.0 during compilation. When using Bazel 6.5.0, using this feature does not result in a compilation error. It seems to affect every compile operation, all giving me the same type of error:

ERROR: C:/users/<name>/workspace/hello_world_test/BUILD:1:10: Compiling hello_world.cc failed: (Exit 2): cl.exe failed: error executing CppCompile command (from target //:hello-world) C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64\cl.exe @bazel-out/x64_windows-fastbuild/bin/_objs/hello-world/hello_world.obj.params
cl : Command line error D8004 : '/external:I' requires an argument

It seems that in the .params file, there is a newline after every use of /external:I. This causes MSVC to not recognize that there is an argument given to it. This .params files is not being used when compiling with Bazel 6.5.0, so this was not an issue previously.

Removing the newline after /external:I so that the argument is on the same line in the .params file and manually running the compilation command results in a successful compilation. Compiling without using the .params file by using --features=-compiler_param_file also results in a successful compilation.

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.

I am using a simple Hello World example, with the following files:

  • .bazelrc
common --enable_platform_specific_config

build:linux --cxxopt='-std=c++17'
build:linux --features=external_include_paths

build:windows --cxxopt='-std:c++17'
build:windows --features=external_include_paths
build:windows --cxxopt='/external:W0'
  • BUILD
cc_binary(
    name = "hello-world",
    srcs = ["hello_world.cc"],
)
  • hello_world.cc
#include <iostream>

int main()
{
    std::cout << "Hello World!" << std::endl;
    return 0;
}
  • WORKSPACE is empty
  • .bazelversion contains either 6.5.0 or 7.1.2

Then, on Windows with MSVC, simply running bazel build //:hello-world will reproduce the error when .bazelversion is set to > 7.0.0

Which operating system are you running Bazel on?

Windows 10 Enterprise 22H2

What is the output of bazel info release?

release 7.1.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

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

The above-mentioned error was:

ERROR: C:/users/<name>/workspace/hello_world_test/BUILD:1:10: Compiling hello_world.cc failed: (Exit 2): cl.exe failed: error executing CppCompile command (from target //:hello-world) C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64\cl.exe @bazel-out/x64_windows-fastbuild/bin/_objs/hello-world/hello_world.obj.params
cl : Command line error D8004 : '/external:I' requires an argument

With Bazel 7.1.2, The contents of the .params file are:

/nologo
/DCOMPILER_MSVC
/DNOMINMAX
/D_WIN32_WINNT=0x0601
/D_CRT_SECURE_NO_DEPRECATE
/D_CRT_SECURE_NO_WARNINGS
/bigobj
/Zm500
/EHsc
/wd4351
/wd4291
/wd4250
/wd4996
/I.
/Ibazel-out/x64_windows-fastbuild/bin
/Iexternal/bazel_tools
/Ibazel-out/x64_windows-fastbuild/bin/external/bazel_tools
/external:I
external/bazel_tools
/external:I
bazel-out/x64_windows-fastbuild/bin/external/bazel_tools
/showIncludes
/MD
/Od
/Z7
/wd4117
-D__DATE__=\"redacted\"
-D__TIMESTAMP__=\"redacted\"
-D__TIME__=\"redacted\"
-std:c++17
/external:W0
/Fobazel-out/x64_windows-fastbuild/bin/_objs/hello-world/hello_world.obj
/c
hello_world.cc

When building with bazel 6.5.0, the compile command is not using a .params file. The compile command is as follows:

C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64\cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /I. /Ibazel-out/x64_windows-fastbuild/bin /Iexternal/bazel_tools /Ibazel-out/x64_windows-fastbuild/bin/external/bazel_tools /external:I external/bazel_tools /external:I bazel-out/x64_windows-fastbuild/bin/external/bazel_tools /DBAZEL_CURRENT_REPOSITORY="" /showIncludes /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" -std:c++17 /external:W0 /Fobazel-out/x64_windows-fastbuild/bin/_objs/hello-world/hello_world.obj /c hello_world.cc

The options are the same, with the exception of the /DBAZEL_CURRENT_REPOSITORY="" option being present in Bazel 6.5.0, but not Bazel 7.1.2.

Returning to the output from 7.1.2, if I edit the params files to get rid of the newline between /external:I and its argument, e.g., /external:Iexternal/bazel_tools, or equivalently /external:I external/bazel_tools (with a space), and I try to manually run the same compile command, then it works.

Using Visual Studio 22, 17.9.7
MSVC v143
cl.exe version 19.39.33523 for x64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions