vswhom_sys/
lib.rs

1//! Pure FFI to [Jon Blow's VS discovery script](https://pastebin.com/3YvWQa5c).
2//!
3//! The rest of this crate's documentation is copied borderline verbatim
4//! from the original C++ source code.
5//!
6//! HOW TO USE THIS CODE
7//!
8//! The purpose of this file is to find the folders that contain libraries
9//! you may need to link against, on Windows, if you are linking with any
10//! compiled C or C++ code. This will be necessary for many non-C++ programming
11//! language environments that want to provide compatibility.
12//!
13//! We find the place where the Visual Studio libraries live (for example,
14//! libvcruntime.lib), where the linker and compiler executables live
15//! (for example, link.exe), and where the Windows SDK libraries reside
16//! (kernel32.lib, libucrt.lib).
17//!
18//! We all wish you didn't have to worry about so many weird dependencies,
19//! but we don't really have a choice about this, sadly.
20//!
21//! I don't claim that this is the absolute best way to solve this problem,
22//! and so far we punt on things (if you have multiple versions of Visual Studio
23//! installed, we return the first one, rather than the newest). But it
24//! will solve the basic problem for you as simply as I know how to do it,
25//! and because there isn't too much code here, it's easy to modify and expand.
26//!
27//!
28//! Here is the API you need to know about:
29//!
30//! Call `vswhom_find_visual_studio_and_windows_sdk()`, look at the resulting
31//! paths, then call `vswhom_free_resources()` on the result.
32//!
33//!
34//! This file was about 400 lines before we started adding these comments.
35//! You might think that's way too much code to do something as simple
36//! as finding a few library and executable paths. I agree. However,
37//! Microsoft's own solution to this problem, called "vswhere", is a
38//! mere EIGHT THOUSAND LINE PROGRAM, spread across 70 files,
39//! that they posted to github *unironically*.
40//!
41//! I am not making this up: https://github.com/Microsoft/vswhere
42//!
43//! Several people have therefore found the need to solve this problem
44//! themselves. We referred to some of these other solutions when
45//! figuring out what to do, most prominently ziglang's version,
46//! by Ryan Saunderson.
47//!
48//! I hate this kind of code. The fact that we have to do this at all
49//! is stupid, and the actual maneuvers we need to go through
50//! are just painful. If programming were like this all the time,
51//! I would quit.
52//!
53//! One other shortcut I took is that this is hardcoded to return the
54//! folders for x64 libraries. If you want x86 or arm, you can make
55//! slight edits to the code below, or, if enough people want this,
56//! I can work it in here.
57
58
59extern crate libc;
60
61use libc::{wchar_t, c_int};
62
63
64#[repr(C)]
65pub struct Find_Result {
66    /// Zero if no Windows SDK found.
67    pub windows_sdk_version: c_int,
68
69    pub windows_sdk_root: *mut wchar_t,
70    pub windows_sdk_um_library_path: *mut wchar_t,
71    pub windows_sdk_ucrt_library_path: *mut wchar_t,
72
73    pub vs_exe_path: *mut wchar_t,
74    pub vs_library_path: *mut wchar_t,
75}
76
77extern "C" {
78    pub fn vswhom_find_visual_studio_and_windows_sdk() -> Find_Result;
79
80    pub fn vswhom_free_resources(result: *mut Find_Result);
81}