Building WinUI 3 Desktop Application using MSBuild with Visual Studio LLVM clang-cl

Mohammad Mohsin Siddiqui 175 Reputation points
2023-01-16T06:06:52.7133333+00:00

Hi, When I create a WinUI project in Visual Studio, below is how the project structure looks like:

271349-image.png

This project by default gets built using MSBuild as build system and default MSVS compiler.

However, I would like to build this project using MSBuild as build system and Visual Studio' LLVM toolset for compilation and linker.

Is this possible to achieve?

This is how I am trying.

  1. installed clang-cl vis VS load User's image
  2. Generated CMake cache using CMake like below cmake -G "Visual Studio 17 2022" -T ClangCl D:\WinUI\cmake-cpp-winrt-winui3-master_LLVMclang-cl\cmake-cpp-winrt-winui3-master>cmake -S . -G "Visual Studio 17 2022" -T ClangCL -- Building for: Visual Studio 17 2022 -- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621. -- The C compiler identification is Clang 15.0.1 with MSVC-like command-line -- The CXX compiler identification is Clang 15.0.1 with MSVC-like command-line And this automatically picks VS's LLVM's clang-cl.exe as compiler
  3. But when I build like below, it fails. D:\WinUI\cmake-cpp-winrt-winui3-master_LLVMclang-cl\cmake-cpp-winrt-winui3-master>cmake --build . It fails with below error
    D:\WinUI\cmake-cpp-winrt-winui3-master_LLVMclang-cl\cmake-cpp-winrt-winui3-master\src/App.xaml.h(4,10): fatal error : 'App.xaml.g.h' file not found [D:\Wi nUI\cmake-cpp-winrt-winui3-master_LLVMclang-cl\cmake-cpp-winrt-winui3-master\src\DemoApp.vcxproj] D:\WinUI\cmake-cpp-winrt-winui3-master_LLVMclang-cl\cmake-cpp-winrt-winui3-master\src\MainWindow.xaml.cpp(9,3): error : use of undeclared identifier 'Initi alizeComponent' [D:\WinUI\cmake-cpp-winrt-winui3-master_LLVMclang-cl\cmake-cpp-winrt-winui3-master\src\DemoApp.vcxproj] D:\WinUI\cmake-cpp-winrt-winui3-master_LLVMclang-cl\cmake-cpp-winrt-winui3-master\src\MainWindow.xaml.cpp(15,12): error : function 'IsSettingsInvoked' with deduced return type cannot be used before it is defined [D:\WinUI\cmake-cpp-winrt-winui3-master_LLVMclang-cl\cmake-cpp-winrt-winui3-master\src\DemoApp.vcx proj]

It seems MSBuild process did not generate App.xaml.g.h/App.xaml.g.xpp (and many more files that gets generated if we use MSVC Compiler )) which means that MSBuild did not run the xamlCompiler task to generate .g.h and g.cpp files.

Is there anything specific need to be done to resolve this issue? Am I missing something here?

Any pointers/suggestions will help.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,583 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,519 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,883 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 81,461 Reputation points
    2023-01-16T08:49:59.39+00:00

    There was an issue on GitHub, but it is still open :

    Proposal: Support compiling projects with Clang #1156

    You can upvote/add a comment to draw attention to MS people...

    0 comments No comments