-
Notifications
You must be signed in to change notification settings - Fork 546
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
Statically link the C++ runtime to libSkiaSharp.dll for windows platform #136
Comments
Typically one would create an installer or the ClickOnce deployment and include the VC++ Runtime as part of the install package. |
Neither one of the original two options look very appealing, we need to digest the above. Specially considering that @mattleibow 's suggestion is a viable option. |
I found some info:
I think this sums it up nicely:
|
Looking in to this yesterday (specifically w.r.t. SkiaSharp applications, as in general the situation can be more complicated) I found another option if you don't want to deploy your application via an installer. Your VS license comes with a provision to distribute certain runtime DLLs with your application directly, meaning you don't have to package them via the redistributable installer that everyone is familiar with. So the fix for issue #109 that doesn't require the redistributable installer is to copy the following two DLLs to the directory with your application .exe file: |
@tdenniston Thanks for this. This is definitely another, possibly the best so far, option. We want to make sure we make the right choice here, because as soon as we do a static link, we cannot go back as we may cause even more issues. |
@tdenniston Thanks for info, was looking for this solution myself but did not find this page. It also covers the Community edition, which is very good: https://www.visualstudio.com/en-us/support/legal/mt171547 This is newer version: https://www.visualstudio.com/en-us/downloads/2015-redistribution-vs.aspx I tested in VM and those 2 files are enough to run SkiaSharp succesfully. @mattleibow I thinks we can close this issue as the solution provided by @tdenniston is as good as static linking for me. Maybe adding this info to README would help other too. |
@wieslawsoltes, @tdenniston is correct - but not entirely. Those are the only two non-system dlls that are required in general cases.
The API-* are just the SxS assemblies provided by windows. However, on windows platforms without the Universal CRT, you may also have the need to install https://support.microsoft.com/en-us/kb/2999226. I'm guessing the reason they worked without it, is that they were likely a part of Windows Update (I may be wrong). On a side note, here's the Microsoft documentation that provides the full list of CRT deployment options: https://msdn.microsoft.com/en-us/library/ms235299.aspx |
I disagree with the installer solution.
Not requiring an installation is the whole point of .NET-Core self-contained deployment. Google has this very useful guiding principle: If it takes longer than 4 seconds, it's a bug. |
I'd like to add my vote to making a statically linked version available, although first of all... does anyone know if a statically linked version actually works? Assuming it does, here's my (possibly unique) rationale:
So I'm wondering what's the downside to including the statically linked versions in a separate folder in the nuget package (besides additional size)? This doesn't impact current users who want the shared runtime versions, but for anyone trying to package a static version, the correctly built versions of the dlls are there ready to go. It also means as new releases of SkiaSharp are made, we (those who want the statically linked version) don't need to make a special one-off build each time. In other words, I think there are legitimate cases for wanting statically linked versions and having to build them ourselves is kinda painful. |
To answer my own question, I've just built a statically linked version and it seems to work just fine. The size difference is about 300k:
Anyone else interested in this, there's a fork here with a new build target:
|
One scenario I'm facing this on, where an installer will not work, is deployment to Azure App Services. |
Is Skia still relevant anyway ? |
@ststeiger SkiaSharp can do far more that ImageSharp and also has the added support of doing everything on the GPU. SkiaSharp uses skia, which is the same engine that powers Android and Chrome. Of course, if you like ImageSharp, then feel free to use that. |
@danroot Thanks for pointing out the case with Azure, I will investigate this and see what we can do. |
@mattleibow I may have misunderstood this issue. I landed here from #109 with a similar error in an Azure App Service. In my case though, I was eventually able to get it working in Azure App Services by using this in the csproj PropertyGroup section:
And publishing the ASP.NET Core 2.1 app as "Self Contained". When I do this, the right DLL lands in Azure App Service, and I can run locally from my dev VM. I have the app service set (intentionally) to 32-bit, the projects set to "Any CPU", and it seems to be working both in Azure and on dev machine. I had manually copied msvcp140,dll and vcruntime140.dll to the bin folder, but just removed those and SkiaSharp still works. So I'm thinking Azure App Services has the C++ runtimes already and you just need to be sure the right libSkiaSharp.dll lands as well. It's still a little odd to me. I'm having a hard time imagining a scenario I wouldn't want the native dll and would rather it all "just work" even if it means a few more bytes in the package. But I'm sure there's reasons I just don't understand, and this solves my immediate issue.. |
@danroot Ah. I see. You are most probably working on a x64 machine? What is happening is that AnyCPU is checking your current build machine and detecting x64, so it copies the x64 libSkiaSharp.dll. You deploy to a x86 machine, but there is no way for the IDE to know this. To work around this, you can add the |
Actually I don't. |
I also encountered this. I have .Net Framework 4.7 Azure Function (x64 on Azure), depending on a Net Standard 2.0 class library using SkiaSharp. I platform for all projects to x64 and in the class library I used
But still this error occurs. I can see the dll in |
Or you can stream it ouf - write to
depending on anyway, that works for each operating system. |
I solved it using:
|
After seeing what is happening with Windows Docker containers, we may need to revisit the static linking idea. To be honest, I never linked statically and don't know what the side effects are. Right now, I have this single binary that works on Win 7+ and possible accross various server variants. If this affects loading of other assemblies, will this affect the loading process of the ANGLE binaries? What happens if we statically link to the VC2017 binaries and we run on Windows 7? I need to do some more testing and determine if a static linking has side effects that will affect us. It may just be something that does not affect us in the least, in that case, there is no reason not to. |
It only affects exported/imported C++ objects and memory allocated via CRT allocator ( SkiaSharp and ANGLE aren't doing any of these things. They have plain C API (no C++ objects) and provide custom deallocators for all "object" types. So it's completely safe to use any CRT linking options: static, dynamic, they can even use different versions of C runtime. VC2017 compiler and linker are compatible with Win7. |
@kekekeks I tried a test build with a statically linked Windows binary, and something is not quite right. The raster rendering appears to work just fine, but SkiaSharp chokes when trying to load the OpenGL interface. It throws an Here is my PR: #654 Maybe I am doing something wrong? I just ran the tests and I created a minimal sample using a @toptensoftware, did you make use of the GPU features? Also, things might have changed - I no longer have a hard dependency on opengl32.dll as I now load it dynamically with |
I may need to retest this one... I think something broke and now all GPU fails ;) Ran a clean, if this fails then a clean checkout may be necessary... Or maybe I broke my machine :( EDIT: yup, everything is broken. Going full reset and nuking the entire repo 💥 Bwahahaaaa! Take that you piece of silicon! |
OK. I have fixed the static link errors - it had to do with me writing bad C++ interop code. It appears to be working and most probably will read the next release. Yay! No more vc_redist installs! As of this comment, the new package is undergoing testing and can be downloaded here if you are not part of the EAP: https://jenkins.mono-project.com/view/SkiaSharp/job/SkiaSharp-Pipeline/job/feature%252Fstatic-win32/12/Azure |
* Now building a static Windows binary. #136 * Add support for building a "feature" version
That's it folks! The next version will be statically linked. We hope to have a public preview in a few days. |
As followup from issue #109.
I think there are two possible solutions:
libSkiaSharp.dll
by defaultlibSkiaSharp.dll
I vote for option No 1 as solves most of deployment issues, only downside is increased size of dll.
The text was updated successfully, but these errors were encountered: