-
Notifications
You must be signed in to change notification settings - Fork 555
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
Linux support #90
Comments
SkiaSharp should, but the native supporting code needs to be compiled individually on each Linux distribution. Sadly, NuGet was not designed to cope with this scenario, so there is not much that we can do to ship precompiled binaries. What we should do is at least provide a simple Makefile to create the native library support, so third parties can build/install it easily. |
@migueldeicaza compilations could be provided for several linux flavors using the runtimes/RID feature: https://dotnet.github.io/docs/core-concepts/rid-catalog.html |
@tmds An ARM Linux was actually work with this guy: #18 |
The issue is not identifying the library, the issue is that creating a package with the binaries is incredibly cumbersome (you need to create a package with all available systems upfront, build the native bits, and then package all the bits together). What should ideally happen is that these native binaries should be "addons" to the core package, and could be published independently of the core package. |
@migueldeicaza Any idea when makefiles for popular distros will be available? Is it going to happen this year or are we looking more at 2017? With .Net Core in the wild, lack of server side graphics library in Linux environment all of the sudden seems like a pressing matter. That being said, you are doing wonderful things with SkiaSharp and in Windows as GDI+ replacement it is just amazing. |
@migueldeicaza I think if you compile skia using sufficiently old distro (e. g. CentOS 6, Debian 5) it will just work everywhere. In the worst case you can just bundle dependencies (skia don't really need much: libfontconfig, libfreetype, libz, libpng12) and rely only on libc which is guaranteed to be present by LSB. |
I'm looking into the build.cake file and trying to work out how to convert it to build for linux. |
@jameswalmsley I would say you probably need to just get the externals building. These are grouped using the It pretty much follows the official docs by google: https://skia.org/user/quick/linux It follows the pattern of:
In the case of Android, I did step 4 using Basically, build all the The rest of the stuff is pure C#/.NET P/Invoke |
Yes. Build for Android linux is already there on the Gyp files however, if you plan to build it to any other linux, you will either have to hack the .gyp files to point to your dependencies (specially if you are cross compiling to another arch) and the output will be a bunch of .a. After that all compiled, you need to link it to the skiasharp. I had everything statically linked since the ld and glibc on the targed device was too old (pre-C++11). Basically this is the buld script:
One can create a makefile and make things easier but this native linux "macumba" is not something we are good here. So thanks to @mattleibow we got it to work. The C# side of SkiaSharp is just PInvokes with a .Net like APIs, so just point it to the right lib name and you are set. I hope it help. |
Thanks for this @galvesribeiro! |
Hello guys, I have some tips for you here. When I was messing with skia on linux half a year ago, I've run into an issue with really huge library file (50MB+). I've managed to strip it down to 2MB.
You can find a patch to skia.gyp here: https://github.com/AvaloniaUI/libperspesk/blob/master/linux/skia.patch Another issue with linking it was the fact that for some reason linker doesn't work properly with static library dependencies when you compile your shared library. --whole-archive just bloats your binary size and even then doesn't always work. So the trick is to unpack object files from static libs using I also recommend you to specify --no-undefined linker flag so you won't run into weird My old makefile is here: https://github.com/AvaloniaUI/libperspesk/blob/master/linux/Makefile#L32 |
Oh, forgot to add the script that downloads and actually builds skia itself: https://github.com/AvaloniaUI/libperspesk/blob/master/linux/getskia.sh |
I wish I had that! Hehehe btw, after strip, my release build was 3mb with everything statically linked. |
@mattleibow Did you see this? https://github.com/phusion/holy-build-box |
If anyone is interested, I've managed to run Cake in that docker container. First, you need to acquire mono-opt package for CentOS 5. For some reason I wasn't able to use the repo, so I've downloaded it manually from https://copr-be.cloud.fedoraproject.org/results/tpokorra/mono-opt/epel-5-x86_64/00496651-mono-opt/mono-opt-4.6.2-1.x86_64.rpm . In case it gets deleted, here is mega link: https://mega.nz/#!cswD2Jza!EqE-Q_rwmTK0vwYeNDaWSGm0aHK6y5roF1BHZdPGtz8 You need to install this package with yum install -y --nogpgcheck ./mono-opt-4.6.2-1.x86_64.rpm
yum install -y curl unzip
source /opt/mono/env.sh After that you should be able to run BTW, last time when I was messing with Skia, my library was depending on:
So it probably should be possible to provide a build of Skia that works everywhere |
Hello Guys, I was able to get the whole thing working on .net core on linux. I will share that when I have some time. If someone is interested and can't wait let me know and I'll share my new gn target. (Not using gyp) |
@Kuqd I'm interested in learning that, I've been working on a way to make a Wayland Program under Linux. (Would love to avoid using OpenGL.) |
@Kuqd I am busy looking to get Linux support in, especially for .NET Core. I have been using gyp because that was there, but if it is possible to share what you have done I would like to try using gn. Also, what OS specs are you running? |
Not using gyp is actually a good idea, since there is a lot of stuff hardcoded there. With custom scripts it should be much easier to build in unusual environments like ARM platforms with custom toolchains, HBB, etc. |
Just referencing this as it is relevant: NuGet/Home#3114 |
I have created a partially complete script and makefile. Build Script: SkiaSharp/cake/BuildExternals.cake Lines 420 to 463 in 21306d6
Makefile: https://github.com/mono/SkiaSharp/blob/21306d6267aeadcba31255d823e89edd54055440/native-builds/libSkiaSharp_linux/Makefile The basic steps are to gyp (create the internal makefiles), ninja (build the skia static libraries), and make (create the dynamic, linked libSkiaSharp). The Makefile is also pretty straight forward, take the skia outputs, and the xamarin classes and link together. I don't actually do anything specific for linux. I am still using gyp right now, but I will be looking to switch to gn sometime in the near future. |
Sorry I was away, here is the target to add to the build.gn:
then run this :
This is going to build 2 so : libSkiasharp.so and libskia.so, libSkiasharp.so depend on libskia.so, so make sure you update your LD_LIBRARY_PATH correclty on linux. I also have the .netstandard (1.6) project, with build task to create the correct nugetpackage that you can use on linux and .net core.If I have time I can create a pull request later @mattleibow , next month. The project I have is using the new visual studio 2017 RC3 (so you need the last toolchain) csproj, I've added my .net standard binding to SkiaSharp\binding\SkiaSharp.NETStandard\SkiaSharp.NETStandard.csproj :
Once you have the package built all you need is to add a root nuget.config to fetch from the local folder like such:
then you can reference it like that in your project :
I can provide built package if you want, but you will need to make sure that you fullfil all shared libraries dependencies use:
We're are in a middle of a big launch so can't really do more. I'm having very good performance by the way on ubuntu ! :) Hope it helps Cyril |
#238 Docker image and changes needed to produce a portable library that should work on most modern Linux distributions. |
I am looking at what is pulled in when adding the GPU bits. It is quite a bit and maybe the experts can tell me how much of this really portable. My local build and that of the holy build box is very similar: Holy Build Box:
Full -v: https://gist.github.com/mattleibow/f98bdd8b5a1bfc824f175a905bc48a9c My Local Build:
Full -v: https://gist.github.com/mattleibow/636ffaf7e9edf081bb08b094cdce3bea |
Would be nice if X11, GL and HW acceleration would be optional/configurable while building... That would make low-powered/non-X11 targets to use it as well... |
Also, about x86/32-bit builds. Is there a way to do this on a 64-bit OS? And should I even try? The same build config and I get these errors:
It appears those packages only come with either x86 or x64 libraries, not both. Should I just use an x86 environment, or is there a clean way to do this properly? |
@galvesribeiro Let me see if I can make that a nice flag that can be set... |
@mattleibow just noticed one thing... HBB is x86/x64 only :( I wonder if someone with experience in that could create the same environment using https://buildroot.org/ since it support more targets including ARM. |
@mattleibow |
Hi, how is it going with the Linux integration? I would like to integrate Skiasharp to an application that is deployed via docker containers. Unfortunately I am not a Linux expert. Installing some dependencies to my docker container would be perfectly fine for me too. I am a little bit lost at the moment. |
@SebastianStehle you can grab Avalonia.Skia.Linux.Natives nuget package with prebuilt libSkiaSharp.so that should work for most libc based distros (Debian/Ubuntu/RHEL/CentOS) |
Is there something else I have to do? I always get "Unable to load DLL 'libSkiaSharp': The specified module could not be found." I also tried to add add the *.so file as runtimeTarget to SkiaSharp:
I also tested other rid, e.g. just linux But it does not work so far |
|
Yes, it is deloyed to the following folder: "runtimes/linux-x64/native/libSkiaSharp.so", I also tested it to move the file to another folder, e.g. the root, but it does not help so far. Do you have a small example I will check that the other libraries are there as well. I guess I would get another error, e.g. cannot open shared object file 'libGL.so.1" or so. |
Check the library with I guess, I need to update the package so it won't require libGL. |
Hi,
Now I have all the dependencies (checked with Before the following dependencies were missing: libfontconfig.so.1 I still get the same error, when I run the container (on a linux host): System.DllNotFoundException: Unable to load DLL 'libSkiaSharp': The specified module could not be found. |
I've updated the package ( Also make sure that |
Thanks for your work on this @kekekeks. I am still waiting on our release engineering team to get a nice build of SkiaSharp out. I hope building linux using the new scripts is easer than it was. As you noticed, the last version (1.56.2) had no hard dependencies on anything except fontconfig. Right now I am in the process of updating to the m57 release of skia. This also comes with the new build system GN. A fair bit has changed with the build system, and I think for the better. |
I'm using your latest scripts with slightly modified holy-build-box-based docker image from before (I had to remove built-in Unfortunately I'm can't provide a proper dockerfile, since environment setup process involves some issues with installing Mono and I was unable to get it automated. I recommend to use the same approach, since it produces a portable binary that can run on almost all distros that matter. |
I have moved forward a small step. Now I get:
My dockerfile
If I don't install libfontconfig I get the old error. Chaning the paths in deps.json does not make a difference. I also noticed that there is a mismatch here in Skiasharp.dll: [assembly: AssemblyVersion("1.56.0.0")] Don't know if this is an issue but I also noticed some minor differences on .NET Core in Linux vs Win (often related to network stack btw.). |
It seems that you are doing something wrong with publishing. Make sure, that your project has proper runtime identifier included and that you have restored deps using said identifier before running I'd also recommend to create a self-contained bundle and run it on generic debian image. |
I cleaned everything, called "dotnet restore", "dotnet publish" and thats it. My csproj ist very simple as well:
The published version works correctly on Windows, also on another machine. Btw: I also tested version 1.56.1 of Skiasharp, therefore the different version numbers, but it does not change anything. |
You need |
Sorry, I was already very tired when I wrote it. I made a |
I suggest to either create a self-contained bundle or simply run from source. Always work for me that way. |
I'm trying to figure out why cake is being used for native linux builds at all? Correct me if I'm wrong but to built a native linux library the only thing required is to build libskia and than run make within the "native-builds/libSkiaSharp_linux/" . Using dotnetcore and cake just seems over and above as to what is really needed to compile the native linux library. |
@hurricanehrndz The reason for that is basically 2 reasons: I am not that clued up on make (or what the linux guys are using these days), and there are a few extra steps: https://github.com/mono/SkiaSharp/blob/master/cake/BuildExternals.cake#L102-L105 After working on this project, my skills have moved up a tiny bit, but I haven't had time to update the scripts. The best thing would be to actually mix all of this into the Makefile and just call make from cake. Thus, no need for any dependencies if you are just building native. And, I will mention that the build process has improved recently - the first few versions did not use the nice gn tool, and was a bit harder to do with my very limited knowledge. If you can go make and have the time, you can move this logic into the Makefile and send a PR. Everyone in the linux side of SkiaSharp will love you. ❤️ 🐧 |
Let me close this issue and open new issues with more specific tasks. As of now, linux support is available and working, just a bit rough to do. The issue to move the build into make: #311 I am closing this issue as it is quite big and is really too broad an issue. If any further questions, comments or issues are for linux support, either use the above issues or just create a new issue with your comment. This way the tasks are smaller and actionable, as well as easier to consume. |
Does SkiaSharp work on Linux?
The text was updated successfully, but these errors were encountered: