OutSystems / CefGlue

.NET binding for The Chromium Embedded Framework (CEF)
MIT License
277 stars 41 forks source link

Linux support (Final) #153

Closed Haltroy closed 3 months ago

Haltroy commented 3 months ago

This is a follow-up for #121, #88 and #119 with help of @kkwpsv

This PR aims to add Linux support on both x64 and ARM64. The x64 support works flawlessly while ARM64 has issues (see below). Hopefully this is the final last pR on this topic, which is to bring CefGlue to Linux.

This PR also changes README to add a better support table for operating systems (Wİndows, macOS and Linux), UI toolkits (WPF and Avalonia UI) and processor architectures (x64 and ARM64).

Edits by maintainers are allowed on this PR.

Tested on:

ARM64 Issues (Direct quote from @kkwpsv)

If we load libcef.so dynamic, it will fail with "cannot allocate memory in static TLS block". Maybe CLR uses too much TLS? I tried glibc.rtld.optional_static_tls . It doesn't work. Maybe my linux os not support it. I don't know how to investigate it further.

Then I tried LD_PRELOAD, it works. But we need to do additional things to make it work with Avalonia. Cef uses HarfBuzz, and Avalonia also uses it. We must set LD_PRELOAD=/path/to/libHarfBuzzSharp.so:/path/to/libcef.so to ensure libHarfBuzzSharp load before cef, or the process will crash with SIGSEGV in HarfBuzz call.

We can also use patchelf to modify the elf file to load cef when process loading. patchelf --add-needed libHarfBuzzSharp.so --add-needed libcef.so path/to/Xilium.CefGlue.Demo.Avalonia patchelf --add-needed libcef.so path/to/Xilium.CefGlue.BrowserProcess (Browser process doesn't use Avalonia, so there's no need to add libHarfBuzzSharp.so)

Haltroy commented 3 months ago

Fixed most of the requests. Now we need to tackle down 2 issues:

joaompneves commented 3 months ago

While trying to produce the cef nuget package for linux, the script is taking alot of time in the stripping phase. In my machine I aborted after 10 mins and in the Azure pipelines (where we will be running the script) it took more than 30mins without finishing. How long is that supposed to take?

EDIT: took more than 60mins and the process was aborted with timeout

Haltroy commented 3 months ago

While trying to produce the cef nuget package for linux, the script is taking alot of time in the stripping phase. In my machine I aborted after 10 mins and in the Azure pipelines (where we will be running the script) it took more than 30mins without finishing. How long is that supposed to take?

EDIT: took more than 60mins and the process was aborted with timeout

It shouldn't take that much long. It uses cURL (just like cef.redist.osx) if aria2 was not found. I have no idea where is the issue in, the download phase or the stripping phase. If you have any logs, can you share them here? Also commands "strip" and "aarch64-linux-gnu-strip" are needed. If your machine is not Linux maybe it's trying to strip it for your OS instead?

EDIT: Yes we do need to strip these binaries otherwise NuGet won't accept them.

joaompneves commented 3 months ago

While trying to produce the cef nuget package for linux, the script is taking alot of time in the stripping phase. In my machine I aborted after 10 mins and in the Azure pipelines (where we will be running the script) it took more than 30mins without finishing. How long is that supposed to take? EDIT: took more than 60mins and the process was aborted with timeout

It shouldn't take that much long. It uses cURL (just like cef.redist.osx) if aria2 was not found. I have no idea where is the issue in, the download phase or the stripping phase. If you have any logs, can you share them here? Also commands "strip" and "aarch64-linux-gnu-strip" are needed. If your machine is not Linux maybe it's trying to strip it for your OS instead?

EDIT: Yes we do need to strip these binaries otherwise NuGet won't accept them.

I said in the initial reply, its in the stripping phase. The strip commands don't output anything. In Azure I'm also using a macOS machine, cause if I try to run the script in a ubuntu machine I get scripting errors.

Haltroy commented 3 months ago

While trying to produce the cef nuget package for linux, the script is taking alot of time in the stripping phase. In my machine I aborted after 10 mins and in the Azure pipelines (where we will be running the script) it took more than 30mins without finishing. How long is that supposed to take? EDIT: took more than 60mins and the process was aborted with timeout

It shouldn't take that much long. It uses cURL (just like cef.redist.osx) if aria2 was not found. I have no idea where is the issue in, the download phase or the stripping phase. If you have any logs, can you share them here? Also commands "strip" and "aarch64-linux-gnu-strip" are needed. If your machine is not Linux maybe it's trying to strip it for your OS instead? EDIT: Yes we do need to strip these binaries otherwise NuGet won't accept them.

I said in the initial reply, its in the stripping phase. The strip commands don't output anything. In Azure I'm also using a macOS machine, cause if I try to run the script in a ubuntu machine I get scripting errors.

Yeah I just noticed that. Sİnce I was using Linux and the topic is porting it to Linux I thought it would be better to write this script for Linux too. Running it on macOS is not my intention so I guess that's why it's taking longer to strip since its stripping for macOS instead of Linux (I guess). Have no idea why its giving script errors on Ubuntu though. (Is there any specific Ubuntu version that you use so I can test it and fix it there).

joaompneves commented 3 months ago

This is the Azure log: Generating script. Script contents: sh make_cefredist.sh linux64 ========================== Starting Command Output =========================== /usr/bin/bash --noprofile --norc /home/vsts/work/_temp/5825aa49-149a-4e70-85f1-ac0ca844e721.sh make_cefredist.sh: 4: [: linux64: unexpected operator downloading cef binaries /usr/bin/aria2c

According to this https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml

it should be running on ubuntu 22

Haltroy commented 3 months ago

Tested with the bash version that listed in Ubuntu 22 image packages list. It never gave any errors (also the error on line 4 which was just a check for the first argument and every documentation that I could find is doing it the exact same way)

joaompneves commented 3 months ago

Switching from sh to bash solved. Although the ARM54 still have some errors:

make_cefredist.sh: line 48: aarch64-linux-gnu-strip: command not found
make_cefredist.sh: line 49: aarch64-linux-gnu-strip: command not found
make_cefredist.sh: line 50: aarch64-linux-gnu-strip: command not found
make_cefredist.sh: line 51: aarch64-linux-gnu-strip: command not found
make_cefredist.sh: line 52: aarch64-linux-gnu-strip: command not found

Not sure I can I install that in the agent. Is it possible to include that in the script? Can you do that?

Haltroy commented 3 months ago

Switching from sh to bash solved. Although the ARM54 still have some errors:

make_cefredist.sh: line 48: aarch64-linux-gnu-strip: command not found
make_cefredist.sh: line 49: aarch64-linux-gnu-strip: command not found
make_cefredist.sh: line 50: aarch64-linux-gnu-strip: command not found
make_cefredist.sh: line 51: aarch64-linux-gnu-strip: command not found
make_cefredist.sh: line 52: aarch64-linux-gnu-strip: command not found

Not sure I can I install that in the agent. Is it possible to include that in the script? Can you do that?

We need to install binutils-aarch64-linux-gnu package into that system somehow or run an ARM64 machine (which where normal strip command can work its magic). Also ARM64 binaries are way bigger (~2GiB) so we really have to figure out a way. Since I have no idea how your Azure systems work, my guess is that running apt install -y binutils-aarch64-linux-gnu before executing the bash script is the only way. This might (?) help

Haltroy commented 3 months ago

So I guess that's it. Nuget & CEF redist issue got solved.

joaompneves commented 3 months ago

Can you test it again on Linux, with the most recent changes?

joaompneves commented 3 months ago

Can you test it again on Linux, with the most recent changes?

A screenshot would be nice to see how things look on Linux

Haltroy commented 3 months ago

Remember that "no-zygote" line? Yeah it crashed with this error: [0730/203230.971696:ERROR:zygote_communication_linux.cc(158)] Did not receive ping from zygote child

I added it back and now everything works. 0001

joaompneves commented 3 months ago

Its now available, version: 120.6099.204