The windows crate, which provides Rust bindings to the Windows API, is split into a few internal crates, one of them being the windows-targets. This create is also split in a few internal crates, and these are loaded according to the target platform.
These platform-dependent crates don't seem to do much: they simply pass cargo:rustc-link-search=native={LIB_DIR}
to the compiler.
Now looking at these LIB_DIR
directories, they contain an already-compiled static library, one for each platform. Example: windows.0.48.0.lib file.
I couldn't find any documentation regarding this, but I suppose these static libraries are compiled from the C source files found in the baseline
directory, which contain... a duplication of the Windows API function declarations in C. That's intriguing.
The Rust bindings themselves are written somewhere else, like here (GDI bindings).
Question: these compiled C static libraries seem to be a duplication of the API already available in Windows, so why are they necessary?
I got a response by asking directly the official windows crate maintainers:
While the GNU and MSVC toolchains often provide some import libs to support C++ development, those lib files are often incomplete, missing, or just plain wrong. This can lead to linker errors that are very difficult to diagnose. The
windows-targets
crate ensures that all functions defined by thewindows
andwindows-sys
crates can be linked without relying on implicit lib files distributed by the toolchain.
For anyone interested, further details can be seen here.