#sf #bindings-generator #api-bindings #service-fabric


A Rust library for interacting with the Service Fabric COM API on Windows

3 unstable releases

0.2.1 Dec 15, 2023
0.2.0 Dec 13, 2023
0.1.0 Nov 26, 2023

#77 in Windows APIs

Download history 1/week @ 2024-02-18 32/week @ 2024-02-25 1/week @ 2024-03-03 57/week @ 2024-03-10 3/week @ 2024-03-17 31/week @ 2024-03-31

91 downloads per month

MIT license

151K SLoC

Rust 133K SLoC // 0.0% comments C 17K SLoC // 0.1% comments C++ 1K SLoC // 0.0% comments C# 131 SLoC // 0.2% comments Visual Studio Solution 25 SLoC

Contains (static library, 365KB) InternalFabricUUID.lib, (DOS exe, 240KB) .windows/winmd/sf.winmd, (static library, 165KB) FabricUUID.lib, (static library, 135KB) FabricUUID.lib, (static library, 195KB) InternalFabricUUID.lib, (static library, 5KB) FabricClient.lib and 3 more.


This crate contains Rust bindings for calling Service Fabric (SF) using the native COM API on Windows. The SF APIs are specified through IDL files that we fetch from the github.com/Azure/sf-c-util project.

Generating sf.winmd

The first step is to build the sf.winmd file from the SF IDL files. We do this using the win32metadata tooling that knows how to munch IDL files and produce .winmd files. An msbuild project file has been crafted to accomplish this which you will find at .metadata/generate.proj. I simply followed the instructions from the blog post "Generating metadata for use with the windows crate for Rust" to write this file up. Here's what you'll need to do to generate (or re-generate) sf.winmd:

  1. If you haven't already, install the Visual Studio component called MSVC v143 - VS 2022 C++ ARM64/ARM64EC build tools (Latest) using the Visual Studio Installer. If you're doing this out in the future when VS 2022 is old ancient software, please supplant 2022 with whatever is the current newfangled goodness.

  2. Open a Visual Studio Development terminal and navigate to the .metadata folder and run:

git submodule init --update
dotnet build

That's it. This will generate the sf.winmd file in the .windows\winmd folder.

Generating Rust bindings

Next we generate Rust bindings from the sf.winmd file. This is accomplished using the windows-bindgen and windows-metadata crates. The code for generating this lives in crates/tools/api/src/main.rs. From a terminal that's located in the root of the repo, run the following command to generate (or re-generate) src/bindings.rs.

cargo run --package api

This will gobble up sf.winmd and produce bindings.rs which at the time of writing this readme, is a measly 132,000 odd lines long. Easy peasy.


~2.5M SLoC