1 // Licensed under the Apache License, Version 2.0
2 // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
4 // All files in the project carrying such notice may not be copied, modified, or distributed
5 // except according to those terms.
6 use std::cell::Cell;
7 use std::collections::HashMap;
8 use std::env::var;
9 // (header name, &[header dependencies], &[library dependencies])
10 const DATA: &'static [(&'static str, &'static [&'static str], &'static [&'static str])] = &[
11     // km
12     ("d3dkmthk", &["basetsd", "d3dukmdt", "minwindef", "ntdef", "windef"], &[]),
13     // mmos
14     // shared
15     ("basetsd", &[], &[]),
16     ("bcrypt", &["minwindef", "winnt"], &["bcrypt"]),
17     ("bthdef", &["bthsdpdef", "guiddef", "minwindef", "ntdef"], &[]),
18     ("bthioctl", &["bthdef", "bthsdpdef", "minwindef", "ntdef", "winioctl"], &[]),
19     ("bthsdpdef", &["guiddef", "minwindef", "ntdef"], &[]),
20     ("bugcodes", &["ntdef"], &[]),
21     ("cderr", &["minwindef"], &[]),
22     ("cfg", &["minwindef"], &[]),
23     ("d3d9", &["basetsd", "d3d9caps", "d3d9types", "guiddef", "minwindef", "unknwnbase", "windef", "wingdi", "winnt"], &["d3d9"]),
24     ("d3d9caps", &["d3d9types", "guiddef", "minwindef", "winnt"], &[]),
25     ("d3d9types", &["basetsd", "guiddef", "minwindef", "windef", "winnt"], &[]),
26     ("d3dkmdt", &["basetsd", "minwindef", "ntdef"], &[]),
27     ("d3dukmdt", &["basetsd", "guiddef", "minwindef", "ntdef"], &[]),
28     ("dcomptypes", &["dxgitype", "minwindef", "winnt"], &[]),
29     ("devguid", &[], &[]),
30     ("devpkey", &["devpropdef"], &[]),
31     ("devpropdef", &["guiddef", "minwindef", "winnt"], &[]),
32     ("dinputd", &[], &[]),
33     ("dxgi", &["basetsd", "dxgiformat", "dxgitype", "guiddef", "minwindef", "unknwnbase", "windef", "winnt"], &["dxgi"]),
34     ("dxgi1_2", &["basetsd", "dxgi", "dxgiformat", "dxgitype", "guiddef", "minwinbase", "minwindef", "unknwnbase", "windef", "winnt"], &[]),
35     ("dxgi1_3", &["dxgi", "dxgi1_2", "dxgiformat", "guiddef", "minwindef", "unknwnbase", "windef", "winnt"], &["dxgi"]),
36     ("dxgi1_4", &["basetsd", "dxgi1_2", "dxgi1_3", "dxgiformat", "dxgitype", "guiddef", "minwindef", "unknwnbase", "winnt"], &[]),
37     ("dxgi1_5", &["basetsd", "dxgi", "dxgi1_2", "dxgi1_3", "dxgi1_4", "dxgiformat", "minwindef", "unknwnbase", "winnt"], &[]),
38     ("dxgi1_6", &["basetsd", "dxgi1_2", "dxgi1_4", "dxgi1_5", "dxgitype", "guiddef", "minwindef", "windef", "winnt"], &[]),
39     ("dxgiformat", &[], &[]),
40     ("dxgitype", &["d3d9types", "dxgiformat", "minwindef"], &[]),
41     ("enclaveapi", &["basetsd", "minwinbase", "minwindef", "ntdef", "winnt"], &["kernel32"]),
42     ("evntprov", &["basetsd", "guiddef", "minwindef", "winnt"], &["advapi32"]),
43     ("evntrace", &["basetsd", "evntcons", "evntprov", "guiddef", "handleapi", "minwindef", "timezoneapi", "vadefs", "winnt", "wmistr"], &["advapi32"]),
44     ("guiddef", &[], &[]),
45     ("hidclass", &["guiddef", "minwindef", "winioctl", "winnt"], &[]),
46     ("hidpi", &["hidusage", "minwindef", "ntdef", "ntstatus", "winnt"], &["hid"]),
47     ("hidsdi", &["guiddef", "hidpi", "minwindef", "winnt"], &["hid"]),
48     ("hidusage", &["minwindef"], &[]),
49     ("ifdef", &["basetsd", "guiddef", "ntdef"], &[]),
50     ("ifmib", &["ifdef", "ipifcons", "minwindef", "ntdef"], &[]),
51     ("in6addr", &["minwindef"], &[]),
52     ("inaddr", &["minwindef"], &[]),
53     ("intsafe", &[], &[]),
54     ("ipifcons", &["minwindef"], &[]),
55     ("ipmib", &["ifdef", "ifmib", "minwindef", "nldef", "ntdef"], &[]),
56     ("iprtrmib", &["ipmib", "minwindef", "ntdef"], &[]),
57     ("ks", &[], &[]),
58     ("ksmedia", &["minwindef"], &[]),
59     ("ktmtypes", &["guiddef", "minwindef", "winnt"], &[]),
60     ("lmcons", &["minwindef", "winnt"], &[]),
61     ("minwindef", &["basetsd", "ntdef"], &[]),
62     ("mmreg", &["guiddef", "minwindef"], &[]),
63     ("mprapidef", &[], &[]),
64     ("mstcpip", &["basetsd", "guiddef", "in6addr", "inaddr", "minwindef", "winnt", "ws2def"], &["ntdll"]),
65     ("mswsockdef", &["minwindef", "winnt", "ws2def"], &[]),
66     ("netioapi", &["basetsd", "guiddef", "ifdef", "ipifcons", "minwindef", "nldef", "ntddndis", "ntdef", "ws2def", "ws2ipdef"], &["iphlpapi"]),
67     ("nldef", &["basetsd", "minwindef", "ntdef"], &[]),
68     ("ntddndis", &["ifdef", "minwindef"], &[]),
69     ("ntddscsi", &["basetsd", "minwindef", "ntdef", "winioctl", "winnt"], &[]),
70     ("ntddser", &["devpropdef"], &[]),
71     ("ntdef", &["basetsd", "guiddef"], &[]),
72     ("ntstatus", &["ntdef"], &[]),
73     ("qos", &["minwindef"], &[]),
74     ("rpc", &[], &[]),
75     ("rpcdce", &["guiddef", "minwindef", "rpc"], &[]),
76     ("rpcndr", &[], &[]),
77     ("sddl", &["basetsd", "minwindef", "winnt"], &["advapi32"]),
78     ("sspi", &["basetsd", "guiddef", "minwindef", "subauth", "wincred", "winnt"], &["credui", "secur32"]),
79     ("stralign", &["vcruntime", "winnt"], &["kernel32"]),
80     ("tcpestats", &["basetsd", "ntdef"], &[]),
81     ("tcpmib", &["basetsd", "in6addr", "minwindef", "ntdef"], &[]),
82     ("transportsettingcommon", &["guiddef"], &[]),
83     ("tvout", &["guiddef", "minwindef"], &[]),
84     ("udpmib", &["basetsd", "in6addr", "minwindef", "ntdef"], &[]),
85     ("usb", &["minwindef", "usbspec", "winnt"], &[]),
86     ("usbioctl", &["basetsd", "guiddef", "minwindef", "ntdef", "usb", "usbiodef", "usbspec", "winioctl"], &[]),
87     ("usbiodef", &["guiddef", "minwindef", "winioctl", "winnt"], &[]),
88     ("usbscan", &["ntdef", "winioctl"], &[]),
89     ("usbspec", &["basetsd", "guiddef", "minwindef", "winnt"], &[]),
90     ("windef", &["minwindef", "winnt"], &[]),
91     ("windot11", &["basetsd", "minwindef", "ntddndis", "winnt", "wlantypes"], &[]),
92     ("windowsx", &["minwindef"], &[]),
93     ("winerror", &["minwindef", "wtypesbase"], &[]),
94     ("winusbio", &["minwindef", "usb"], &[]),
95     ("wlantypes", &["basetsd", "minwindef"], &[]),
96     ("wmistr", &["basetsd", "guiddef", "minwindef", "winnt"], &[]),
97     ("wnnc", &["minwindef"], &[]),
98     ("ws2def", &["basetsd", "guiddef", "inaddr", "minwindef", "vcruntime", "winnt"], &[]),
99     ("ws2ipdef", &["in6addr", "inaddr", "minwindef", "ws2def"], &[]),
100     ("wtypes", &["guiddef", "minwindef", "ntdef", "rpcndr", "wingdi", "wtypesbase"], &[]),
101     ("wtypesbase", &["minwindef", "rpcndr", "winnt"], &[]),
102     // ucrt
103     ("corecrt", &[], &[]),
104     // um
105     ("accctrl", &["guiddef", "minwindef", "winbase", "winnt"], &[]),
106     ("aclapi", &["accctrl", "guiddef", "minwindef", "winnt"], &["advapi32"]),
107     ("adhoc", &["guiddef", "minwindef", "unknwnbase", "winnt"], &[]),
108     ("appmgmt", &["guiddef", "minwindef", "winnt"], &["advapi32"]),
109     ("audioclient", &["audiosessiontypes", "basetsd", "guiddef", "minwindef", "mmreg", "strmif", "unknwnbase", "winerror", "winnt", "wtypesbase"], &[]),
110     ("audiosessiontypes", &["minwindef"], &[]),
111     ("avrt", &["guiddef", "minwindef", "winnt"], &["avrt"]),
112     ("bits", &["basetsd", "guiddef", "minwindef", "unknwnbase", "winnt"], &[]),
113     ("bits10_1", &["basetsd", "bits", "bits2_0", "bits3_0", "bits5_0", "minwindef", "winnt"], &[]),
114     ("bits1_5", &["basetsd", "bits", "rpcndr", "winnt"], &[]),
115     ("bits2_0", &["basetsd", "bits", "bits1_5", "minwindef", "winnt"], &[]),
116     ("bits2_5", &["minwindef", "rpcndr", "unknwnbase", "winnt"], &[]),
117     ("bits3_0", &["basetsd", "bits", "bits2_0", "guiddef", "minwindef", "unknwnbase", "winnt"], &[]),
118     ("bits4_0", &["basetsd", "bits3_0", "minwindef", "unknwnbase", "winnt"], &[]),
119     ("bits5_0", &["basetsd", "bits1_5", "bits3_0", "bits4_0", "guiddef", "minwindef", "winnt"], &[]),
120     ("bitscfg", &["guiddef", "oaidl", "unknwnbase", "winnt", "wtypes"], &["oleaut32"]),
121     ("bitsmsg", &["minwindef"], &[]),
122     ("bluetoothapis", &["bthdef", "bthsdpdef", "guiddef", "minwinbase", "minwindef", "windef", "winnt"], &["bthprops"]),
123     ("bluetoothleapis", &["bthledef", "minwindef", "winerror", "winnt"], &["bluetoothapis"]),
124     ("bthledef", &["basetsd", "guiddef", "minwindef", "winnt"], &[]),
125     ("cfgmgr32", &["basetsd", "cfg", "devpropdef", "guiddef", "minwindef", "winnt", "winreg"], &["cfgmgr32"]),
126     ("cguid", &[], &[]),
127     ("combaseapi", &["basetsd", "guiddef", "minwindef", "objidl", "objidlbase", "propidl", "rpcdce", "unknwnbase", "winnt", "wtypesbase"], &["ole32"]),
128     ("coml2api", &["minwindef"], &[]),
129     ("commapi", &["minwinbase", "minwindef", "winbase", "winnt"], &["kernel32"]),
130     ("commctrl", &["basetsd", "commoncontrols", "guiddef", "minwinbase", "minwindef", "vcruntime", "windef", "winnt", "winuser"], &["comctl32"]),
131     ("commdlg", &["basetsd", "minwindef", "prsht", "unknwnbase", "windef", "wingdi", "winnt", "winuser"], &["comdlg32"]),
132     ("commoncontrols", &["commctrl", "guiddef", "minwindef", "unknwnbase", "windef", "winnt"], &["comctl32"]),
133     ("consoleapi", &["minwindef", "wincon", "wincontypes", "winnt"], &["kernel32"]),
134     ("corsym", &["basetsd", "objidlbase", "unknwnbase", "winnt"], &[]),
135     ("d2d1", &["basetsd", "d2dbasetypes", "d3dcommon", "dcommon", "dwrite", "dxgi", "guiddef", "minwindef", "unknwnbase", "wincodec", "windef", "winnt"], &["d2d1"]),
136     ("d2d1_1", &["basetsd", "d2d1", "d2d1effectauthor", "d2dbasetypes", "dcommon", "documenttarget", "dwrite", "dxgi", "dxgiformat", "guiddef", "minwindef", "objidlbase", "unknwnbase", "wincodec", "winnt"], &["d2d1"]),
137     ("d2d1_2", &["d2d1", "d2d1_1", "dxgi", "minwindef", "winnt"], &["d2d1"]),
138     ("d2d1_3", &["basetsd", "d2d1", "d2d1_1", "d2d1_2", "d2d1effects", "d2d1svg", "dcommon", "dwrite", "dxgi", "dxgitype", "minwindef", "ntdef", "objidlbase", "wincodec", "winerror"], &["d2d1"]),
139     ("d2d1effectauthor", &["basetsd", "d2d1", "d2d1_1", "d2dbasetypes", "d3dcommon", "dxgiformat", "guiddef", "minwindef", "ntdef", "unknwnbase", "wincodec"], &[]),
140     ("d2d1effects", &[], &[]),
141     ("d2d1effects_1", &[], &[]),
142     ("d2d1effects_2", &[], &[]),
143     ("d2d1svg", &["basetsd", "d2d1", "d2d1_1", "guiddef", "minwindef", "ntdef", "objidlbase", "winerror"], &[]),
144     ("d2dbasetypes", &["d3d9types", "dcommon"], &[]),
145     ("d3d", &[], &[]),
146     ("d3d10", &["d3dcommon"], &[]),
147     ("d3d10_1", &[], &[]),
148     ("d3d10_1shader", &[], &[]),
149     ("d3d10effect", &[], &[]),
150     ("d3d10misc", &[], &[]),
151     ("d3d10sdklayers", &[], &[]),
152     ("d3d10shader", &["d3d10", "d3dcommon", "minwindef", "unknwnbase", "winnt"], &[]),
153     ("d3d11", &["basetsd", "d3dcommon", "dxgi", "dxgiformat", "dxgitype", "guiddef", "minwindef", "unknwnbase", "windef", "winnt"], &["d3d11"]),
154     ("d3d11_1", &["basetsd", "d3d11", "d3dcommon", "dxgiformat", "dxgitype", "guiddef", "minwindef", "unknwnbase", "winnt"], &[]),
155     ("d3d11_2", &["basetsd", "d3d11", "d3d11_1", "dxgiformat", "minwindef", "winnt"], &[]),
156     ("d3d11_3", &[], &[]),
157     ("d3d11_4", &[], &[]),
158     ("d3d11on12", &["d3d11", "d3d12", "d3dcommon", "guiddef", "minwindef", "unknwnbase", "winnt"], &["d3d11"]),
159     ("d3d11sdklayers", &["basetsd", "d3d11", "dxgi", "minwindef", "unknwnbase", "winnt"], &[]),
160     ("d3d11shader", &["basetsd", "d3dcommon", "minwindef", "unknwnbase", "winnt"], &[]),
161     ("d3d11tokenizedprogramformat", &["minwindef"], &[]),
162     ("d3d12", &["basetsd", "d3dcommon", "dxgiformat", "dxgitype", "guiddef", "minwinbase", "minwindef", "unknwnbase", "windef", "winnt"], &["d3d12"]),
163     ("d3d12sdklayers", &["basetsd", "d3d12", "minwindef", "unknwnbase", "winnt"], &[]),
164     ("d3d12shader", &["basetsd", "d3dcommon", "minwindef", "unknwnbase", "winnt"], &[]),
165     ("d3dcommon", &["basetsd", "minwindef", "unknwnbase", "winnt"], &[]),
166     ("d3dcompiler", &["basetsd", "d3d11shader", "d3dcommon", "guiddef", "minwindef", "winnt"], &["d3dcompiler"]),
167     ("d3dcsx", &[], &[]),
168     ("d3dx10core", &[], &[]),
169     ("d3dx10math", &[], &[]),
170     ("d3dx10mesh", &[], &[]),
171     ("datetimeapi", &["minwinbase", "minwindef", "winnt"], &["kernel32"]),
172     ("davclnt", &["minwindef", "winnt"], &["netapi32"]),
173     ("dbghelp", &["basetsd", "guiddef", "minwindef", "vcruntime", "winnt"], &["dbghelp"]),
174     ("dbt", &["basetsd", "guiddef", "minwindef", "winnt", "winuser"], &[]),
175     ("dcommon", &["basetsd", "dxgiformat", "minwindef", "windef"], &[]),
176     ("dcomp", &["d2d1", "d2d1_1", "d2d1effects", "d2dbasetypes", "d3d9types", "d3dcommon", "dcompanimation", "dcomptypes", "dxgi", "dxgi1_2", "dxgiformat", "guiddef", "minwinbase", "minwindef", "ntdef", "unknwnbase", "windef"], &["dcomp"]),
177     ("dcompanimation", &["ntdef", "unknwnbase"], &[]),
178     ("dde", &["basetsd", "minwindef"], &["user32"]),
179     ("ddraw", &[], &[]),
180     ("ddrawi", &[], &[]),
181     ("ddrawint", &[], &[]),
182     ("debugapi", &["minwinbase", "minwindef", "winnt"], &["kernel32"]),
183     ("devicetopology", &["guiddef", "minwindef", "unknwnbase", "windef", "winnt", "wtypes"], &[]),
184     ("dinput", &[], &[]),
185     ("dispex", &["basetsd", "guiddef", "minwindef", "oaidl", "servprov", "unknwnbase", "winerror", "winnt", "wtypes"], &[]),
186     ("dmksctl", &[], &[]),
187     ("dmusicc", &[], &[]),
188     ("docobj", &["guiddef", "minwindef", "oaidl", "unknwnbase", "winnt"], &[]),
189     ("documenttarget", &["basetsd", "guiddef", "ntdef", "unknwnbase"], &[]),
190     ("dot1x", &["eaptypes", "guiddef", "l2cmn", "minwindef", "winnt"], &[]),
191     ("dpa_dsa", &["basetsd", "minwindef", "winnt"], &["comctl32"]),
192     ("dpapi", &["minwindef", "wincrypt", "windef", "winnt"], &["crypt32"]),
193     ("dsgetdc", &["guiddef", "minwindef", "ntsecapi", "winnt", "ws2def"], &["netapi32"]),
194     ("dsound", &["guiddef", "minwindef", "mmsystem", "unknwnbase", "windef", "winerror", "winnt"], &["dsound"]),
195     ("dsrole", &["guiddef", "minwindef", "winnt"], &["netapi32"]),
196     ("dvp", &[], &[]),
197     ("dwmapi", &["basetsd", "minwindef", "uxtheme", "windef", "winnt"], &["dwmapi"]),
198     ("dwrite", &["basetsd", "d2d1", "dcommon", "guiddef", "minwindef", "unknwnbase", "windef", "winerror", "wingdi", "winnt"], &["dwrite"]),
199     ("dwrite_1", &["basetsd", "dcommon", "dwrite", "minwindef", "winnt"], &[]),
200     ("dwrite_2", &["basetsd", "d3d9types", "dcommon", "dwrite", "dwrite_1", "minwindef", "unknwnbase", "winnt"], &[]),
201     ("dwrite_3", &["basetsd", "dcommon", "dwrite", "dwrite_1", "dwrite_2", "minwindef", "unknwnbase", "wingdi", "winnt"], &[]),
202     ("dxdiag", &[], &[]),
203     ("dxfile", &[], &[]),
204     ("dxgidebug", &["basetsd", "guiddef", "minwindef", "unknwnbase", "winnt"], &["dxgi"]),
205     ("dxva2api", &["basetsd", "d3d9", "d3d9types", "guiddef", "minwindef", "unknwnbase", "windef", "winnt"], &["dxva2"]),
206     ("dxvahd", &["d3d9", "d3d9types", "guiddef", "minwindef", "unknwnbase", "windef", "winnt"], &["dxva2"]),
207     ("eaptypes", &["guiddef", "minwindef", "winnt"], &[]),
208     ("endpointvolume", &["basetsd", "guiddef", "minwindef", "unknwnbase", "winnt"], &[]),
209     ("errhandlingapi", &["basetsd", "minwindef", "winnt"], &["kernel32"]),
210     ("evntcons", &["basetsd", "evntprov", "evntrace", "guiddef", "minwindef", "winnt"], &["advapi32"]),
211     ("exdisp", &["basetsd", "docobj", "oaidl", "ocidl", "winnt", "wtypes"], &[]),
212     ("fibersapi", &["minwindef", "winnt"], &["kernel32"]),
213     ("fileapi", &["minwinbase", "minwindef", "winnt"], &["kernel32"]),
214     ("functiondiscoverykeys_devpkey", &["wtypes"], &[]),
215     ("gl-gl", &[], &["opengl32"]),
216     ("handleapi", &["minwindef", "winnt"], &["kernel32"]),
217     ("heapapi", &["basetsd", "minwinbase", "minwindef", "winnt"], &["kernel32"]),
218     ("highlevelmonitorconfigurationapi", &["minwindef", "physicalmonitorenumerationapi", "winnt"], &["dxva2"]),
219     ("http", &["guiddef", "minwinbase", "minwindef", "sspi", "winnt", "ws2def"], &["httpapi"]),
220     ("imm", &["minwindef", "windef"], &["imm32"]),
221     ("interlockedapi", &["minwindef", "winnt"], &["kernel32"]),
222     ("ioapiset", &["basetsd", "minwinbase", "minwindef", "winnt"], &["kernel32"]),
223     ("ipexport", &["basetsd", "in6addr", "ntdef"], &[]),
224     ("iphlpapi", &["basetsd", "ifdef", "ifmib", "ipexport", "ipmib", "iprtrmib", "iptypes", "minwinbase", "minwindef", "ntdef", "tcpestats", "tcpmib", "udpmib", "ws2def", "ws2ipdef"], &["iphlpapi"]),
225     ("iptypes", &["basetsd", "corecrt", "guiddef", "ifdef", "ipifcons", "minwindef", "nldef", "ntdef", "ws2def"], &[]),
226     ("jobapi", &["minwindef", "winnt"], &["kernel32"]),
227     ("jobapi2", &["basetsd", "minwinbase", "minwindef", "ntdef", "winnt"], &["kernel32"]),
228     ("knownfolders", &[], &[]),
229     ("ktmw32", &["guiddef", "minwinbase", "minwindef", "winnt"], &["ktmw32"]),
230     ("l2cmn", &["guiddef", "minwindef", "winnt"], &[]),
231     ("libloaderapi", &["basetsd", "minwindef", "winnt"], &["kernel32", "user32"]),
232     ("lmaccess", &["basetsd", "lmcons", "minwindef", "winnt"], &["netapi32"]),
233     ("lmalert", &["lmcons", "minwindef", "winnt"], &["netapi32"]),
234     ("lmapibuf", &["lmcons", "minwindef"], &["netapi32"]),
235     ("lmat", &["basetsd", "lmcons", "minwindef", "winnt"], &["netapi32"]),
236     ("lmdfs", &["guiddef", "lmcons", "minwindef", "winnt"], &["netapi32"]),
237     ("lmerrlog", &["minwindef", "winnt"], &[]),
238     ("lmjoin", &["lmcons", "minwindef", "wincrypt", "winnt"], &["netapi32"]),
239     ("lmmsg", &["lmcons", "minwindef", "winnt"], &["netapi32"]),
240     ("lmremutl", &["lmcons", "minwindef", "winnt"], &["netapi32"]),
241     ("lmrepl", &["lmcons", "minwindef", "winnt"], &["netapi32"]),
242     ("lmserver", &["guiddef", "lmcons", "minwindef", "winnt", "winsvc"], &["advapi32", "netapi32"]),
243     ("lmshare", &["basetsd", "guiddef", "lmcons", "minwindef", "winnt"], &["netapi32"]),
244     ("lmstats", &["lmcons", "minwindef", "winnt"], &["netapi32"]),
245     ("lmsvc", &["lmcons", "minwindef", "winnt"], &["netapi32"]),
246     ("lmuse", &["lmcons", "minwindef", "winnt"], &["netapi32"]),
247     ("lmwksta", &["lmcons", "minwindef", "winnt"], &["netapi32"]),
248     ("lowlevelmonitorconfigurationapi", &["minwindef", "physicalmonitorenumerationapi", "winnt"], &["dxva2"]),
249     ("lsalookup", &["guiddef", "minwindef", "ntdef", "winnt"], &["advapi32"]),
250     ("memoryapi", &["basetsd", "minwinbase", "minwindef", "winnt"], &["kernel32"]),
251     ("minschannel", &["guiddef", "minwindef", "wincrypt", "winnt"], &[]),
252     ("minwinbase", &["basetsd", "minwindef", "ntstatus", "winnt"], &[]),
253     ("mmdeviceapi", &["guiddef", "minwindef", "propidl", "propsys", "unknwnbase", "winnt", "wtypes"], &["mmdevapi"]),
254     ("mmeapi", &["basetsd", "imm", "minwindef", "mmsystem", "winnt"], &["winmm"]),
255     ("mmsystem", &["basetsd", "minwindef", "mmreg", "winnt"], &[]),
256     ("msaatext", &[], &[]),
257     ("mscat", &["guiddef", "minwindef", "mssip", "wincrypt", "winnt"], &[]),
258     ("mschapp", &["basetsd", "minwindef", "winnt"], &["advapi32"]),
259     ("mssip", &["guiddef", "minwindef", "mscat", "wincrypt", "winnt"], &["crypt32"]),
260     ("mswsock", &["minwinbase", "minwindef", "mswsockdef", "winnt", "winsock2", "ws2def"], &["mswsock"]),
261     ("namedpipeapi", &["minwinbase", "minwindef", "winnt"], &["advapi32", "kernel32"]),
262     ("namespaceapi", &["minwinbase", "minwindef", "ntdef", "winnt"], &["kernel32"]),
263     ("nb30", &["minwindef", "winnt"], &["netapi32"]),
264     ("ncrypt", &["basetsd", "bcrypt", "minwindef", "winnt"], &["ncrypt"]),
265     ("ntlsa", &["basetsd", "guiddef", "lsalookup", "minwindef", "ntdef", "ntsecapi", "subauth", "winnt"], &["advapi32"]),
266     ("ntsecapi", &["basetsd", "guiddef", "lsalookup", "minwindef", "ntdef", "sspi", "subauth", "winnt"], &["advapi32"]),
267     ("oaidl", &["basetsd", "guiddef", "minwindef", "rpcndr", "unknwnbase", "winnt", "wtypes", "wtypesbase"], &[]),
268     ("objbase", &["combaseapi", "minwindef", "winnt"], &["ole32"]),
269     ("objidl", &["basetsd", "guiddef", "minwindef", "ntdef", "objidlbase", "unknwnbase", "windef", "winnt", "wtypes", "wtypesbase"], &[]),
270     ("objidlbase", &["basetsd", "guiddef", "minwindef", "unknwnbase", "winnt", "wtypesbase"], &[]),
271     ("ocidl", &["guiddef", "minwindef", "ntdef", "oaidl", "unknwnbase", "wtypes", "wtypesbase"], &[]),
272     ("ole2", &["minwindef", "oleidl", "windef", "winnt"], &["ole32"]),
273     ("oleauto", &["basetsd", "minwinbase", "minwindef", "oaidl", "winnt", "wtypes", "wtypesbase"], &["oleaut32"]),
274     ("olectl", &["winerror", "winnt"], &[]),
275     ("oleidl", &["minwindef", "ntdef", "objidl", "unknwnbase", "windef"], &[]),
276     ("opmapi", &["basetsd", "d3d9", "d3d9types", "dxva2api", "guiddef", "minwindef", "unknwnbase", "windef", "winnt"], &["dxva2"]),
277     ("pdh", &["basetsd", "guiddef", "minwindef", "windef", "winnt"], &["pdh"]),
278     ("perflib", &["basetsd", "guiddef", "minwinbase", "minwindef", "winnt"], &["advapi32"]),
279     ("physicalmonitorenumerationapi", &["d3d9", "minwindef", "windef", "winnt"], &["dxva2"]),
280     ("playsoundapi", &["minwindef", "winnt"], &["winmm"]),
281     ("portabledevice", &["basetsd", "wtypes"], &[]),
282     ("portabledeviceapi", &["guiddef", "minwindef", "objidlbase", "portabledevicetypes", "propkeydef", "unknwnbase", "winnt"], &[]),
283     ("portabledevicetypes", &["guiddef", "minwindef", "propidl", "propkeydef", "propsys", "unknwnbase", "winnt", "wtypes"], &[]),
284     ("powerbase", &["minwindef", "winnt", "winuser"], &["powrprof"]),
285     ("powersetting", &["guiddef", "minwindef", "winnt", "winuser"], &["powrprof"]),
286     ("powrprof", &["guiddef", "minwindef", "winnt", "winreg"], &["powrprof"]),
287     ("processenv", &["minwindef", "winnt"], &["kernel32"]),
288     ("processsnapshot", &["basetsd", "minwindef", "winnt"], &["kernel32"]),
289     ("processthreadsapi", &["basetsd", "guiddef", "minwinbase", "minwindef", "winnt"], &["advapi32", "kernel32"]),
290     ("processtopologyapi", &["minwindef", "winnt"], &["kernel32"]),
291     ("profileapi", &["minwindef", "winnt"], &["kernel32"]),
292     ("propidl", &["guiddef", "minwindef", "ntdef", "oaidl", "objidlbase", "unknwnbase", "wtypes", "wtypesbase"], &["ole32"]),
293     ("propkey", &["minwindef", "ntdef", "wtypes"], &[]),
294     ("propkeydef", &["guiddef", "wtypes"], &[]),
295     ("propsys", &["minwindef", "propidl", "propkeydef", "unknwnbase", "winnt", "wtypes"], &[]),
296     ("prsht", &["basetsd", "minwindef", "windef", "winnt", "winuser"], &["comctl32"]),
297     ("psapi", &["basetsd", "minwindef", "winnt"], &["kernel32", "psapi"]),
298     ("realtimeapiset", &["basetsd", "minwindef", "winnt"], &["kernel32"]),
299     ("reason", &["minwindef"], &[]),
300     ("restartmanager", &["minwindef", "winnt"], &["rstrtmgr"]),
301     ("restrictederrorinfo", &["unknwnbase", "winnt", "wtypes"], &[]),
302     ("rmxfguid", &[], &[]),
303     ("rtinfo", &["basetsd"], &[]),
304     ("sapi", &["guiddef", "minwindef", "sapi53", "unknwnbase", "winnt"], &[]),
305     ("sapi51", &["guiddef", "minwindef", "mmreg", "oaidl", "objidlbase", "rpcndr", "servprov", "unknwnbase", "windef", "winnt", "wtypes", "wtypesbase"], &[]),
306     ("sapi53", &["guiddef", "minwindef", "oaidl", "sapi51", "unknwnbase", "urlmon", "winnt", "wtypes"], &[]),
307     ("sapiddk", &["guiddef", "minwindef", "sapi", "sapiddk51", "unknwnbase", "winnt"], &[]),
308     ("sapiddk51", &["guiddef", "minwindef", "mmreg", "oaidl", "objidlbase", "sapi", "unknwnbase", "windef", "winnt"], &[]),
309     ("schannel", &["guiddef", "minwindef", "wincrypt", "windef", "winnt"], &[]),
310     ("securityappcontainer", &["minwindef", "winnt"], &["kernel32"]),
311     ("securitybaseapi", &["guiddef", "minwinbase", "minwindef", "winnt"], &["advapi32", "kernel32"]),
312     ("servprov", &["guiddef", "unknwnbase", "winnt"], &[]),
313     ("setupapi", &["basetsd", "commctrl", "devpropdef", "guiddef", "minwindef", "prsht", "spapidef", "windef", "winnt", "winreg"], &["setupapi"]),
314     ("shellapi", &["basetsd", "guiddef", "minwinbase", "minwindef", "processthreadsapi", "windef", "winnt", "winuser"], &["shell32", "shlwapi"]),
315     ("shellscalingapi", &["minwindef", "windef", "winnt"], &["shcore"]),
316     ("shlobj", &["guiddef", "minwinbase", "minwindef", "shtypes", "windef", "winnt"], &["shell32"]),
317     ("shobjidl", &["guiddef", "minwindef", "propsys", "shobjidl_core", "shtypes", "unknwnbase", "windef", "winnt"], &[]),
318     ("shobjidl_core", &["commctrl", "guiddef", "minwinbase", "minwindef", "objidl", "propkeydef", "propsys", "shtypes", "unknwnbase", "windef", "winnt"], &[]),
319     ("shtypes", &["guiddef", "minwindef", "winnt"], &[]),
320     ("softpub", &[], &[]),
321     ("spapidef", &["minwindef", "winnt"], &[]),
322     ("spellcheck", &["minwindef", "ntdef", "objidlbase", "unknwnbase", "winerror"], &[]),
323     ("sporder", &["guiddef", "minwindef"], &["sporder"]),
324     ("sql", &["sqltypes"], &["odbc32"]),
325     ("sqlext", &["sql", "sqltypes"], &[]),
326     ("sqltypes", &["basetsd", "guiddef", "windef"], &[]),
327     ("sqlucode", &["sqltypes"], &["odbc32"]),
328     ("stringapiset", &["minwindef", "winnls", "winnt"], &["kernel32"]),
329     ("strmif", &["winnt"], &[]),
330     ("subauth", &["minwindef", "winnt"], &[]),
331     ("synchapi", &["basetsd", "minwinbase", "minwindef", "winnt"], &["kernel32", "synchronization"]),
332     ("sysinfoapi", &["basetsd", "minwinbase", "minwindef", "winnt"], &["kernel32"]),
333     ("systemtopologyapi", &["minwindef", "winnt"], &["kernel32"]),
334     ("taskschd", &["minwinbase", "minwindef", "oaidl", "unknwnbase", "winnt", "wtypes"], &[]),
335     ("textstor", &[], &[]),
336     ("threadpoolapiset", &["basetsd", "minwinbase", "minwindef", "winnt"], &["kernel32"]),
337     ("threadpoollegacyapiset", &["minwinbase", "minwindef", "winnt"], &["kernel32"]),
338     ("timeapi", &["minwindef", "mmsystem"], &["winmm"]),
339     ("timezoneapi", &["minwinbase", "minwindef", "winnt"], &["advapi32", "kernel32"]),
340     ("tlhelp32", &["basetsd", "minwindef", "winnt"], &["kernel32"]),
341     ("unknwnbase", &["guiddef", "minwindef", "winnt"], &[]),
342     ("urlhist", &["docobj", "guiddef", "minwindef", "unknwnbase", "winnt", "wtypesbase"], &[]),
343     ("urlmon", &["minwindef", "unknwnbase", "winnt"], &[]),
344     ("userenv", &["minwindef", "winnt", "winreg"], &["userenv"]),
345     ("usp10", &["minwindef", "ntdef", "windef", "winerror", "wingdi", "winnt"], &["usp10"]),
346     ("utilapiset", &["minwindef", "ntdef"], &["kernel32"]),
347     ("uxtheme", &["commctrl", "minwindef", "windef", "wingdi", "winnt"], &["uxtheme"]),
348     ("vsbackup", &["guiddef", "minwindef", "unknwnbase", "vss", "vswriter", "winnt", "wtypes"], &["vssapi"]),
349     ("vss", &["guiddef", "minwindef", "unknwnbase", "winnt"], &[]),
350     ("vsserror", &["winnt"], &[]),
351     ("vswriter", &["minwindef", "unknwnbase", "vss", "winnt", "wtypes"], &[]),
352     ("wbemads", &["oaidl", "wbemdisp", "winerror", "wtypes"], &[]),
353     ("wbemcli", &["minwindef", "oaidl", "rpcndr", "unknwnbase", "winerror", "winnt", "wtypes"], &[]),
354     ("wbemdisp", &["oaidl", "unknwnbase", "winerror", "wtypes"], &[]),
355     ("wbemprov", &["minwindef", "oaidl", "unknwnbase", "wbemcli", "winerror", "winnt", "wtypes"], &[]),
356     ("wbemtran", &["guiddef", "minwindef", "unknwnbase", "wbemcli", "winerror", "winnt", "wtypes"], &[]),
357     ("wct", &["basetsd", "guiddef", "minwindef", "winnt"], &["advapi32"]),
358     ("werapi", &["minwindef", "winnt"], &["kernel32", "wer"]),
359     ("winbase", &["basetsd", "cfgmgr32", "fileapi", "guiddef", "libloaderapi", "minwinbase", "minwindef", "processthreadsapi", "vadefs", "windef", "winnt"], &["kernel32"]),
360     ("wincodec", &["basetsd", "d2d1", "d2d1_1", "dcommon", "dxgiformat", "dxgitype", "guiddef", "minwindef", "ntdef", "objidlbase", "ocidl", "propidl", "unknwnbase", "windef", "winerror", "winnt"], &["windowscodecs"]),
361     ("wincodecsdk", &["guiddef", "minwindef", "oaidl", "objidl", "objidlbase", "ocidl", "propidl", "unknwnbase", "wincodec", "winnt", "wtypes"], &["ole32", "oleaut32", "windowscodecs"]),
362     ("wincon", &["minwinbase", "minwindef", "wincontypes", "windef", "wingdi", "winnt"], &["kernel32"]),
363     ("wincontypes", &["minwindef", "winnt"], &[]),
364     ("wincred", &["minwindef", "sspi", "windef", "winnt"], &["advapi32", "credui"]),
365     ("wincrypt", &["basetsd", "bcrypt", "guiddef", "minwinbase", "minwindef", "ncrypt", "vcruntime", "winnt"], &["advapi32", "crypt32", "cryptnet"]),
366     ("windowsceip", &["minwindef"], &["kernel32"]),
367     ("winefs", &["basetsd", "minwinbase", "minwindef", "wincrypt", "winnt"], &["advapi32"]),
368     ("winevt", &["basetsd", "guiddef", "minwinbase", "minwindef", "vcruntime", "winnt"], &["wevtapi"]),
369     ("wingdi", &["basetsd", "minwindef", "windef", "winnt"], &["gdi32", "msimg32", "opengl32", "winspool"]),
370     ("winhttp", &["basetsd", "minwinbase", "minwindef", "winnt"], &["winhttp"]),
371     ("wininet", &["basetsd", "minwinbase", "minwindef", "ntdef", "windef", "winineti", "winnt"], &["wininet"]),
372     ("winineti", &["minwindef"], &[]),
373     ("winioctl", &["basetsd", "devpropdef", "guiddef", "minwindef", "winnt"], &[]),
374     ("winnetwk", &["basetsd", "minwindef", "windef", "winerror", "winnt"], &["mpr"]),
375     ("winnls", &["basetsd", "guiddef", "minwinbase", "minwindef", "winnt"], &["kernel32"]),
376     ("winnt", &["basetsd", "excpt", "guiddef", "ktmtypes", "minwindef", "ntdef", "vcruntime"], &["kernel32"]),
377     ("winreg", &["basetsd", "minwinbase", "minwindef", "reason", "winnt"], &["advapi32"]),
378     ("winsafer", &["basetsd", "guiddef", "minwindef", "wincrypt", "windef", "winnt"], &["advapi32"]),
379     ("winscard", &["basetsd", "guiddef", "minwindef", "rpcdce", "windef", "winnt", "winsmcrd"], &["winscard"]),
380     ("winsmcrd", &["minwindef", "winioctl"], &[]),
381     ("winsock2", &["basetsd", "guiddef", "inaddr", "minwinbase", "minwindef", "qos", "winbase", "windef", "winerror", "winnt", "ws2def", "wtypesbase"], &["ws2_32"]),
382     ("winspool", &["guiddef", "minwinbase", "minwindef", "vcruntime", "windef", "winerror", "wingdi", "winnt"], &["winspool"]),
383     ("winsvc", &["minwindef", "winnt"], &["advapi32"]),
384     ("wintrust", &["guiddef", "minwindef", "ntdef", "wincrypt", "windef"], &["wintrust"]),
385     ("winusb", &["minwinbase", "minwindef", "usb", "usbspec", "winnt", "winusbio"], &["winusb"]),
386     ("winuser", &["basetsd", "guiddef", "limits", "minwinbase", "minwindef", "vadefs", "windef", "wingdi", "winnt"], &["user32"]),
387     ("winver", &["minwindef", "winnt"], &["kernel32", "version"]),
388     ("wlanapi", &["devpropdef", "eaptypes", "guiddef", "l2cmn", "minwindef", "windef", "windot11", "winnt", "wlantypes"], &["wlanapi"]),
389     ("wlanihv", &["basetsd", "dot1x", "eaptypes", "guiddef", "l2cmn", "minwindef", "windot11", "winnt", "winuser", "wlanihvtypes", "wlantypes", "wlclient"], &[]),
390     ("wlanihvtypes", &["eaptypes", "guiddef", "minwindef", "winnt", "wlantypes"], &[]),
391     ("wlclient", &["guiddef", "minwindef", "windot11", "winnt"], &[]),
392     ("wow64apiset", &["minwindef", "winnt"], &["kernel32"]),
393     ("wpdmtpextensions", &["wtypes"], &[]),
394     ("ws2bth", &["bthdef", "bthsdpdef", "guiddef", "minwindef", "winnt", "ws2def"], &[]),
395     ("ws2spi", &["basetsd", "guiddef", "minwindef", "vcruntime", "windef", "winnt", "winsock2", "ws2def", "wtypesbase"], &["ws2_32"]),
396     ("ws2tcpip", &["guiddef", "minwinbase", "minwindef", "mstcpip", "vcruntime", "winerror", "winnt", "winsock2", "ws2def", "wtypesbase"], &["fwpuclnt", "ws2_32"]),
397     ("wtsapi32", &["minwindef", "ntdef"], &["wtsapi32"]),
398     ("xinput", &["guiddef", "minwindef", "winnt"], &["xinput"]),
399     // vc
400     ("excpt", &[], &[]),
401     ("limits", &[], &[]),
402     ("vadefs", &[], &[]),
403     ("vcruntime", &[], &[]),
404     // winrt
405     ("activation", &["inspectable", "winnt"], &[]),
406     ("hstring", &["winnt"], &[]),
407     ("inspectable", &["guiddef", "hstring", "minwindef", "unknwnbase", "winnt"], &[]),
408     ("roapi", &["activation", "basetsd", "guiddef", "hstring", "inspectable", "objidl", "winnt"], &["runtimeobject"]),
409     ("robuffer", &["objidl", "winnt"], &["runtimeobject"]),
410     ("roerrorapi", &["basetsd", "hstring", "minwindef", "restrictederrorinfo", "unknwnbase", "winnt"], &["runtimeobject"]),
411     ("winstring", &["basetsd", "hstring", "minwindef", "winnt"], &["runtimeobject"]),
412 ];
413 struct Header {
414     required: bool,
415     included: Cell<bool>,
416     dependencies: &'static [&'static str],
417     libraries: &'static [&'static str],
418 }
419 struct Graph(HashMap<&'static str, Header>);
420 impl Graph {
generate() -> Graph421     fn generate() -> Graph {
422         Graph(DATA.iter().map(|&(name, dependencies, libraries)| {
423             let header = Header {
424                 required: false,
425                 included: Cell::new(false),
426                 dependencies: dependencies,
427                 libraries: libraries,
428             };
429             (name, header)
430         }).collect())
431     }
identify_required(&mut self)432     fn identify_required(&mut self) {
433         for (name, header) in &mut self.0 {
434             if let Ok(_) = var(&format!("CARGO_FEATURE_{}", name.to_uppercase())) {
435                 header.required = true;
436                 header.included.set(true);
437             }
438         }
439     }
check_everything(&self)440     fn check_everything(&self) {
441         if let Ok(_) = var("CARGO_FEATURE_EVERYTHING") {
442             for (_, header) in &self.0 {
443                 header.included.set(true);
444             }
445         }
446     }
resolve_dependencies(&self)447     fn resolve_dependencies(&self) {
448         let mut done = false;
449         while !done {
450             done = true;
451             for (_, header) in &self.0 {
452                 if header.included.get() {
453                     for dep in header.dependencies {
454                         let dep = &self.0.get(dep).expect(dep);
455                         if !dep.included.get() {
456                             done = false;
457                             dep.included.set(true);
458                         }
459                     }
460                 }
461             }
462         }
463     }
emit_features(&self)464     fn emit_features(&self) {
465         for (name, header) in &self.0 {
466             if header.included.get() && !header.required {
467                 println!("cargo:rustc-cfg=feature=\"{}\"", name);
468             }
469         }
470     }
emit_libraries(&self)471     fn emit_libraries(&self) {
472         let mut libs = self.0.iter().filter(|&(_, header)| {
473             header.included.get()
474         }).flat_map(|(_, header)| {
475             header.libraries.iter()
476         }).collect::<Vec<_>>();
477         libs.sort();
478         libs.dedup();
479         // FIXME Temporary hacks until build script is redesigned.
480         libs.retain(|&&lib| match &*var("TARGET").unwrap() {
481             "aarch64-pc-windows-msvc" | "aarch64-uwp-windows-msvc" | "thumbv7a-pc-windows-msvc" => {
482                 if lib == "opengl32" { false }
483                 else { true }
484             },
485             _ => true,
486         });
487         let prefix = library_prefix();
488         let kind = library_kind();
489         for lib in libs {
490             println!("cargo:rustc-link-lib={}={}{}", kind, prefix, lib);
491         }
492     }
493 }
library_prefix() -> &'static str494 fn library_prefix() -> &'static str {
495     if var("TARGET").map(|target|
496         target == "i686-pc-windows-gnu" || target == "x86_64-pc-windows-gnu"
497     ).unwrap_or(false) && var("WINAPI_NO_BUNDLED_LIBRARIES").is_err() {
498         "winapi_"
499     } else {
500         ""
501     }
502 }
library_kind() -> &'static str503 fn library_kind() -> &'static str {
504     if var("WINAPI_STATIC_NOBUNDLE").is_ok() {
505         "static-nobundle"
506     } else {
507         "dylib"
508     }
509 }
try_everything()510 fn try_everything() {
511     let mut graph = Graph::generate();
512     graph.identify_required();
513     graph.check_everything();
514     graph.resolve_dependencies();
515     graph.emit_features();
516     graph.emit_libraries();
517 }
main()518 fn main() {
519     println!("cargo:rerun-if-changed=build.rs");
520     println!("cargo:rerun-if-env-changed=WINAPI_NO_BUNDLED_LIBRARIES");
521     println!("cargo:rerun-if-env-changed=WINAPI_STATIC_NOBUNDLE");
522     let target = var("TARGET").unwrap();
523     let target: Vec<_> = target.split('-').collect();
524     if target.get(2) == Some(&"windows") {
525         try_everything();
526     }
527 }
528