We have support for custom linker flags creating NuGets from binding projects: they're stored either in a LinkWith attribute in the assembly or a manifest next to the assembly or in a binding resource package.
However, we don't have any support for additional linker flags when we link with libraries from a NuGet that don't come from a binding project (those automatically added to ResolvedFileToPublish by NuGet's logic, see https://github.com/xamarin/xamarin-macios/blob/main/dotnet/BundleContents.md for more info).
This is particularly common for NuGets that have support for numerous platforms, in which case the native library will likely be a C library, and not have any specific binding code for our platforms.
We should come up with a solution here.
Idea: add support for a manifest file next to the library. This file would have the same format as our other manifest file.
Example manifest file:
<BindingAssembly>
<NativeReference Name="libtest.a">
<ForceLoad></ForceLoad>
<Frameworks>CoreLocation Foundation ModelIO</Frameworks>
<IsCxx></IsCxx>
<Kind>Static</Kind>
<LinkerFlags></LinkerFlags>
<NeedsGccExceptionHandling></NeedsGccExceptionHandling>
<SmartLink></SmartLink>
<WeakFrameworks></WeakFrameworks>
</NativeReference>
</BindingAssembly>
this file would be next to wherever libtest.a is in the NuGet (named libtest.manifest).
In theory these linker flags are only needed for static libraries, not for dylibs nor xcframeworks, but it should be trivial to add support for the manifest file for all types of libraries, so we should just do that as well (this could become useful if we use the manifest file to store more information in the future).
We have support for custom linker flags creating NuGets from binding projects: they're stored either in a LinkWith attribute in the assembly or a manifest next to the assembly or in a binding resource package.
However, we don't have any support for additional linker flags when we link with libraries from a NuGet that don't come from a binding project (those automatically added to ResolvedFileToPublish by NuGet's logic, see https://github.com/xamarin/xamarin-macios/blob/main/dotnet/BundleContents.md for more info).
This is particularly common for NuGets that have support for numerous platforms, in which case the native library will likely be a C library, and not have any specific binding code for our platforms.
We should come up with a solution here.
Idea: add support for a manifest file next to the library. This file would have the same format as our other manifest file.
Example manifest file:
this file would be next to wherever
libtest.ais in the NuGet (namedlibtest.manifest).In theory these linker flags are only needed for static libraries, not for dylibs nor xcframeworks, but it should be trivial to add support for the manifest file for all types of libraries, so we should just do that as well (this could become useful if we use the manifest file to store more information in the future).