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

Add support for ARM64 platforms #1

Open
gastonmuijtjens opened this issue Mar 2, 2023 · 12 comments
Open

Add support for ARM64 platforms #1

gastonmuijtjens opened this issue Mar 2, 2023 · 12 comments

Comments

@gastonmuijtjens
Copy link

Now that ARM64 is gaining popularity (mostly due to Apple Silicon on macOS), I would like to know whether it is possible to add support for the ARM64 platform to this library?

Trying to use the library on a M1 Mac raises the following exception:

System.DllNotFoundException: Unable to load shared library \u0027nfd\u0027 or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libnfd, 0x0001): tried: \u0027libnfd\u0027 (no such file), \u0027/System/Volumes/Preboot/Cryptexes/OSlibnfd\u0027 (no such file), \u0027/usr/lib/libnfd\u0027 (no such file, not in dyld cache), \u0027libnfd\u0027 (no such file), \u0027/usr/local/lib/libnfd\u0027 (no such file), \u0027/usr/lib/libnfd\u0027 (no such file, not in dyld cache)\n   at NativeFileDialogSharp.Native.NativeFunctions.NFD_OpenDialogMultiple(Byte* filterList, Byte* defaultPath, nfdpathset_t* outPaths)\n   at NativeFileDialogSharp.Dialog.FileOpenMultiple(String filterList, String defaultPath)\n 

I did some research already, and it turns out that ARM64 support for all platforms was already added a while ago to the devel branch of nativefiledialog. I assume that we can relatively easy add the runtimes for ARM64 to this project?

Thanks in advance.

@milleniumbug
Copy link
Owner

If the original library added support, then it's matter of compiling it toward the target platform.

I don't own the Apple hardware, so I see two ways to go from here:

  • use the hackintosh setup that I've used to compile the native library for Mac in the first place and cross-compile
  • use some CI/CD setup that supports targeting the ARM64 Apple ecosystem

@gastonmuijtjens
Copy link
Author

@milleniumbug Thanks for your reply. Me and my team does have both ARM64- and x64-based Macs available. If you could give us some guidance on how to compile the original native library, I can give it a try.

@kaylumah
Copy link

Hi @milleniumbug I am running into the same issue, and might be able to help. If you can give some pointers on how to compile the native library that would be most appreciated :)

@milleniumbug
Copy link
Owner

I have merged my changes and the changes at the upstream devel branch into https://github.com/milleniumbug/nativefiledialog/tree/devel
It turned out to be thankfully pretty simple as there were no changes to the source interface or binary interface, aside from an identical change to the one I already did (exposing NFD_Free as a public interface)

The other part is gonna be more difficult because I don't remember the exact way I made macOS x64 compile it, I do have a zsh history and browsing through I can give some vague directions:

  • clone the devel branch of my fork
  • make sure make and clang++ are available from the Terminal. If they're not already shipped with the system, it's likely a matter of either a.) installing Xcode, or b.) doing something with Homebrew
  • from the terminal, go to the build/gmake_macosx directory
  • run make config=release_arm64
  • assuming nothing fails (for me doing the above command fails, presumably because I don't have the arm64 development kit installed), the compiled library should appear in build/lib/Release/arm64/libnfd.dylib

@kaylumah
Copy link

@milleniumbug thank you for the guidance, I now have the build/lib/Release/arm64/libnfd.dylib file, but it does not show up as a git change.

So

  1. how do I verify the file is correct
  2. how do I get it back into source control

Thanks
Max

@milleniumbug
Copy link
Owner

milleniumbug commented Mar 18, 2023

Yeah, it won't show in git status as a change because it's a compiled library file, you typically do not commit these to the repo. But that's fine because I don't really want it in the native library repo, I'd like to see it in the runtimes directory in the C# wrapper library

https://github.com/milleniumbug/NativeFileDialogSharp/tree/main/NativeFileDialogSharp/runtimes

Adding it there under the osx-arm64/native directory should do the trick, and the only necessary thing would be using dotnet publish to create a NuGet library package.

@kaylumah
Copy link

Create a PR to add the lib, anything else needed from my part?
Do we need to change the csproj or something?

On Monday I can do a local Nuget pack to verify it is working as expected

@milleniumbug
Copy link
Owner

I have published the version including the ARM64 native library into NuGet as pre-release version 0.6.0-alpha - check it out if it works for you (you may need to select the "Include prerelease" option to see it in the listing of your IDE)

https://www.nuget.org/packages/NativeFileDialogSharp/0.6.0-alpha

@kaylumah
Copy link

I was able to verify that on arm64 Mac I can now open the file dialog :)

@milleniumbug
Copy link
Owner

Before I make it an actual release I'd like to see a bit more testing. @gastonmuijtjens , can you check on your devices?

@gastonmuijtjens
Copy link
Author

@milleniumbug I can confirm it works on both an Intel (x64) Mac and Apple Silicon (ARM64) Mac now. Thanks to you and @kaylumah for your effort. Please let me know if I can be of any further assistance.

@chrisyarbrough
Copy link

Thanks for the 0.6.0-alpha version! I was glad to find it and can also confirm it works on my Apple M1 chip with macOS Sonoma.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants