Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native] Question: Only use runtimes/{rid}/native without NativeReference? #14622

Closed
KiruyaMomochi opened this issue Apr 3, 2022 · 3 comments
Labels
support The issue is related to support
Milestone

Comments

@KiruyaMomochi
Copy link

KiruyaMomochi commented Apr 3, 2022

It's a question and I find it's hard to fill that issue template...

I'm currently building a native package for MacCatalyst and iOS.

For .NET 6 desktop platform like Windows/macOS desktop, I know putting native library files in runtimes/{rid}/native just work. However, Xamarin.iOS docs tells me that I must use PackNativeLibrary item to add them, so I add a .target file to my packge and it works.

I also found that SkiaSharp.NativeAssets.MacCatalyst doesn't use PackNativeLibrary, it only put files in runtimes. After testing this works well for me too.

Now is what confusing me

Another package SkiaSharp.NativeAssets.iOS, doesn't like the one for catalyst, includes .targets files for net6.0-ios13.6 and xamarinios1.0. But it also works after removing these .targets files. (Tested on simulator. I don't have any real iOS device, so I don't know if the behavior is the same on a real phone.)

The question

By checking #11667, I believe just put these native files in runtimes/{rid}/native is enough, and no NativeReference is required. Is that correct?

@KiruyaMomochi KiruyaMomochi changed the title [NativeReference] - Only use runtimes/{rid}/native without NativeReference? [native] Question: Only use runtimes/{rid}/native without NativeReference? Apr 3, 2022
@rolfbjarne rolfbjarne added the support The issue is related to support label Apr 4, 2022
@rolfbjarne rolfbjarne added this to the Future milestone Apr 4, 2022
@rolfbjarne
Copy link
Member

Yes, it's correct that you can put native files (.a, .framework, .dylib) in runtimes/{rid}/native, and they'll be picked up automatically (in .NET 6+).

However, if you have special requirements (such as additional linker flags for when we build the main executable), then you'll need a NativeReference.

However, Xamarin.iOS docs tells me that I must use PackNativeLibrary item to add them

Can you point us to these docs so that we can update them?

@KiruyaMomochi
Copy link
Author

KiruyaMomochi commented Apr 5, 2022

Thanks for your explanation.

It's not mentioned directly. I followed Working with Embedded Frameworks and added reference using Visual Studio for Mac, then found out what is added to .csproj file.

There is also an older article, Referencing Native Libraries in Xamarin.iOS, telling me to add extra arguments.

I hope we have some documentation explaining this .NET 6 feature, but I can't even find a clear documentation in .NET 6 or NuGet docs, although NuGet/Home#8623 and a StackOverflow answer explains some.

@KiruyaMomochi
Copy link
Author

KiruyaMomochi commented Apr 5, 2022

Please note that runtimes/{rid}/native is only granted to work as a NuGet package. In other words, if you including runtimes/** in your project directly or use a package reference, it will not work.

Instead, you must create a NuGet package for these native libraries, then use PackageReference to add them.

Releated: dotnet/runtime#65420 and dotnet/sdk#16381

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
support The issue is related to support
Projects
None yet
Development

No branches or pull requests

2 participants