Skip to content

Commit

Permalink
Try calling vcvarsall.bat
Browse files Browse the repository at this point in the history
Context: dotnet#808 (comment)
Context: https://github.com/dotnet/runtime/blob/e1e46a8d2ca9c2c932c8ceb61f884c7c82351442/eng/native/init-compiler-and-cmake.cmd
Context: https://github.com/dotnet/runtime/blob/e1e46a8d2ca9c2c932c8ceb61f884c7c82351442/src/mono/mono.proj#L362

We tried calling `vcvars64.bat` during an earlier invocation, which
failed, but we were attempting to call it from YAML.

Instead, take a page out of the dotnet/runtime build system: Instead
of calling `vcvars64.bat` from YAML, instead call it
*from within MSBuild*, via `call path\to\vcvars64.bat && …`.

Thus, on Windows, we do:

	call "%VSINSTALLROOT%\VC\Auxiliary\Build\vcvarsall.bat x86_amd64 && ^
	  cmake -G "NMake Makefiles" -S . -B obj\Debug -DJDK_INCLUDE_LIST=…"
	…
	call "%VSINSTALLROOT%\VC\Auxiliary\Build\vcvarsall.bat x86_amd64 && ^
	  cd obj\Debug && ^
	  nmake VERSION=1

This *appears* to work from a "clean" shell.  What about CI?
  • Loading branch information
jonpryor committed Mar 6, 2021
1 parent ebb3516 commit 93872cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
3 changes: 1 addition & 2 deletions build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ variables:
HostedMacImage: macOS-10.15
HostedWinVS2019: Hosted Windows 2019 with VS2019
NetCoreTargetFrameworkPathSuffix: -netcoreapp3.1
VSInstallDir: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise
MsvcDir: $(VSInstallDir)\VC\Tools\MSVC
VSInstallRoot: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise

jobs:
- job: windows_build
Expand Down
36 changes: 18 additions & 18 deletions tests/NativeTiming/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,33 @@
DependsOnTargets="_PrepareCmake;_BuildNativeTiming">
</Target>

<Target Name="_GetBuildComands">
<ItemGroup Condition=" '$(VSINSTALLROOT)' != '' ">
<_Vcvarsall Include="$(VSINSTALLROOT)\VC\Auxiliary\Build\vcvarsall.bat" />
</ItemGroup>
<PropertyGroup Condition=" '$(VSINSTALLROOT)' != '' And '$(_Vcvarsall->Count())' != '0' ">
<_Vcvarsall>%(_Vcvarsall.Identity)</_Vcvarsall>
<_PrepareToolchain>call "$(_Vcvarsall)" x86_amd64 &amp;&amp; </_PrepareToolchain>
</PropertyGroup>
<PropertyGroup>
<_Make Condition=" '$(OS)' != 'Windows_NT' ">make</_Make>
<_Make Condition=" '$(OS)' == 'Windows_NT' ">nmake</_Make>
</PropertyGroup>
</Target>

<Target Name="_PrepareCmake"
DependsOnTargets="_GetBuildComands"
Inputs="CMakeLists.txt;$(MSBuildThisFileFullPath);NativeTiming.csproj"
Outputs="$(IntermediateOutputPath)CMakeCache.txt">
<MakeDir Directories="$(IntermediateOutputPath)" />
<ItemGroup Condition=" '$(MSVCDIR)' != '' ">
<_Cl Include="$(MSVCDIR)\*\bin\Hostx64\x64\cl.exe" />
</ItemGroup>
<PropertyGroup Condition=" '@(_Cl->Count())' != '0' ">
<_ClPath>%(_Cl.Identity)</_ClPath>
<_ClPath>$(_ClPath.Replace('%5c', '/'))</_ClPath>
</PropertyGroup>
<PropertyGroup>
<_JdkDirs>"-DJDK_INCLUDE_LIST=@(JdkIncludePath, ';')"</_JdkDirs>
<!--
<_Cc Condition=" '$(_ClPath)' != '' " >"-DCMAKE_C_COMPILER=$(_ClPath)"</_Cc>
-->
<_CmakeGenerator Condition=" '$(OS)' != 'Windows_NT' ">-G "Unix Makefiles"</_CmakeGenerator>
<!--
<_CmakeGenerator Condition=" '$(OS)' == 'Windows_NT' ">-G "NMake Makefiles"</_CmakeGenerator>
-->
</PropertyGroup>
<Exec
ContinueOnError="WarnAndContinue"
Command="$(CmakePath) $(_CmakeGenerator) -S . -B $(IntermediateOutputPath) $(_JdkDirs) $(_Cc)"
Command="$(_PrepareToolchain) $(CmakePath) $(_CmakeGenerator) -S . -B $(IntermediateOutputPath) $(_JdkDirs)"
/>
<PropertyGroup>
<_CmakeStatus>$(MSBuildLastTaskResult)</_CmakeStatus>
Expand Down Expand Up @@ -82,14 +85,11 @@
</Target>

<Target Name="_BuildNativeTiming"
DependsOnTargets="_GetBuildComands"
Inputs="timing.c"
Outputs="$(_NativeTimingOutputPath)">
<PropertyGroup>
<_Make Condition=" '$(OS)' != 'Windows_NT' ">make</_Make>
<_Make Condition=" '$(OS)' == 'Windows_NT' ">nmake</_Make>
</PropertyGroup>
<Exec
Command="$(_Make) VERBOSE=1"
Command="$(_PrepareToolchain) $(_Make) VERBOSE=1"
WorkingDirectory="$(IntermediateOutputPath)"
/>
<ItemGroup>
Expand Down

0 comments on commit 93872cf

Please sign in to comment.