bazelbuild / bazelbuild/rules_cc
find_vc_path fails to detect VS2022 Preview installation
- Dominant language
- Starlark
- Stars
- 247
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I just started to learn Bazel recently but encountered an issue that Bazel fails detect local installation of VS2022 Preview.
I was able to workaround it by defining envvar ``BAZEL_VC=C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC``, but I believe this should be property detected by [`find_vc_path`](https://github.com/bazelbuild/rules_cc/blob/96d7d59f1fc928ac78b08e07f1172e5b24fe5dac/cc/private/toolchain/windows_cc_configure.bzl#L122).
By looking at code I found several places which might be contributing to this issue:
* `vswhere.exe` is called without `-prerelease` option, which is required to detect Preview installations.
https://github.com/bazelbuild/rules_cc/blob/96d7d59f1fc928ac78b08e07f1172e5b24fe5dac/cc/private/toolchain/windows_cc_configure.bzl#L177
* `program_files_dir` (`C:\\Program Files (x86)`) is used for searching installation paths. Since VS2022 is now 64-bit application, `C:\\Program Files` might be better option here.
https://github.com/bazelbuild/rules_cc/blob/96d7d59f1fc928ac78b08e07f1172e5b24fe5dac/cc/private/toolchain/windows_cc_configure.bzl#L248
Output
```
...
INFO: Analyzed target //source:main (83 packages loaded, 397 targets configured).
ERROR: ***/source/BUILD.bazel:1:10: Compiling source/main.cpp failed: (Exit 1): vc_installation_error_x64.bat failed: error executing CppCompile command (from target //source:main) external\bazel_tools~cc_configure_extension~local_config_cc\vc_installation_error_x64.bat @bazel-out/x64_windows-dbg/bin/source/_objs/main/main.obj.params
The target you are compiling requires Visual C++ build tools.
Bazel couldn't find a valid Visual C++ build tools installation on your machine.
Please check your installation following https://bazel.build/docs/windows#using
Target //source:main failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 4.531s, Critical Path: 0.10s
INFO: 6 processes: 6 internal.
ERROR: Build did NOT complete successfully
...
```
Environment
* Windows11
* VS2022 17.13.0 Preview 3.0 (no other versions are installed)
* Bazel 7.2.1
Contributor guide
Research direction
Start in cc/private/toolchain/windows_cc_configure.bzl, especially find_vc_path and the vswhere.exe invocation around the referenced lines. Check how prerelease installations and the program_files_dir path are discovered. Done means a VS2022 Preview installation is detected without setting BAZEL_VC and the local C++ toolchain can compile.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100