paleozogt / MSVCDocker

MSVC via Wine in Docker
121 stars 21 forks source link

Is it possible and does it make sense to use clang to build apps linked to MSVC runtime? #1

Closed KOLANICH closed 5 years ago

KOLANICH commented 5 years ago

I guess if it is possible to do it, full MSVC build tools are not needed, wine is not needed, the only needed thing are msvc headers and libs, and it is still possible to make libs suitable for the apps using msvc runtime as python (for other apps it makes no sense to use ms compiler and runtime).

paleozogt commented 5 years ago

I don't think its possible. AFAIK, Clang isn't ABI compatible with MSVC.

KOLANICH commented 5 years ago

https://clang.llvm.org/docs/MSVCCompatibility.html

First, Clang attempts to be ABI-compatible, meaning that Clang-compiled code should be able to link against MSVC-compiled code successfully. However, C++ ABIs are particularly large and complicated, and Clang’s support for MSVC’s C++ ABI is a work in progress.

paleozogt commented 5 years ago

Now, that's very interesting. It looks like clang-cl is

the first-ever open-source C++ compiler that’s ABI-compatible with Microsoft Visual C++ (MSVC)

Both Chrome and Firefox use clang-cl/lld-link, so its not just a beta feature.

At first glance it seems like we could cross-compile with clang on a Linux host. Some thoughts:

It's definitely worth looking into. Thanks for the info!

KOLANICH commented 5 years ago

clang-cl requires at least Windows SDK headers/libs. It's unclear how to get those files. Perhaps we could install them on a Windows VM and copy them over into a Docker image just like we do with MSVC proper.

If we have to install MSVC in order to get the CRT for clang, is it worth it to use clang

Or you can install (or just download) VS in Windows, obtain a direct link to msi files by proxying all the requests via mitmproxy, then download only the needed msis by direct links and install (requires wine, but .net is not needed) or unpack (doesn't require wine, only msitools) only them. Should consume much less space than full VS build tools installed by the installer (the installer lacks customization, for example it installs toolchains for unneeded platforms and there is (at least was the last time I have installed MSVC and on the feedback site the support have claimed that adding customization to the installer is not planned) no way to disable it other than not to use it at all);

Getting tools like CMake to use clang-cl might be problematic on a non-Windows host.

In fact on Windows host it is problematic to use CMake + CLang + MinGW since Kitware have embedded a check and shows the message "this setup is unsupported" so I have to patch CMake stdlib in order to build CLang + MinGW on Windows host. It is obviously a bug in CMake. So if CLang + MSVC is unsupported, you may need to create a patch file and apply it after cmake installation. And a toolchain file is obviously needed.

For example, CMake doesn't have an MSVC generator on Linux hosts.

You don't need clang-cl. The only difference of clang-cl from usual clang is MSVC-compatible command line interface. You can compile with usual clang using usual flags like in GCC and still use MS libs and runtime.

It's unclear if the MSVCRT runtime is part of the Windows SDK or not.

It isn't and Windows SDK really depends on MSVC. MinGW and ReactOS use 9wn SDKs and DDKs which are far from being complete.

paleozogt commented 5 years ago

@KOLANICH With b6ac118532ae4d51e609549bacd44ac09d54ac94 I've updated the project to support clang-cl. Thanks for the suggestion!