@@ -231,9 +231,38 @@ resolution logic to find that import library. Alternatively, specifying
231
231
` kind = "raw-dylib" ` instructs the compiler to generate an import library
232
232
during compilation and provide that to the linker instead.
233
233
234
- ` raw-dylib ` is only supported on Windows and not supported on 32-bit x86
235
- (` target_arch="x86" ` ). Using it when targeting other platforms or
236
- x86 on Windows will result in a compiler error.
234
+ ` raw-dylib ` is only supported on Windows. Using it when targeting other
235
+ platforms will result in a compiler error.
236
+
237
+ #### The ` import_name_type ` key
238
+
239
+ On x86 Windows, names of functions are "decorated" (i.e., have a specific prefix
240
+ and/or suffix added) to indicate their calling convention. For example, a
241
+ ` stdcall ` calling convention function with the name ` fn1 ` that has no arguments
242
+ would be decorated as ` _fn1@0 ` . However, the [ PE Format] does also permit names
243
+ to have no prefix or be undecorated. Additionally, the MSVC and GNU toolchains
244
+ use different decorations for the same calling conventions which means, by
245
+ default, some Win32 functions cannot be called using the ` raw-dylib ` link kind
246
+ via the GNU toolchain.
247
+
248
+ To allow for these differences, when using the ` raw-dylib ` link kind you may
249
+ also specify the ` import_name_type ` key with one of the following values to
250
+ change how functions are named in the generated import library:
251
+
252
+ * ` decorated ` : The function name will be fully-decorated using the MSVC
253
+ toolchain format.
254
+ * ` noprefix ` : The function name will be decorated using the MSVC toolchain
255
+ format, but skipping the leading ` ? ` , ` @ ` , or optionally ` _ ` .
256
+ * ` undecorated ` : The function name will not be decorated.
257
+
258
+ If the ` import_name_type ` key is not specified, then the function name will be
259
+ fully-decorated using the target toolchain's format.
260
+
261
+ Variables are never decorated and so the ` import_name_type ` key has no effect on
262
+ how they are named in the generated import library.
263
+
264
+ The ` import_name_type ` key is only supported on x86 Windows. Using it when
265
+ targeting other platforms will result in a compiler error.
237
266
238
267
### The ` link_name ` attribute
239
268
@@ -308,3 +337,4 @@ restrictions as [regular function parameters].
308
337
[ `whole-archive` documentation for rustc ] : ../../rustc/command-line-arguments.html#linking-modifiers-whole-archive
309
338
[ `verbatim` documentation for rustc ] : ../../rustc/command-line-arguments.html#linking-modifiers-verbatim
310
339
[ `dylib` versus `raw-dylib` ] : #dylib-versus-raw-dylib
340
+ [ PE Format ] : https://learn.microsoft.com/windows/win32/debug/pe-format#import-name-type
0 commit comments