Skiasharp: [QUESTION] Loading difficulties for xplat pwsh modules

Created on 8 Feb 2019  路  6Comments  路  Source: mono/SkiaSharp

Having an issue reliably loading native libraries from Skia within a powershell module on non-Windows platforms.

The error we're getting, predictably, is:

Message        : Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help
                 diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable:
                 dlopen(liblibSkiaSharp, 1): image not found
TypeName       :
Data           : {}
InnerException :
TargetSite     : IntPtr sk_fontmgr_ref_default()
StackTrace     :    at SkiaSharp.SkiaApi.sk_fontmgr_ref_default()
                    at SkiaSharp.SKFontManager.get_Default()
                    at PSWordCloud.WCUtils..cctor() in
                 /Users/****/Documents/Git/PSWordCloud/Cmdlet/src/WCUtils.cs:line 153
HelpLink       :
Source         : SkiaSharp
HResult        : -2146233052

So it seems as though we can work around this just by adding the right folder to the referenced environment variable... however, this doesn't seem to _work_. Adding the folders containing the native libs to the variable doesn't let them load.

For PowerShell this is a _particular_ problem, because I can't ship a version of my module for _every_ OS; I have to ship everything together. Well, I suppose I _can_, but that reduces discoverability. 馃檨

Is there a way we can build Skia to look for the native libraries under different _filenames_? Currently, several of the files that get dropped in <OS>/native have identical names, making it impossible for me to put them _all_ in the same folder as the main SkiaSharp.dll. If we could give them discrete names and still have Skia recognise and load the correct one, it'd neatly solve this problem.

image

That's what the structure looks like after a standard dotnet publish, but I'm not sure how to go about making sure each native library is accessible on a given platform that may be running pwsh.

type-question

Most helpful comment

"Resolved" by: https://github.com/PowerShell/PowerShell/pull/11032
Docs: https://docs.microsoft.com/en-us/powershell/scripting/learn/writing-portable-modules?view=powershell-7#dependency-on-native-libraries

NOTE: you still have to manually copy the native binaries into the correct place in your module.

All 6 comments

馃 would it be better to just have Mac/Linux users install Skia separately via mono itself, and avoid bothering to package too many native libs?

Well, we could go the one route and just put the x64 binaries for macOS/Windows/Linux as they have different extensions dylib/dll/so.

For Windows, you can either just ship the x64 binary, or, load each of the assemblies dynamically:

[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string dllToLoad);
...
if (is64Bit)
    LoadLibrary("path/to/64.dll");
else
    LoadLibrary("path/to/32.dll");

Something like this:
https://github.com/xamarin/urho/blob/a484a103208c854aead8f0d5cdc2150429f2813a/Bindings/Desktop/DesktopUrhoInitializer.cs#L41

I see you opened this issue: https://github.com/PowerShell/PowerShell/issues/8861 :)

馃槃 Yeah, best to ask on both ends of the dependency chain, I figured. Also @TylerLeonhardt asked me to open one for PowerShell specifically, because clearly we need better support for this stuff in-the-box for ourselves.

Appreciate the resource, thank you so much! <3

No prob. Now that I have commented on that issue, I will keep an eye on it.

"Resolved" by: https://github.com/PowerShell/PowerShell/pull/11032
Docs: https://docs.microsoft.com/en-us/powershell/scripting/learn/writing-portable-modules?view=powershell-7#dependency-on-native-libraries

NOTE: you still have to manually copy the native binaries into the correct place in your module.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alanricker picture alanricker  路  3Comments

loketha picture loketha  路  4Comments

michaldobrodenka picture michaldobrodenka  路  3Comments

Ziriax picture Ziriax  路  3Comments

joreg picture joreg  路  4Comments