Building WinUI 3 Desktop Application using LLVM/Clang

abhishek.m 46 Reputation points
2022-12-16T13:30:39.24+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.

However, I would like to build this project using LLVM Clang-Cl. Stating for ample clarity, I would also be wanting to use the Generator as 'Ninja'.

Is this possible to achieve?

As a bunch of headers get generated when this project is built, I tried using running cppwinrt.exe manually on this project to generate the relevant headers. While few headers got generated but still a bunch were missing. Also, could not understand how the .g.h/.g.cpp files can get generated without MSBuild.

I have also tried this link - https://github.com/fredemmott/cmake-cpp-winrt-winui3. However, the same doesnt work with LLVM/Clang and Ninja.

Any pointers/suggestions will help.

Community Center | Not monitored
{count} vote

1 answer

Sort by: Most helpful
  1. Mohammad Mohsin Siddiqui 175 Reputation points
    2023-01-11T12:36:10.9666667+00:00

    @Roy Li Can we use clang-cl being shipped with VS. So basically can the below be achieved?

    WinUI project using MSBuild build system (i.e Visual Studio Generator) and for compiler/linker as clang-cl compiler shipped with Visual Studio.

    So 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 clang-cl shipped with
    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 did not generate App.xaml.g.h/App.xaml.g.xpp (and many more files that gets generated if we use VS cl compiler) which means that MSBuild did not run the xamlCompiler task.

    Is there anything specific need to be done to resolve this issue ?

    Regards,

    Mohsin Siddiqui

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.