DirectPInvoke with compile time platform check #95319
Labels
area-NativeAOT-coreclr
question
Answer questions and provide assistance, not an issue with source code or documentation.
In an .NET library (https://github.com/getsentry/sentry-dotnet), I'm integrating a native depency ((https://github.com/getsentry/sentry-native) as a static library and linking with DirectPInvoke.
For some of the native functions, the .net code needs to call the appropriate function variant based on the platform it's running on being Windows or Linux. The problem is, with the .net library targeting
net8.0
TFM, there doesn't seem to be a way to check do the conditional call that is properly resolved at link-time. This results in a link-time error when compiling for Linux, where windows-specific functions are not exported from the native library.The relevant c# code is:
Additionally, static linking in consumer applications is achieved with a
buildTransitive/Sentry.Native.targets
file:Ideally,
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
could be resolved as a compile-time constant and the conditional code could be trimmed completely when running on other platforms.Or is there another way to achieve this? AFAICT, the only option I have is removing the library-specific DirectPInvoke specification and listing all symbols explicitly, omitting the single windows-specific symbol.
I've tried adding
<DirectPInvoke Remove="sentry-native!sentry_options_set_database_pathw" />
to buildTransitive targets file but that doesn't seem to do anything.The text was updated successfully, but these errors were encountered: