Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake could not find any instance of Visual Studio #793

Closed
homuler opened this issue Sep 29, 2021 · 5 comments
Closed

CMake could not find any instance of Visual Studio #793

homuler opened this issue Sep 29, 2021 · 5 comments

Comments

@homuler
Copy link

homuler commented Sep 29, 2021

I'm trying to use Visual Studio 16 2019.
I understand this version is not supported yet, but judging from CI errors (bazelbuild/continuous-integration#1204), I thought the version is not relevant, so I create this issue.

When I try to build libhello_example with Visual Studio 16 2019,

diff --git a/examples/cmake_hello_world_lib/static/BUILD.bazel b/examples/cmake_hello_world_lib/static/BUILD.bazel
index b32e9ad..44a6c33 100644
--- a/examples/cmake_hello_world_lib/static/BUILD.bazel
+++ b/examples/cmake_hello_world_lib/static/BUILD.bazel
@@ -15,7 +15,7 @@ cmake(
     name = "libhello",
     generate_args = select({
         "//:windows": [
-            "-G \"Visual Studio 15 2017\"",
+            "-G \"Visual Studio 16 2019\"",
             "-A x64",
         ],
         "//conditions:default": None,

the following error occurs.

C:\Users\homul\sources\rules_foreign_cc\examples>bazel build -c opt //cmake_hello_world_lib/static:libhello_example
DEBUG: C:/users/homul/_bazel_homul/3ndcen5c/external/bazel_toolchains/rules/rbe_repo/version_check.bzl:68:14:
Current running Bazel is ahead of bazel-toolchains repo. Please update your pin to bazel-toolchains repo in your WORKSPACE file.
DEBUG: C:/users/homul/_bazel_homul/3ndcen5c/external/bazel_toolchains/rules/rbe_repo/checked_in.bzl:125:14: buildkite_config not using checked in configs; Bazel version 4.2.1 was picked/selected but no checked in config was found in map {"0.20.0": ["8.0.0"], "0.21.0": ["8.0.0"], "0.22.0": ["8.0.0", "9.0.0"], "0.23.0": ["8.0.0", "9.0.0"], "0.23.1": ["8.0.0", "9.0.0"], "0.23.2": ["9.0.0"], "0.24.0": ["9.0.0"], "0.24.1": ["9.0.0"], "0.25.0": ["9.0.0"], "0.25.1": ["9.0.0"], "0.25.2": ["9.0.0"], "0.26.0": ["9.0.0"], "0.26.1": ["9.0.0"], "0.27.0": ["9.0.0"], "0.27.1": ["9.0.0"], "0.28.0": ["9.0.0"], "0.28.1": ["9.0.0"], "0.29.0": ["9.0.0"], "0.29.1": ["9.0.0", "10.0.0"], "1.0.0": ["9.0.0", "10.0.0"], "1.0.1": ["10.0.0"], "1.1.0": ["10.0.0"], "1.2.0": ["10.0.0"], "1.2.1": ["10.0.0"], "2.0.0": ["10.0.0"], "2.1.0": ["10.0.0"], "2.1.1": ["10.0.0", "11.0.0"], "2.2.0": ["11.0.0"], "3.0.0": ["11.0.0"], "3.1.0": ["11.0.0"], "3.2.0": ["11.0.0"], "3.3.0": ["11.0.0"], "3.3.1": ["11.0.0"], "3.4.1": ["11.0.0"], "3.5.0": ["11.0.0"], "3.5.1": ["11.0.0"], "3.6.0": ["11.0.0"], "3.7.0": ["11.0.0"], "3.7.1": ["11.0.0"], "3.7.2": ["11.0.0"], "4.0.0": ["11.0.0"]}
INFO: Analyzed target //cmake_hello_world_lib/static:libhello_example (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: C:/users/homul/sources/rules_foreign_cc/examples/cmake_hello_world_lib/static/BUILD.bazel:14:6: Foreign Cc - CMake: Building libhello failed: (Exit 1): bash.exe failed: error executing command C:/msys64/usr/bin/bash.exe -c bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello_foreign_cc/wrapper_build_script.sh
rules_foreign_cc: Build failed!
rules_foreign_cc: Keeping temp build directory and dependencies directory for debug.
rules_foreign_cc: Please note that the directories inside a sandbox are still cleaned unless you specify --sandbox_debug Bazel command line flag.
rules_foreign_cc: Printing build logs:
_____ BEGIN BUILD LOGS _____

Bazel external C/C++ Rules. Building library libhello

Environment:______________
BUILD_SCRIPT=bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello_foreign_cc/build_script.sh
EXT_BUILD_ROOT=C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples
BUILD_LOG=bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello_foreign_cc/CMake.log
PWD=/c/users/homul/_bazel_homul/3ndcen5c/execroot/rules_foreign_cc_examples
MSYS_NO_PATHCONV=1
HOME=/home/homul
BUILD_WRAPPER_SCRIPT=bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello_foreign_cc/wrapper_build_script.sh
EXT_BUILD_DEPS=C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples/bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello.ext_build_deps
SYSTEMROOT=C:\Windows
TERM=xterm-256color
TEMP=C:\Users\homul\AppData\Local\Temp
BUILD_TMPDIR=C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples/bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello.build_tmpdir
INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt
SHLVL=2
RUNFILES_MANIFEST_ONLY=1
MSYS2_ARG_CONV_EXCL=*
INSTALLDIR=C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples/bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello
TMP=C:\Users\homul\AppData\Local\Temp
PATH=C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64:/usr/bin:/bin:/c/Windows:/c/Windows/System32:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files/Git/cmd:/c/Program Files/dotnet:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Users/homul/AppData/Local/Programs/Python/Python39:/c/Users/homul/AppData/Local/Programs/Microsoft VS Code/bin:/c/bin:/usr/bin:/c/Users/homul/AppData/Local/Microsoft/WindowsApps:/c/Users/homul/.dotnet/tools:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/VC/VCPackages:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/CommonExtensions/Microsoft/TestWindow:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/MSBuild/Current/bin/Roslyn:/c/Program Files (x86)/Microsoft SDKs/Windows/v10.0A/bin/NETFX 4.8 Tools/x64/:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/Tools/devinit:/c/Program Files (x86)/Windows Kits/10/bin/10.0.18362.0/x64:/c/Program Files (x86)/Windows Kits/10/bin/x64:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools//MSBuild/Current/Bin:/c/Windows/Microsoft.NET/Framework64/v4.0.30319:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/Tools/::/c/Windows/system32:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/Llvm/x64/bin:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin:/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja
WINDIR=C:\Windows
LIB=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\lib\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64
SYSTEMDRIVE=C:
_=/usr/bin/env
__________________________
+ 'C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples/external/cmake-3.21.2-windows-x86_64/bin/cmake.exe' -DCMAKE_TOOLCHAIN_FILE=crosstool_bazel.cmake -DCMAKE_BUILD_TYPE=Release '-DCMAKE_INSTALL_PREFIX=C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples/bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello' '-DCMAKE_PREFIX_PATH=C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples/bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello.ext_build_deps' -DCMAKE_RANLIB= -A x64 -G 'Visual Studio 16 2019' 'C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples/cmake_hello_world_lib/static'
CMake Deprecation Warning at CMakeLists.txt:4 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


CMake Error at CMakeLists.txt:6 (project):
  Generator

    Visual Studio 16 2019

  could not find any instance of Visual Studio.



-- Configuring incomplete, errors occurred!
See also "C:/Users/homul/_bazel_homul/3ndcen5c/execroot/rules_foreign_cc_examples/bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello.build_tmpdir/CMakeFiles/CMakeOutput.log".
_____ END BUILD LOGS _____
rules_foreign_cc: Build wrapper script location: bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello_foreign_cc/wrapper_build_script.sh
rules_foreign_cc: Build script location: bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello_foreign_cc/build_script.sh
rules_foreign_cc: Build log location: bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello_foreign_cc/CMake.log

Target //cmake_hello_world_lib/static:libhello_example failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 3.421s, Critical Path: 1.20s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully

However, if I run the corresponding command directly,

C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples/external/cmake-3.21.2-windows-x86_64/bin/cmake.exe -DCMAKE_TOOLCHAIN_FILE=crosstool_bazel.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples/bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello -DCMAKE_PREFIX_PATH=C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples/bazel-out/x64_windows-opt/bin/cmake_hello_world_lib/static/libhello.ext_build_deps -DCMAKE_RANLIB= -A x64 -G "Visual Studio 16 2019" C:\users\homul\_bazel_homul\3ndcen5c\execroot\rules_foreign_cc_examples/cmake_hello_world_lib/static

it works.

CMake calls IEnumSetupInstances.Next internally like this,

while (SUCCEEDED(enumInstances->Next(1, &instance, NULL)) && instance) {

but instance is always NULL when it's called from bazel.

It's just a hunch, but I think it might have happened after the Windows version was upgraded (10.0.19042.0), because dropping the Windows SDK version or bazel version didn't solve the problem.

Environments

Bazel: 4.2.1
Visual Studio: Visual Studio Build Tools 2019
VC: 14.29.30133
Windows SDK: 10.0.18362.0 (I confirmed that 10.0.19041.0 does not work too)

@homuler
Copy link
Author

homuler commented Sep 29, 2021

If ProgramData is set, I can build it successfully.

diff --git a/examples/cmake_hello_world_lib/static/BUILD.bazel b/examples/cmake_hello_world_lib/static/BUILD.bazel
index b32e9ad..8c909f8 100644
--- a/examples/cmake_hello_world_lib/static/BUILD.bazel
+++ b/examples/cmake_hello_world_lib/static/BUILD.bazel
@@ -13,9 +13,12 @@ filegroup(
 # Shows a standard library
 cmake(
     name = "libhello",
+    env = {
+        "ProgramData": "C:\\ProgramData",
+    },
     generate_args = select({
         "//:windows": [
-            "-G \"Visual Studio 15 2017\"",
+            "-G \"Visual Studio 16 2019\"",
             "-A x64",
         ],
         "//conditions:default": None,

@WeijuZheng
Copy link

This also happened to me. By setting the ProgramData, it works. But it doesn't make sense to me. Can someone explain to me why this help?

Environments

Bazel: 4.2.1
Visual Studio: Visual Studio 2019
VC: 14.29.30133
Windows SDK: 10.0.20348.0

@zchrissirhcz
Copy link

I meet same error with windows-latest. I change -G "Visual Studio 16 2019" -A x64 to -G "Visual Studio 17 2022" -A x64 to solve it.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_foreign_cc!

@github-actions
Copy link

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants