Giter Club home page Giter Club logo

mingw-w64-cppwinrt's Introduction

C++/WinRT on MinGW-w64

C++/WinRT is a C++ binding (officially "language projection") for the WinRT1 APIs. Originally developed by Kenny Kerr, it has become a part of the official Windows SDK and the recommended way to consume WinRT APIs from C++. See also the official introduction to C++/WinRT and the WinRT API reference.

C++/WinRT was made with MSVC in mind, but a series of changes to make it compatible with GCC and Clang (also libstdc++ and libc++ respectively) has been merged upstream, making it usable with various MinGW-w64 toolchains (with some limitations). This is a collection of documentation and example code intended to help you understand how to use this binding with a MinGW-w64 toolchain.

If you want to see how C++/WinRT works within Visual Studio, I attempted to document it in a separate file.

Note: If you are using MSVC and Visual Studio, please use the official NuGet package instead.

⚠️ Warning: The information here is work in progress and experimental.

Status

  • ✅ Calling simple WinRT APIs should work.
  • ✅ Some test cases of the upstream test suite pass with MinGW-w64.
  • ❌ XAML UI has not been explored but likely doesn't work out of the box.
  • ❌ Authoring WinRT components is currently impossible (missing tooling to produce WinMD from IDL.)
  • ⚠️ Consuming custom WinRT components may work but has not been tested.
  • ⚠️ Anything involving coroutine needs more testing.
  • ⚠️ Some untested functionality may break in various ways.

Usage Guide

Toolchain

C++/WinRT requires C++20 for its coroutine support. (C++/WinRT officially supports C++17 but only with MSVC-specific coroutine extensions.) You will need a rather recent compiler. You should also try to get the latest MinGW-w64 runtime and headers.

Compilers:

  • LLVM/Clang:
    • ✅ LLVM 15 is recommended.
    • 🔲 LLVM 14 is untested.
    • ⚠️ LLVM 13 does not work out of the box due to missing a floating point std::to_chars implementation in libc++, but can be worked around by disabling the winrt::to_hstring(float) and winrt::to_hstring(double) overloads (microsoft/cppwinrt#1257). It also contains only experimental coroutine support (the stabilized implementation is only available since libc++ 14) so anything involving coroutines should be considered unstable and to be avoided.
    • ⚠️ Earlier versions are untested.
  • GCC:
    • ✅ GCC 12 in MSYS2 has been tested to work.
    • 🔲 GCC 11 is untested.
    • ⚠️ GCC 10 is missing a floating point std::to_chars implementation in libc++ (same as LLVM 13).
    • ❌ GCC 9 and earlier do not support coroutine.

Tested toolchains:

Using cppwinrt with Prebuilt Headers

Headers are built on GitHub Actions workflow runs and made available as build artifacts.

Build System Integration

This project provides both CMake config file and pkg-config file in the releases for using the headers with build systems such as CMake and Autotools. To see how these integrations work, you can check the examples. Better documentation may be added in the future.

(I am still figuring this out, so details are subject to change.)

Building Upstream cppwinrt Directly

If you want to use the upstream cppwinrt tool directly and without build system integration, please refer to Using Upstream cppwinrt.

Licence

All code and resources in this repository are released under the MIT License, unless otherwise specified.

Footnotes

  1. Windows Runtime, not to be confused with the operating system that was called "Windows RT".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.