Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[build] Use $(VSINSTALLDIR), not $(VSINSTALLROOT) (#1048)
Context: 3824b97 Context: a3de91e Context: 5c756b1 Context: https://learn.microsoft.com/en-us/cpp/build/reference/msbuild-visual-cpp-overview?view=msvc-170 There is an "interesting" dichotomy between local Windows builds and CI builds of xamarin/Java.Interop regarding the `%VSINSTALLROOT%` environment variable: 1. `%VSINSTALLDIR%` is set automatically on CI for .NET Framework. 2. `%VSINSTALLROOT%`is *not* set automatically for .NET Framework or .NET Core, which is why commit 5c756b1 added `VSInstallRoot` to the *global* variables block in `azure-pipelines.yaml`. 3. `%VSINSTALLDIR%` *is* set, but `%VSINSTALLROOT%` is *not* set when using the [**Developer Command Prompt For…**][0] shortcut item. The result of this is that `src/java-interop` is built on CI, thus ensuring that it continues to build and works via unit tests (yay), but it is *not* easy to build in a local checkout. The build doesn't fail; it just does not produce per-arch `java-interop.dll` files. (Handy way to check for this: in a diagnostic build log, search for `NativeToolchainSupported = True`. If you don't see it, you don't have Windows support.) This makes things "weird" when trying to help people build the repo on Windows. Furthermore, CI *didn't* use `%VSINSTALLDIR%`, because it was not set when building for .NET Core; `%VSINSTALLROOT%` was set "consistently" for "everyone" (except for local builds). Try to restore some degree of sanity: *probe* for and support *both* `%VSINSTALLDIR%` *and* `%VSINSTALLROOT%`, with `%VSINSTALLROOT%` taking priority, and `%VSINSTALLDIR%` as fallback. Update `azure-pipelines.yaml` so that only .NET Core builds set the `VSINSTALLDIR` environment variable. .NET Framework builds will use the implicitly set `%VsInstallRoot%` env var. Finally, for .NET Core builds, `%VSINSTALLDIR%` ***MUST*** [end with a trailing `\`][1]. If it doesn't, the build will fail in "mysterious" ways: Task "Exec" (TaskId:943) Task Parameter:Command=call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 && cmake -G "NMake Makefiles" -S "D:/a/_work/1/s/src/java-interop/" -B "D:/a/_work/1/s/src/java-interop/obj//Release-net7.0/win-x64/" "-DJDK_INCLUDE_LIST=C:/hostedtoolcache/windows/Java_Temurin-Hotspot_jdk/8.0.345-1/x64/include;C:/hostedtoolcache/windows/Java_Temurin-Hotspot_jdk/8.0.345-1/x64/include/win32" "-DJNI_C_PATH=D:/a/_work/1/s/src/java-interop/obj//Release-net7.0/jni.c" && cmake --build "D:/a/_work/1/s/src/java-interop/obj//Release-net7.0/win-x64/" -v (TaskId:943) call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 && cmake -G "NMake Makefiles" -S "D:/a/_work/1/s/src/java-interop/" -B "D:/a/_work/1/s/src/java-interop/obj//Release-net7.0/win-x64/" "-DJDK_INCLUDE_LIST=C:/hostedtoolcache/windows/Java_Temurin-Hotspot_jdk/8.0.345-1/x64/include;C:/hostedtoolcache/windows/Java_Temurin-Hotspot_jdk/8.0.345-1/x64/include/win32" "-DJNI_C_PATH=D:/a/_work/1/s/src/java-interop/obj//Release-net7.0/jni.c" && cmake --build "D:/a/_work/1/s/src/java-interop/obj//Release-net7.0/win-x64/" -v (TaskId:943) ********************************************************************** (TaskId:943) ** Visual Studio 2022 Developer Command Prompt v17.3.5 (TaskId:943) ** Copyright (c) 2022 Microsoft Corporation (TaskId:943) ********************************************************************** (TaskId:943) [ERROR:VsDevCmd.bat] *** VsDevCmd.bat encountered errors. Environment may be incomplete and/or incorrect. *** (TaskId:943) [ERROR:VsDevCmd.bat] In an uninitialized command prompt, please 'set VSCMD_DEBUG=[value]' and then re-run (TaskId:943) [ERROR:VsDevCmd.bat] vsdevcmd.bat [args] for additional details. (TaskId:943) [ERROR:VsDevCmd.bat] Where [value] is: (TaskId:943) [ERROR:VsDevCmd.bat] 1 : basic debug logging (TaskId:943) [ERROR:VsDevCmd.bat] 2 : detailed debug logging (TaskId:943) [ERROR:VsDevCmd.bat] 3 : trace level logging. Redirection of output to a file when using this level is recommended. (TaskId:943) [ERROR:VsDevCmd.bat] Example: set VSCMD_DEBUG=3 (TaskId:943) [ERROR:VsDevCmd.bat] vsdevcmd.bat > vsdevcmd.trace.txt 2>&1 (TaskId:943) CMake Error at CMakeLists.txt:3 (project): (TaskId:943) … ##[warning]EXEC(0,0): Warning : CMAKE_CXX_COMPILER not set, after EnableLanguage ##[warning]EXEC(0,0): Warning : CMAKE_C_COMPILER not set, after EnableLanguage [0]: https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170#developer_command_file_locations [1]: https://developercommunity.visualstudio.com/t/vcvars32bat-fails-after-upgrade-to-vs-2017-version/375841
- Loading branch information