paleozogt / MSVCDocker

MSVC via Wine in Docker
121 stars 20 forks source link

msbuild with cmake #13

Open NeroBurner opened 4 years ago

NeroBurner commented 4 years ago

In the known issues the following is stated

vcwine cmake ../../test -G "Visual Studio 15 2017 Win64"
vcwine msbuild

is it just, that manually calling msbuild does not work or is something from the environment missing as well?

At our Windows CI builds we use the following commands

cmake -H. -Bbuild -G "Visual Studio 15 2017 Win64"
cmake --build build --config Release

Can someone test if these commands work with vcwine put before them?

vcwine cmake -H. -Bbuild -G "Visual Studio 15 2017 Win64"
vcwine cmake --build build --config Release
paleozogt commented 4 years ago

I think its because something is missing from the wine installation. Probably something subtle with .Net. I haven't been able to figure out what it is, though.

NeroBurner commented 4 years ago

I'm very interested in the error message when you execute vcwine cmake --build build --config Release

paleozogt commented 4 years ago

Running CMake with the Visual Studio generator falls down like this:

vcwine cmake --debug-output .. -G "Visual Studio 15 2017 Win64"
Running with debug output on.
CMake Error at CMakeLists.txt:2 (project):
  Generator

    Visual Studio 15 2017 Win64

  could not find any instance of Visual Studio.

It's hard to see what's failing, but I suspect its due to msbuild not working.

Running msbuild directly shows:

vcwine msbuild '/?'
MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
System.ComponentModel.Win32Exception (0x80004005): Access denied
   at Microsoft.Build.Shared.BuildEnvironmentHelper.get_Instance()
   at Microsoft.Build.Utilities.Traits.get_Instance()
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String commandLine)

Unhandled Exception: System.ComponentModel.Win32Exception: Access denied
   at Microsoft.Build.Shared.BuildEnvironmentHelper.get_Instance()
   at Microsoft.Build.Utilities.Traits.get_Instance()
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String commandLine)
   at Microsoft.Build.CommandLine.MSBuildApp.Main()
wine: Unhandled exception 0xe0434352 in thread 37 at address 0x7b43de4c (thread 0037), starting debugger...
Can't attach process 0036: error 5

Figuring out what msbuild is unhappy about would be super helpful.

NeroBurner commented 4 years ago

Thank you!

On windows I need to call vcvarsall.bat before msbuild works. Could this be part of the error?

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64

source: https://stackoverflow.com/questions/43372235/vcvarsall-bat-for-visual-studio-2017#43570522

paleozogt commented 4 years ago

The entrypoint to the image runs a script called vcwine which sets up the environment in the same way that vcvarsall does. A fair bit of the logic in this project is to have that get set up properly (and transparently to the docker user).

You can tell that the env is setup properly in a couple ways. One is that cl is in the PATH:

➜  vcwine which cl
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\cl.EXE

The other is that CMake will happily generate NMake projects:

➜  cd test
➜  mkdir .build && cd .build
➜  vcwine cmake .. -G "NMake Makefiles"
-- The C compiler identification is MSVC 19.16.27035.0
-- The CXX compiler identification is MSVC 19.16.27035.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: Z:/host/home/paleozogt/Development/MSVCDocker/test/.build
➜ 
➜ vcwine nmake
Microsoft (R) Program Maintenance Utility Version 14.16.27035.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Scanning dependencies of target helloworld
[ 50%] Building CXX object CMakeFiles/helloworld.dir/helloworld.cpp.obj
helloworld.cpp
[100%] Linking CXX executable helloworld.exe
[100%] Built target helloworld
➜
➜ vcwine ./helloworld.exe
hello world from win x86_64 msvc v1916

Why MSBuild doesn't work is still a mystery to me. :(

NeroBurner commented 4 years ago

Thabk you for taking the time to explain things to me

I didn't know that msbuild has its source available on github

https://github.com/microsoft/msbuild

Maybe the bug has something to do with the .Net framework used. Is mono installed in the wine environment?

paleozogt commented 4 years ago

We're using .Net proper. From Dockerfile.wine:

# dotnet in wine
RUN winetricks -q dotnet472