Hi all,
I would like to share an open-source project I have been working on called Windows Kit, which aims to provide a Swift language projection for both Win32 (C and COM) and WinRT APIs from the Windows SDK, Windows App SDK, and Windows Driver Kit.
See the README for a more approachable and detailed introduction to the background for this project.
The features I have implemented in the projection generator so far include:
- Pure Swift and cross-platform
- A Windows Metadata parser made with Swift Binary Parsing (only implementing the subset of ECMA-335 used by Windows Metadata, which saves a lot of work)
- Downloads Windows Metadata packages from the NuGet Server API in
.nupkg
format (which is just a renamed.zipfile) and caches the metadata files
locally - A ZIP format parser also made with Swift Binary Parsing (used to extract the NuGet packages)
- A Deflate decompressor (used in the ZIP parser) made with a
BitSpan
non-copyable LSB bit reader inspired byParserSpanfrom Swift Binary Parsing
and a two-level lookup table for Huffman decoding like zlib - Generates and prints the desired Swift interfaces for classes, enums, and structs using SwiftSyntax
The differences to the existing WinRT projection by The Browser Company from a user's perspective will be the expanded API surface available and distribution as pre-made Swift packages instead of requiring a local CMake setup to run the projection generator. I also plan to use C++ interop for COM and WinRT instead of C interop (as COM was designed to be a subset of the C++ ABI, and WinRT is based on COM) which will be simpler and possibly easier for the compiler to optimise. And it will take more advantage of Clang attributes to let the compiler do much of the projection work on its own.
The main work to do next will be working out how the generated C, C++, and Swift code will interact, completing the projection of each of the constructs in Windows Metadata, and handling the unique aspects of the NuGet packages for each SDK.
The codebase has lots of comments documenting what I've learned about Windows Metadata and keeping it as easy to understand as possible has been a major goal. I have also written a document explaining the Windows Metadata format and strategies I used to maintain safety when parsing it.
I am open to collaborating if anyone is interested. Thanks for reading!