Skip to content

Commit

Permalink
Add comment about using source-generated p/invokes to interop guideli…
Browse files Browse the repository at this point in the history
…nes (#63350)
  • Loading branch information
elinor-fung authored Jan 4, 2022
1 parent eed3a62 commit 4a1bcc3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/coding-guidelines/interop-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ Using enums instead of partial, static classes can lead to needing lots of casts

When defining the P/Invoke signatures and structs, we follow the guidelines in the [interop best practices documentation](https://docs.microsoft.com/en-us/dotnet/standard/native-interop/best-practices).

The runtime repo makes use of [source-generated p/invokes](../design/features/source-generator-pinvokes.md) whenever possible (see [the compatibility doc](../design/libraries/DllImportGenerator/Compatibility.md) for unsupported scenarios). Methods should be marked `GeneratedDllImport` and be `static` and `partial`.

If implicit framework references are disabled (as is the case for most libraries projects), explicit references to the below are required for marshalling arrays:
- `System.Memory`
- `System.Runtime.CompilerServices.Unsafe`

## UNIX shims

Often, various UNIX flavors offer the same API from the point-of-view of compatibility with C/C++ source code, but they do not have the same ABI. e.g. Fields can be laid out differently, constants can have different numeric values, exports can be named differently, etc. There are not only differences between operating systems (Mac OS X vs. Ubuntu vs. FreeBSD), but also differences related to the underlying processor architecture (x64 vs. x86 vs. ARM).
Expand Down

0 comments on commit 4a1bcc3

Please sign in to comment.