NativeFileDialogSharp
NativeFileDialogSharp copied to clipboard
Add support for ARM64 platforms
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.
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
@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.
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 :)
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_macosxdirectory - 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
@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
- how do I verify the file is correct
- how do I get it back into source control
Thanks Max
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.
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
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
I was able to verify that on arm64 Mac I can now open the file dialog :)
Before I make it an actual release I'd like to see a bit more testing. @gastonmuijtjens , can you check on your devices?
@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.
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.
Quite late to the party, but I recently started using this library and switched to 0.6.0-alpha, it fixed the file picker for me on OSX Sequoia with an M1 macbook pro.