Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Enable build with Visual Studio 2017#2390

Merged
jkotas merged 17 commits intodotnet:masterfrom
wjk:vs2017-build
Dec 23, 2016
Merged

Enable build with Visual Studio 2017#2390
jkotas merged 17 commits intodotnet:masterfrom
wjk:vs2017-build

Conversation

@wjk
Copy link
Contributor

@wjk wjk commented Dec 19, 2016

This PR enables building (the native parts of) CoreRT using Visual Studio 2017 RC.

Closes #2383.

@wjk
Copy link
Contributor Author

wjk commented Dec 19, 2016

@jkotas I had to update the minimum CMake version to 3.7.0 to enable compilation with VS2017, as earlier versions don't support that version of VS. However, I presume that the CI machines don't have this version of VS installed, as all 6 checks failed as I was writing this. However, this version is only required when building for VS2017; earlier versions (or non-VS build systems) will still work with the older version previously used. Unfortunately, I don't know how to express this in CMake. Could you give me a few pointers? Thanks!

@wjk
Copy link
Contributor Author

wjk commented Dec 19, 2016

In addition, I cannot yet successfully build CoreRT using VS2017, because when the build script sources vcvarsall.bat, it places a copy of CMake on the front of the PATH that is too old (version 3.6.20160606-g836e2-dirty-MSVC, to be precise). This prevents the command prompt from using the 3.7.0 version of CMake that I previously installed separately. Could you help me with this as well?

@jkotas
Copy link
Member

jkotas commented Dec 19, 2016

Try something like:

if(NOT(CMAKE_VERSION VERSION_LESS 3.7.0))
    message(FATAL_ERROR "CMake version 3.7.0 or higher is required to compile with VS2017")
endif()

@jkotas
Copy link
Member

jkotas commented Dec 19, 2016

when the build script sources vcvarsall.bat, it places a copy of CMake on the front of the PATH that is too old (version 3.6.20160606-g836e2-dirty-MSVC, to be precise

Can we just use this version of CMake that comes with VS2017? Or is it not possible for some reason?

@wjk
Copy link
Contributor Author

wjk commented Dec 20, 2016

@jkotas According to the CMake website, CMake 3.7.0 is the minimum required version for VS2017 support. I will test on the version of CMake that is bundled, however. I have researched how to check the generator being used, and will push a commit later tonight that only requires a higher CMake version when targeting VS2017.

William Kent added 4 commits December 19, 2016 20:25
Unfortunately, the generated solution then does not build
correctly. I am still looking into this.
The code previously assumed that the probe-win.ps1 script is located in the
current working directory. During my testing, I found that this is not robust
enough for all use-cases. Using %~dp0 to identify the directory containing the
batch file is more robust against this issue.
@wjk
Copy link
Contributor Author

wjk commented Dec 20, 2016

@jkotas Note: The Ubuntu builds are currently failing with the following message:

There was an error processing the xunit test results: [xUnit] [ERROR] - No test reports found for the metric 'xUnit.Net' with the resolved pattern '**/testResults.xml'. Configuration error?.

I don't know what this means, but it seems unrelated to these changes.

@wjk
Copy link
Contributor Author

wjk commented Dec 20, 2016

I have fixed the build to function correctly using the CMake version included with VS2017. I have adjusted the version check to 3.6.0 accordingly.

However, I am running into a very strange issue: When the Visual Studio files generated by CMake are built by the automated build-native.cmd file, the build fails immediately complaining that The build tools for v141 (PlatformToolset = 'v141') cannot be found. Yet, when I build the exact same MSBuild files from the command line (using msbuild /nologo INSTALL.vcxproj), the build does not encounter this problem, and in fact completes successfully with no issues! Can you please help me resolve this?

Only the copy of MSBuild shipped with VS2017 can successfully
build VS2017 vcxproj files. Using any other copy will cause
strange errors.
@wjk
Copy link
Contributor Author

wjk commented Dec 20, 2016

My latest commit fixes the problem mentioned in my comment above regarding the PlatformToolset; please disregard that.

@wjk
Copy link
Contributor Author

wjk commented Dec 20, 2016

And the CoreRT build cycle (native and managed) completes successfully on my computer with no issues! I think this one may be ready to merge. Note that the CI system won't test these changes, as this is an optional feature that must be explicitly enabled by the user.

@jkotas
Copy link
Member

jkotas commented Dec 20, 2016

There was an error processing the xunit test results

This is cascading error. The primary error is:

18:00:23 CMake Error at functions.cmake:11 (string):
18:00:23   string end index: 21 is out of range -1 - 14
18:00:23 Call Stack (most recent call first):
18:00:23   CMakeLists.txt:7 (string_has_prefix)

@jkotas
Copy link
Member

jkotas commented Dec 20, 2016

Also, if I just fetch your branch and run "build.cmd", it fails with:

'_msbuildexe' is not recognized as an internal or external command, operable program or batch file.

William Kent added 4 commits December 19, 2016 21:54
Third time's the charm, right?
This should fix the problem @jkotas is reporting, but
I cannot be certain.
@wjk
Copy link
Contributor Author

wjk commented Dec 20, 2016

@jkotas Try it now. I have fixed the Ubuntu build issue, and I should have fixed the issue you are having. (I have confirmed that it no longer complains of the issue you reported, but I cannot make that specific configuration build on my PC. This is because the only version of CMake I have now is the one in VS2017; I uninstalled the other because I didn't think I would need it anymore.) Sorry about that!

@jkotas
Copy link
Member

jkotas commented Dec 20, 2016

This batch file variable is still misbehaving if I do "build.cmd vs2017". Here is output with set _echo=on:

 if not exist !_msbuildexe! (set _msbuildexe="C:\Program Files\MSBuild\14.0\Bin\MSBuild.exe" )
 if not exist !_msbuildexe! (echo Error: Could not find MSBuild.exe.  Please see https://github.com/dotnet/corert/blob/master/Documentation/prerequisites-for-building.md for build instructions.   && exit /b 1 )
)
The system cannot find the drive specified.
The system cannot find the drive specified.
The system cannot find the drive specified.

@jkotas
Copy link
Member

jkotas commented Dec 20, 2016

@janvorli Could you please take a look at the CMake changes?


set __VSProductVersion=
if /i "%__VSVersion%" == "vs2015" set __VSProductVersion=140
if /i "%__VSVersion%" == "vs2017" set __VSProductVersion=150
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to mention vs2017 in the help text at the end of the file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wjk
Copy link
Contributor Author

wjk commented Dec 20, 2016

@jkotas Regarding those drive-not-found errors: I've seen those, and have no idea what is causing them. Since they seem to have no effect on the build, I was ignoring them, but I understand how they should be corrected before this PR is merged. I will get on the documentation sometime tomorrow.

# Include cmake functions
include(functions.cmake)

string_has_prefix(${CMAKE_GENERATOR} "Visual Studio 15 2017" GENERATOR_IS_VS2017)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to introduce a new function. string(FIND ${CMAKE_GENERATOR} "Visual Studio 15 2017" VS2017_POS) and comparing VS2017_POS to 0 would work for this purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janvorli Thank you! For some reason I couldn't find that in the documentation. I will get that fixed later today.


:: VS2017 changed the location of vcvarsall.bat.
if /i "%__VSVersion%" == "vs2017" (
call "!VS%__VSProductVersion%COMNTOOLS!\..\..\VC\Auxiliary\Build\vcvarsall.bat" %__VCBuildArch%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: tabs -> spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be precise, how many spaces?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 spaces per tab

@jkotas
Copy link
Member

jkotas commented Dec 22, 2016

drive-not-found errors: I've seen those, and have no idea what is causing them.

They are caused by the :: tagged comment inside the if block that you have added. You can fix them by using the old fashioned rem instead of :: for the comment.

The Windows batch file interpreter treats these two
symbols differently. When "::" is used within an if
block, it can create spurious drive-not-found errors.
Using "rem" avoids this problem.
@jkotas
Copy link
Member

jkotas commented Dec 23, 2016

Thank you!

@jkotas jkotas merged commit 13f9167 into dotnet:master Dec 23, 2016
@wjk wjk deleted the vs2017-build branch December 23, 2016 03:29
MichalStrehovsky added a commit to MichalStrehovsky/corert that referenced this pull request Apr 26, 2017
This is a followup to dotnet#2390 that fixes a few things:

* vs2017 no longer needs to be passed to build.cmd (it will be
autodetected)
* Building and running tests now works
* Documentation updates to point out running from Developer Command
prompt is needed.

Fixes dotnet#3394.
jkotas pushed a commit that referenced this pull request Apr 27, 2017
This is a followup to #2390 that fixes a few things:

* vs2017 no longer needs to be passed to build.cmd (it will be
autodetected)
* Building and running tests now works
* Documentation updates to point out running from Developer Command
prompt is needed.

Fixes #3394.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants