From 28d78405773aa532c28cd3bd9eaa8ee7f1779ac0 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Fri, 7 Oct 2022 13:17:42 -0400 Subject: [PATCH 1/6] [build] Use $(VSINSTALLDIR), not $(VSINSTALLROOT) Context: 3824b974dada6f302ed5f7b7f97ffbd08990a82a Context: a3de91efdaec04b3927b755a07018e8d26cfdc71 Context: https://learn.microsoft.com/en-us/cpp/build/reference/msbuild-visual-cpp-overview?view=msvc-170 I do not remember why commit 3824b974 went with `$(VSINSTALLROOT)`, but the `%VSINSTALLROOT%` environment variable is *not* set within the Visual Studio Command Prompt `VsDevCmd.bat`. This means that when building `src/java-interop` on Windows off of CI, by default it won't do anything, because `$(NativeToolchainSupported)` won't be set. Replace all usage of `$(VSINSTALLROOT)` with `$(VSINSTALLDIR)`, which *is* documented, and *is* set by `VsDevCmd.bat`. This should allow Windows builds to produce `java-interop.dll` without grief. --- build-tools/automation/azure-pipelines.yaml | 2 +- build-tools/scripts/NativeToolchain.targets | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index d115f99f6..4837ea114 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -28,7 +28,7 @@ variables: 1ESWindowsImage: AzurePipelinesWindows2022compliant 1ESMacPool: Azure Pipelines 1ESMacImage: internal-macos-11 - VSInstallRoot: C:\Program Files\Microsoft Visual Studio\2022\Enterprise + VSInstallDir: C:\Program Files\Microsoft Visual Studio\2022\Enterprise jobs: - job: windows_build diff --git a/build-tools/scripts/NativeToolchain.targets b/build-tools/scripts/NativeToolchain.targets index 1618c5b44..d5d6a5d93 100644 --- a/build-tools/scripts/NativeToolchain.targets +++ b/build-tools/scripts/NativeToolchain.targets @@ -1,7 +1,7 @@ - - <_VcvarsallPath>$(VSINSTALLROOT)\VC\Auxiliary\Build\vcvarsall.bat + + <_VcvarsallPath>$(VSINSTALLDIR)\VC\Auxiliary\Build\vcvarsall.bat From 7cbfe43b219e49e108c119baf3bd1b7527145df7 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Fri, 7 Oct 2022 14:03:51 -0400 Subject: [PATCH 2/6] Fails on CI. (Of course!) but why! Pull out the diagnostic logging! --- build-tools/automation/azure-pipelines.yaml | 4 ++-- build-tools/automation/templates/core-build.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index 4837ea114..2726aca7a 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -28,7 +28,6 @@ variables: 1ESWindowsImage: AzurePipelinesWindows2022compliant 1ESMacPool: Azure Pipelines 1ESMacImage: internal-macos-11 - VSInstallDir: C:\Program Files\Microsoft Visual Studio\2022\Enterprise jobs: - job: windows_build @@ -65,7 +64,8 @@ jobs: inputs: solution: Java.Interop.sln configuration: $(Build.Configuration) - msbuildArguments: /restore + msbuildArguments: /restore -v:diag + logFileVerbosity: 'diagnostic' - task: MSBuild@1 displayName: MSBuild RunNUnitTests.targets diff --git a/build-tools/automation/templates/core-build.yaml b/build-tools/automation/templates/core-build.yaml index 0283fcdae..e32385604 100644 --- a/build-tools/automation/templates/core-build.yaml +++ b/build-tools/automation/templates/core-build.yaml @@ -19,4 +19,4 @@ steps: displayName: Build Solution inputs: projects: Java.Interop.sln - arguments: '-c $(Build.Configuration)' + arguments: '-c $(Build.Configuration) -v:diag' From 70e50b494486298f64a63a5d0635b960d9b1ce26 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Fri, 7 Oct 2022 15:15:18 -0400 Subject: [PATCH 3/6] Why %VSINSTALLROOT%? Because that's what exists on CI; for the ".NET Framework" + VS 2022 CI bot, courtesy a 449MB build log, VS 2022 has: VsInstallRoot = C:\Program Files\Microsoft Visual Studio\2022\Enterprise among many, many other env vars which contain `\2022\Enterprise`. The .NET Core build, meanwhile, has *none of that*. It also shows significantly fewer environment variables; 55 lines of env vars vs. 209 for .NET Framework. (Added security?) Make a squircle: update the `$(_VcvarsallPath)` check to support *both* `$(VsInstallRoot)` (.NET Framework CI) and `$(VsInstallDir)`. The .NET Core Windows build will explicitly set `VsInstallDir`. Hopefully this results in a viable build environment. --- build-tools/automation/azure-pipelines.yaml | 2 ++ build-tools/scripts/NativeToolchain.targets | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index 2726aca7a..bec49f213 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -85,6 +85,8 @@ jobs: name: $(1ESWindowsPool) demands: - ImageOverride -equals $(1ESWindowsImage) + variables: + VSINSTALLDIR: C:\Program Files\Microsoft Visual Studio\2022\Enterprise timeoutInMinutes: 20 workspace: clean: all diff --git a/build-tools/scripts/NativeToolchain.targets b/build-tools/scripts/NativeToolchain.targets index d5d6a5d93..5632946a5 100644 --- a/build-tools/scripts/NativeToolchain.targets +++ b/build-tools/scripts/NativeToolchain.targets @@ -1,7 +1,9 @@ - - <_VcvarsallPath>$(VSINSTALLDIR)\VC\Auxiliary\Build\vcvarsall.bat + + <_VSInstallDir Condition=" '$(VsInstallRoot)' != '' ">$(VsInstallRoot) + <_VSInstallDir Condition=" '$(_VSInstallDir)' == '' And '$(VsInstallDir)' != '' ">$(VsInstallDir) + <_VcvarsallPath Condition=" '$(_VSInstallDir)' != '' ">$(_VSInstallDir)\VC\Auxiliary\Build\vcvarsall.bat From 2f0d464c9c2ea299560cd8f8dbdbf8422f41006a Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Fri, 7 Oct 2022 16:00:38 -0400 Subject: [PATCH 4/6] Did the squircle work? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mostly. Even though the .NET Core build logs *still* don't contain `VsInstallDir` -- part of the `variables:` block in `azure-pipelines.yaml` -- the logs *do* contain `NativeToolchainSupported = True`. The updated `VsInstallDir` check works! What *doesn't* work is the actual src/java-interop build (?!) 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 Since .NET Framework builds now, remove the diagnostic logging for .NET Framework in 7cbfe43b219e49e108c119baf3bd1b7527145df7. Update `RunCmake.proj` so that we do as the warning suggests: add `set VSCMD_DEBUG=3` as part of the build. --- build-tools/automation/azure-pipelines.yaml | 3 +-- build-tools/scripts/RunCmake.proj | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index bec49f213..8dd53293e 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -64,8 +64,7 @@ jobs: inputs: solution: Java.Interop.sln configuration: $(Build.Configuration) - msbuildArguments: /restore -v:diag - logFileVerbosity: 'diagnostic' + msbuildArguments: /restore - task: MSBuild@1 displayName: MSBuild RunNUnitTests.targets diff --git a/build-tools/scripts/RunCmake.proj b/build-tools/scripts/RunCmake.proj index 5ea67f6b5..98e2a9265 100644 --- a/build-tools/scripts/RunCmake.proj +++ b/build-tools/scripts/RunCmake.proj @@ -25,7 +25,7 @@ <_Prepare>$(PrepareNativeToolchain) - <_Prepare Condition=" '$(_Prepare)' != '' And !$(_Prepare.Trim().EndsWith('&&')) ">$(_Prepare) && + <_Prepare Condition=" '$(_Prepare)' != '' And !$(_Prepare.Trim().EndsWith('&&')) ">set VSCMD_DEBUG=3 && $(_Prepare) && <_SourceDir>$(CmakeSourceDir.Replace('%5c', '/')) <_BuildDir>$(CmakeBuildDir.Replace('%5c', '/')) <_ExtraArgs>$(CmakeExtraArgs.Replace('%5c', '/')) From 0a6669fbfb70a653ba9f04a390b323c7b523c1d4 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Fri, 7 Oct 2022 18:15:12 -0400 Subject: [PATCH 5/6] Fixity fix? Now that we have `set VSCMD_DEBUG=3`, we have *moar input*: [DEBUG:VsDevCmd.bat] calling "ext\clang_cl.bat" (TaskId:5320) [ERROR:ext\clang_cl.bat] init:FAILED code:1 (TaskId:5320) `ext\clang_cl.bat` is failing. Unfortunately, my local VS install doesn't have `clang_cl.bat`, and the log file doesn't have much additional information. :-( Some "random" searching later, and we hit: https://developercommunity.visualstudio.com/t/vcvars32bat-fails-after-upgrade-to-vs-2017-version/375841 > The main issue with the error message " init:FAILED code:1" was, it was just a mere message to the user, it was not a actual error message in my case, for me the actual error was there was no trailing "\" appended for environment variable "VSINSTALLDIR" (?!) Update `azure-pipelines.yaml` so that `VSINSTALLDIR` ends with `\`. --- build-tools/automation/azure-pipelines.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index 8dd53293e..710adfbf6 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -85,7 +85,7 @@ jobs: demands: - ImageOverride -equals $(1ESWindowsImage) variables: - VSINSTALLDIR: C:\Program Files\Microsoft Visual Studio\2022\Enterprise + VSINSTALLDIR: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\ timeoutInMinutes: 20 workspace: clean: all From ab4b9e35385cbe5263d0171953b6912ffb3895e1 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Fri, 7 Oct 2022 20:14:05 -0400 Subject: [PATCH 6/6] Remove debug logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Context: 3824b974dada6f302ed5f7b7f97ffbd08990a82a Context: a3de91efdaec04b3927b755a07018e8d26cfdc71 Context: 5c756b143043e8981116c36c30b5ebf2fc63adb1 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 5c756b14 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 --- build-tools/automation/templates/core-build.yaml | 2 +- build-tools/scripts/RunCmake.proj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build-tools/automation/templates/core-build.yaml b/build-tools/automation/templates/core-build.yaml index e32385604..0283fcdae 100644 --- a/build-tools/automation/templates/core-build.yaml +++ b/build-tools/automation/templates/core-build.yaml @@ -19,4 +19,4 @@ steps: displayName: Build Solution inputs: projects: Java.Interop.sln - arguments: '-c $(Build.Configuration) -v:diag' + arguments: '-c $(Build.Configuration)' diff --git a/build-tools/scripts/RunCmake.proj b/build-tools/scripts/RunCmake.proj index 98e2a9265..5ea67f6b5 100644 --- a/build-tools/scripts/RunCmake.proj +++ b/build-tools/scripts/RunCmake.proj @@ -25,7 +25,7 @@ <_Prepare>$(PrepareNativeToolchain) - <_Prepare Condition=" '$(_Prepare)' != '' And !$(_Prepare.Trim().EndsWith('&&')) ">set VSCMD_DEBUG=3 && $(_Prepare) && + <_Prepare Condition=" '$(_Prepare)' != '' And !$(_Prepare.Trim().EndsWith('&&')) ">$(_Prepare) && <_SourceDir>$(CmakeSourceDir.Replace('%5c', '/')) <_BuildDir>$(CmakeBuildDir.Replace('%5c', '/')) <_ExtraArgs>$(CmakeExtraArgs.Replace('%5c', '/'))