kleisauke / net-vips

.NET binding for libvips.
https://kleisauke.github.io/net-vips/
MIT License
399 stars 32 forks source link

netvips.native.osx-arm64 for use in Unity #151

Closed jsm174 closed 2 years ago

jsm174 commented 2 years ago

Hello. I started working on getting VisualPinball.Engine to run on M1 macs using Unity 2021.2.1f1.

As you know from helping us in the past, we put the libraries in a Plugins folder keeping everything organized by architecture.

I noticed that 8.11.4 native does not include the osx-arm64 because of .NET 6. I tried to manually include it with a PackageReference, but it complained as well.

I was able to manually copy the file from the nuget into the Plugins folder, and Unity and NetVips runs fine.

Just to confirm, I checked the architecture:

➜  osx-arm64 git:(master) ✗ file libvips.42.dylib
libvips.42.dylib: Mach-O 64-bit dynamically linked shared library arm64

Is there anyway around this .NET 6 requirement for this type of case?

jsm174 commented 2 years ago

I came up with an ugly workaround, hopefully there is a better way to do this:

https://github.com/freezy/VisualPinball.Engine/blob/972caba542c4beaf186bf6ef7e646359f2703903/VisualPinball.Engine/VisualPinball.Engine.csproj#L59-L83

kleisauke commented 2 years ago

Thanks for reporting this! I think that I erroneously assumed that Apple Silicon support would only be available in .NET 6.

Note to myself: I could probably move this: https://github.com/kleisauke/net-vips/blob/d71da511a20667899933f41b66491f2d6b600fcf/build/native/NetVips.Native.nuspec#L32-L33

To the targetFramework="netstandard2.1" group below and remove the entire targetFramework="net6.0" group. Although, I'm not sure if I should also add a custom target file (NetVips.Native.osx-arm64.targets), similar to the x64 build: https://github.com/kleisauke/net-vips/blob/d71da511a20667899933f41b66491f2d6b600fcf/build/native/targets/NetVips.Native.osx-x64.targets#L10 (perhaps that isn't needed on the newer versions of Mono(?))

jsm174 commented 2 years ago

Thanks for looking into this. We appreciate it!

I'm not sure how custom targets work. In Visual Studio 2019 .Mac, I'm not sure how you would actually set up osx-arm64 for running / debugging. I know dotnet is using Rosetta.

Screen Shot 2021-11-08 at 7 10 59 AM

In Unity, it's definitely not using Rosetta, and is using the arm64 binaries.

I have a branch started here:

https://github.com/freezy/VisualPinball.Engine/tree/update-deps-osx-arm64

kleisauke commented 2 years ago

Those .targets files are only included within the netstandard2.0 or net452 target framework groups, so I guess I can leave that out within the netstandard2.1 group.

Commit https://github.com/kleisauke/net-vips/commit/b2ddba19cb859c4c6235b17c96d0a5269a08da7a on the issue-151 branch moves the macOS ARM64 NuGet package to the netstandard2.1 group, I think that should work for Mono/Unity. If you want to test this, you can use the nightly version of NetVips.Native. Add the https://ci.appveyor.com/nuget/net-vips feed in the <packageSources> section of your NuGet.config:

<packageSources>
  <add key="netvips-nightly" value="https://ci.appveyor.com/nuget/net-vips" />
</packageSources>

And use NetVips.Native v8.11.4.1 from there. This will be in NetVips.Native v8.12.0, due in a couple of days.

jsm174 commented 2 years ago

@kleisauke - Thank you again! Just tried this all out. Upgraded our projects to .netstandard2.1 as well, and it's working great. Since 8.12.0 is close, I'm assuming there won't be a 8.11.4.1 official?

kleisauke commented 2 years ago

A release candidate of NetVips.Native v8.12.0 is now available for testing. https://www.nuget.org/packages/NetVips.Native/8.12.0-rc1

I don't think there would be an official 8.11.4.1 release.

jsm174 commented 2 years ago

Great. Thanks. Just updated!

kleisauke commented 2 years ago

NetVips.Native v8.12.1 is now available.