imazen / imageflow-dotnet

The official .NET API for Imageflow, the Rust image processing and optimization engine for web servers
GNU Affero General Public License v3.0
143 stars 25 forks source link

Apple Silicon M1 Pro: Unable to load shared library 'libdl.so' #39

Open pieterdhondt opened 2 years ago

pieterdhondt commented 2 years ago

Using code:

private async Task<string> GetThumbnailBase64(byte[] imageBytes)
{
       using (var b = new ImageJob())
        {
            var r = await b.Decode(imageBytes)
                .ResizerCommands("width=100&height=100&mode=crop")
                .EncodeToBytes(new MozJpegEncoder(50,true))
                .Finish().InProcessAsync();

            var base64thumbnail = r.First.TryGetBytes().HasValue ? Convert.ToBase64String(r.First.TryGetBytes().Value) : null;
            return base64thumbnail;
        }       
}

I am not able to use the library on a Mac with M1 Pro on macOS 12.0.1. It throws the following exception:

System.DllNotFoundException: Unable to load shared library 'libdl.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibdl.so, 0x0001): tried: 'liblibdl.so' (no such file), '/usr/local/lib/liblibdl.so' (no such file), '/usr/lib/liblibdl.so' (no such file), '/Users/pieterdhondt/Git/topics-service/TopicsService.Api/liblibdl.so' (no such file), '/usr/local/lib/liblibdl.so' (no such file), '/usr/lib/liblibdl.so' (no such file)
         at Imageflow.Bindings.UnixLoadLibrary.dlopen(String fileName, Int32 flags)
         at Imageflow.Bindings.UnixLoadLibrary.Execute(String fileName)
         at Imageflow.Bindings.NativeLibraryLoader.LoadLibrary(String fullPath, IntPtr& handle, Nullable`1& errorCode)
         at Imageflow.Bindings.NativeLibraryLoader.TryLoadByBasenameInternal(String basename, ILibraryLoadLogger log, IntPtr& handle, IEnumerable`1 customSearchDirectories)
         at Imageflow.Bindings.NativeLibraryLoader.TryLoadByBasename(String basename, ILibraryLoadLogger log, IntPtr& handle, IEnumerable`1 customSearchDirectories)
         at Imageflow.Bindings.NativeLibraryLoader.FixDllNotFoundException[T](String basename, Func`1 invokingOperation, IEnumerable`1 customSearchDirectories)
         at Imageflow.Bindings.JobContextHandle..ctor()
         at Imageflow.Bindings.JobContext..ctor()
         at Imageflow.Fluent.ImageJob.FinishAsync(JobExecutionOptions executionOptions, SecurityOptions securityOptions, CancellationToken cancellationToken)

The same code runs fine on Windows or within a Linux container.

Any advice?

shane9 commented 2 years ago
internal static class UnixLoadLibrary
{
        // TODO: unsure if this works on Mac OS X; it might be libc instead
        [DllImport("libc.dylib", SetLastError = true, CharSet = CharSet.Ansi)]
        private static extern IntPtr dlopen(string fileName, int flags);
        ...
}

Changing libdl.so to libc.dylib fixes this issue. Then there will be an issue loading libimageflow. Haven't looked into that yet.

I think this would be a good use case for NativeLibrary.SetDllImportResolver

lilith commented 2 years ago

What version of .NET are you using? We try to support everything .NET Standard 2.0 does, which means a lot of hackery for every runtime and platform.

shane9 commented 2 years ago

.NET 6.0 on M1 Mac

heinzmuller commented 2 years ago

Same issue here, any suggestions @shane9 @pieterdhondt?

adamshaylor commented 2 years ago

.NET 6.0.400 on M1 for me.

lilith commented 2 years ago

I don't have a M1 mac to add support for aarch64 / mac... I bought a 2020 retina prior to the announcement.

On Wed, Sep 7, 2022, 2:07 PM Adam Shaylor @.***> wrote:

.NET 6.0.400 on M1 for me.

— Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow-dotnet/issues/39#issuecomment-1239820337, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH3NOUSME7Z347Z5YR3V5DYZBANCNFSM5JCL6YHQ . You are receiving this because you commented.Message ID: @.***>

lilith commented 1 year ago

Duplicate of https://github.com/imazen/imageflow/issues/592

piotr-szczygiel commented 1 year ago

Hi, I have same issue (net7, M2). Any news about when it will be fixed? It's nearly 2 years since when it was originaly reported.

lilith commented 1 year ago

Apple Silicon isn't supported yet except in x86 emulation mode; I don't have an M1/M2 to test with and there don't seem to be many people using it. Is your company interested in funding it?

On Tue, Jul 4, 2023, 3:07 PM Piotr Szczygieł @.***> wrote:

Hi, I have same issue (net7, M2). Any news about when it will be fixed? It's nearly 2 years since when it was originaly reported.

— Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow-dotnet/issues/39#issuecomment-1619555516, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH2I4FC4OUMFHQWSVILXOOXLJANCNFSM5JCL6YHQ . You are receiving this because you commented.Message ID: @.***>

EzzeldenElshrbaty commented 9 months ago

Hi, I have the same issue (net7, M2). any updates????

lilith commented 9 months ago

So far nobody has volunteered to work on it or loan me the hardware I would need to test and port it to Apple Silicon.

On Sat, Nov 25, 2023, 2:16 PM EzzeldenElshrbaty @.***> wrote:

Hi, I have the same issue (net7, M2). any updates????

— Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow-dotnet/issues/39#issuecomment-1826421462, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH6DQBF5CD37QFRLWETYGJN2XAVCNFSM5JCL6YH2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBSGY2DEMJUGYZA . You are receiving this because you commented.Message ID: @.***>

EzzeldenElshrbaty commented 9 months ago

I think it will be a little hard because most of the developers are in different countries.