Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Support compiling projects with Clang #1156

Open
ackh opened this issue Aug 1, 2021 · 7 comments
Open

Proposal: Support compiling projects with Clang #1156

ackh opened this issue Aug 1, 2021 · 7 comments
Assignees
Labels
area-DeveloperTools Issues related to authoring (source and IDL), debugging, HotReload, LiveVisualTree, VS integration feature

Comments

@ackh
Copy link

ackh commented Aug 1, 2021

Proposal: Support compiling projects with Clang

Summary

A while ago, support for compiling C++ desktop apps with Clang was added to Visual Studio (see here, here and here). However, projects created using the Project Reunion Visual Studio Extension do not offer to use Clang as the project's platform toolset. Clang support should be extended for such projects.

Rationale

Project Reunion apps that are written in C++ must use C++/WinRT which means that the C++ code is standards conformant and hence theoretically compilable with any modern C++ compiler. Technically, the compiler shouldn't matter because the code will only run on Windows. But we have a C++ cross-platform codebase that targets Android, iOS and Windows and we do run into compatibility issues between Clang and Visual C++.

Code that compiles fine for Android and iOS with Clang fails to compile with Visual C++ for Windows. An example is a large constexpr array that compiles with Clang but not with Visual C++. We have opened a bug describing this issue more than two years ago but is still not fixed yet. Another example where the compiler matters is in its supported string size. The Visual C++ compiler emits compiler error C2026 if it deems a string to be too long. Clang uses a different, larger limit for strings and the bug I opened regarding this is even older but still not fixed.

There are more examples where C++ compilers are incompatible although they target the same language standard and platform. It is not my intention to put any blame on the Visual C++ compiler team. They simply have more important things to do than fixing those edge case issues. But I want to point out that there are good reasons to compile a codebase with the same compiler everywhere. Although it shouldn't matter it actually does.

Therefore, please consider adding the option to compile projects created using the Project Reunion Visual Studio Extension with Clang.

@sylveon
Copy link

sylveon commented Aug 9, 2021

Relevant: microsoft/microsoft-ui-xaml#1045 (comment)

The workaround I presented here might still work. Clang not showing up as a build tool is a side effect of the Project Reunion templates effectively creating a ""UWP"" project (from the view of the VS project system, not an actual UWP app) for some reason.

My indications regarding coroutines are not useful anymore, as Clang implements C++20 coroutines now.

@MarkIngramUK
Copy link

Support for building with Clang is why I'm sticking with CMake as a build system for now. It's a PITA, and I'd much rather have official support for Clang/LLVM from within Visual Studio. cppwinrt does generate code that is compatible with Clang (assuming a recent version of cppwinrt, not the one that ships in the latest SDK in Visual Studio).

@sylveon
Copy link

sylveon commented Aug 16, 2021

Visual Studio does support clang, as long as you're not making a UWP project (and as indicated above, the PR templates are "UWP"):
image

@MarkIngramUK
Copy link

That's clang-cl. The Clang frontend that partially supports some of CL's command line options. I'm referring to the real (GCC style) Clang frontend, with the LLVM backend (clang-cl uses Microsoft's C2 backend for code generation).

@sylveon
Copy link

sylveon commented Aug 16, 2021

clang-cl translates MSVC style arguments to something the "real" clang can interpret and will invoke it, this will obviously use the "real" clang frontend and LLVM for codegen (as the platform toolset's name indicates). Passing it -v will show the translated clang invocation. You can use -Xclang to directly pass a GCC style argument.

What you're thinking of is Clang/C2, which hasn't been supported for quite some time now (and I haven't even found a way to use it in VS 2019, since it has been superseded by the largely superior clang-cl)

@MarkIngramUK
Copy link

OK, that's interesting. I missed that change, up until now I'd been thinking the LLVM (clang-cl) was indeed Clang/C2 (I figured it was just a string change in the UI). I'd still like to see the option for Clang++ in order to use GCC style syntax, to make things easier for cross-platform development.

For ref, in case anyone else is reading this:
https://devblogs.microsoft.com/cppblog/clang-llvm-support-for-msbuild-projects/

@BenJKuhn BenJKuhn assigned AdamBraden and unassigned BenJKuhn Aug 18, 2021
@BenJKuhn BenJKuhn added the area-DeveloperTools Issues related to authoring (source and IDL), debugging, HotReload, LiveVisualTree, VS integration label Aug 18, 2021
@BrunoBieri
Copy link

Scott Jones gave some insight into this in the January 2022 WinUI Community Call here:
https://youtu.be/k6WJmymqNKE?t=2238

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-DeveloperTools Issues related to authoring (source and IDL), debugging, HotReload, LiveVisualTree, VS integration feature
Projects
None yet
Development

No branches or pull requests

7 participants