tryphotino/photino.Blazor

Photino is using libwebkit2gtk-4.0-37 but building a flatpak that supports .NET 8 requires libwebkit2gtk-4.1

Opened this issue ยท 16 comments

I wanted to build a flatpak, but currently Photino is using libwebkit2gtk-4.0-37
In flatpak yaml, instead of

runtime: org.freedesktop.Platform
runtime-version: '23.08'
sdk: org.freedesktop.Sdk

you have to use

runtime: org.gnome.Platform
runtime-version: '46'
sdk: org.gnome.Sdk

Because:
https://docs.flatpak.org/en/latest/available-runtimes.html
The GNOME runtime is appropriate for any application that uses the GNOME platform. It is based on the Freedesktop runtime and adds the GNOME platform, including WebKitGTK

But Gnome 46 includes libwebkit2gtk-4.1

I tried using Gnome 41 that includes libwebkit2gtk-4.0 but Gnome 41 can not use .NET 8:

sdk-extensions:
  - org.freedesktop.Sdk.Extension.dotnet8

It can only support org.freedesktop.Sdk.Extension.dotnet5 and org.freedesktop.Sdk.Extension.dotnet6

This is my flatpak yaml:

id: net.openhabittracker.app
runtime: org.gnome.Platform
runtime-version: '46'
sdk: org.gnome.Sdk
sdk-extensions:
  - org.freedesktop.Sdk.Extension.dotnet8
build-options:
  prepend-path: "/usr/lib/sdk/dotnet8/bin"
  append-ld-library-path: "/usr/lib/sdk/dotnet8/lib"
  prepend-pkg-config-path: "/usr/lib/sdk/dotnet8/lib/pkgconfig"

command: OpenHT

finish-args:
  - --device=dri
  - --socket=x11
  - --share=ipc
  - --env=DOTNET_ROOT=/app/lib/dotnet

modules:
  - name: dotnet
    buildsystem: simple
    build-commands:
    - /usr/lib/sdk/dotnet8/bin/install.sh

  - name: OpenHabitTracker
    buildsystem: simple
    sources:
      - type: git
        url: https://github.com/Jinjinov/OpenHabitTracker.git
        branch: main
      - ./nuget-sources.json
    build-commands:
      - dotnet publish OpenHabitTracker.Blazor.Photino/OpenHabitTracker.Blazor.Photino.csproj -c Release -r linux-x64 -p:PublishSingleFile=true -p:SelfContained=true --source ./nuget-sources
      - mkdir -p ${FLATPAK_DEST}/bin
      - cp -r OpenHabitTracker.Blazor.Photino/bin/Release/net8.0/linux-x64/publish/* ${FLATPAK_DEST}/bin

I tried building webkit2gtk-4.0 from source, but the build always fails on my PC with 16 GB of RAM and 16 GB of SWAP (increased from 2 GB).

I can't use old Gnome which includes webkit2gtk-4.0 because it doesn't support .NET 8

I can't use new Gnome because it only includes webkit2gtk-4.1 but Photino needs webkit2gtk-4.0

I can't build webkit2gtk-4.0 from source, because the build always fails...

I don't know what else I can try...

id: net.openhabittracker.app
#runtime: org.freedesktop.Platform
#runtime-version: '23.08'
#sdk: org.freedesktop.Sdk
runtime: org.gnome.Platform
runtime-version: '46'
sdk: org.gnome.Sdk
sdk-extensions:
  - org.freedesktop.Sdk.Extension.dotnet8
build-options:
  prepend-path: "/usr/lib/sdk/dotnet8/bin"
  append-ld-library-path: "/usr/lib/sdk/dotnet8/lib"
  prepend-pkg-config-path: "/usr/lib/sdk/dotnet8/lib/pkgconfig"

command: OpenHT

finish-args:
  - --device=dri
  # TODO: Replace this with wayland and fallback-x11 once Wayland support
  #       becomes available:
  #       https://github.com/AvaloniaUI/Avalonia/pull/8003
  - --socket=x11
  - --share=ipc
  - --env=DOTNET_ROOT=/app/lib/dotnet

modules:
  - name: webkit2gtk-4.0
    sources:
      - type: archive
        url: https://webkitgtk.org/releases/webkitgtk-2.44.4.tar.xz
        sha256: 2ce4ec1b78413035037aba8326b31ed72696626b7bea7bace5e46ac0d8cbe796
        x-checker-data:
          type: html
          url: https://webkitgtk.org/releases/
          version-pattern: LATEST-STABLE-(\d[\.\d]+\d)
          url-template: https://webkitgtk.org/releases/webkitgtk-$version.tar.xz
    buildsystem: cmake-ninja
    config-opts:
      - -DPORT=GTK
      - -DCMAKE_BUILD_TYPE=RelWithDebInfo
      - -DENABLE_DOCUMENTATION=OFF
      - -DENABLE_MINIBROWSER=OFF
      - -DENABLE_WEBDRIVER=OFF
      - -DENABLE_GAMEPAD=OFF
      - -DUSE_LIBBACKTRACE=OFF
      - -DUSE_GTK4=OFF
      - -DUSE_SOUP2=ON
      - -DENABLE_BUBBLEWRAP_SANDBOX=OFF
    modules:
      - name: libsoup-2.4
        buildsystem: meson
        config-opts:
        - "-Dtests=false"
        sources:
        - type: archive
          url: https://download.gnome.org/sources/libsoup/2.74/libsoup-2.74.3.tar.xz
          sha256: e4b77c41cfc4c8c5a035fcdc320c7bc6cfb75ef7c5a034153df1413fa1d92f13

      - name: unifdef
        no-autogen: true
        make-install-args:
          - prefix=${FLATPAK_DEST}
        sources:
          - type: archive
            url: https://dotat.at/prog/unifdef/unifdef-2.12.tar.xz
            sha256: 43ce0f02ecdcdc723b2475575563ddb192e988c886d368260bc0a63aee3ac400
        cleanup:
          - '*'

  - name: dotnet
    buildsystem: simple
    build-commands:
    - /usr/lib/sdk/dotnet8/bin/install.sh

  - name: OpenHabitTracker
    buildsystem: simple
    sources:
      - type: git
        url: https://github.com/Jinjinov/OpenHabitTracker.git
        branch: main
      - ./nuget-sources.json
    build-commands:
      - dotnet publish OpenHabitTracker.Blazor.Photino/OpenHabitTracker.Blazor.Photino.csproj -c Release -r linux-x64 -p:PublishSingleFile=true -p:SelfContained=true --source ./nuget-sources
      - mkdir -p ${FLATPAK_DEST}/bin
      - cp -r OpenHabitTracker.Blazor.Photino/bin/Release/net8.0/linux-x64/publish/* ${FLATPAK_DEST}/bin

@Jinjinov can you adapt you FP configuration to not reference the dotnet SDK? If you publish your Photino app as a single file executable it will include the runtime for dotnet.

Here's the guide I prepared for packaging in Linux and it has worked for me so far.

https://github.com/tryphotino/photino.Samples/tree/master/Photino.PublishPhotino/PublishPhotino#universal-packaging-with-flatpak

What is the reason for using the deprecated libwebkit2gtk-4.0-37 ?

Is it too hard to update to libwebkit2gtk-4.1 ?

Are the any breaking changes?

Can I help somehow?

@Jinjinov There are some breaking changes between 4.0 and 4.1 and we have to compile with one or the other. We want to avoid making a separate NuGet package just for Linux if possible. Currently, 4.0 is more widely supported and, if we switch to 4.1, all of the existing apps using 4.0 will break (we actually did one release with 4.1 and it didn't go well, so we reverted). @philippjbauer is going to take a stab at figuring out path forward. In the interim, have you tried version 45? We think in our testing it worked with both .NET 8 and 4.0.

running the hello world sample also fails on ubuntu 24.04 LTS. i think it is very important to support 4.1 soon.

Same issue, can't get Photino to run in Flatpak, after following the Hello World sample.

These should be the available libwebkit2gtk versions, per Gnome version:

41  libwebkit2gtk-4.0.so.37.56.10

42  libwebkit2gtk-4.0.so.37.57.8

43  libwebkit2gtk-4.1.so.0.8.5
43  libwebkit2gtk-5.0.so.0.0.0

44  libwebkit2gtk-4.1.so.0.12.8

45  libwebkit2gtk-4.1.so.0.13.8

46  libwebkit2gtk-4.1.so.0.16.5

So the most recent version still providing 4.0 is 42, but that results in the following error:

/usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /app/bin/Photino.Native
.so)

And the Gnome 42 runtime comes with:

sh-5.1$ strings /lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBCXX_3.4.29
GLIBCXX_DEBUG_MESSAGE_LENGTH

Not sure if building Photino.Native from within the Flatpak would fix that, but maybe it's solving the wrong problem given the used Gnome versions.

@Jinjinov There are some breaking changes between 4.0 and 4.1 and we have to compile with one or the other. We want to avoid making a separate NuGet package just for Linux if possible. Currently, 4.0 is more widely supported and, if we switch to 4.1, all of the existing apps using 4.0 will break (we actually did one release with 4.1 and it didn't go well, so we reverted). @philippjbauer is going to take a stab at figuring out path forward. In the interim, have you tried version 45? We think in our testing it worked with both .NET 8 and 4.0.

Could you elaborate, or point me to an issue or something where the problems are detailed?

@Jinjinov can you adapt you FP configuration to not reference the dotnet SDK? If you publish your Photino app as a single file executable it will include the runtime for dotnet.

Here's the guide I prepared for packaging in Linux and it has worked for me so far.

https://github.com/tryphotino/photino.Samples/tree/master/Photino.PublishPhotino/PublishPhotino#universal-packaging-with-flatpak

@philippjbauer if I build the executable myself and then push the binaries to a repo, then flatpak isn't building my app from source, which is what I want, for several reasons

@Jinjinov There are some breaking changes between 4.0 and 4.1 and we have to compile with one or the other. We want to avoid making a separate NuGet package just for Linux if possible. Currently, 4.0 is more widely supported and, if we switch to 4.1, all of the existing apps using 4.0 will break (we actually did one release with 4.1 and it didn't go well, so we reverted). @philippjbauer is going to take a stab at figuring out path forward. In the interim, have you tried version 45? We think in our testing it worked with both .NET 8 and 4.0.

@MikeYeager why would a separate NuGet for Linux be necessary? is webkit2gtk used on any other platform besides Linux? why is 4.0 more widely supported? GNOME started using 4.1 with GNOME 43 on September 21, 2022 - that is more than 2 years ago. no, GNOME 45 does not support 4.0 because GNOME 42 was the last version that supported 4.0

can you point me to the branch that you used to release with 4.1? what exactly didn't go well?

We are aware of the issue, however it is a dilemma (as well described in a tauri issue). We have to build Photino for EITHER 4.0 or 4.1. We can't make it work for both. Until recently, 4.0 was much more prevalent, however, this is no longer the case. If we switch to 4.1, it will break everyone running 4.0. At some point, we will make the switch and create a breaking change. Until then, the work-around is to install 4.0 manually as described in that link OR to create your own package (deb, snap, etc.) for distribution and include the library (see publishing guide in samples). CentOs, Debian 11 and below and Ubuntu 20.04 and below do not have the webkitgtk 4.0. We will likely go to a new major version number when we do switch to 4.1. If the community has any suggestions, we'd like to hear from you.

I have spent countless hours trying to build webkit2gtk-4.0 from source - as I said in my previous post, 16 GB of RAM with 16 GB of swap wasn't enough. I finally succeeded with 24 GB of RAM and 24 GB of swap - the peak memory usage was 40 GB. I then submitted the flatpak to flathub, where the build failed.

Could you please show me the branch where you enabled 4.1 so that I can build the NuGet myself? Or, if you deleted that branch, tell me how I can do it myself? Pretty please, this issue is frustrating beyond belief - and I am not blaming you, I perfectly understand your reasons and I appreciate your dedication to maintaining an open source library, I am grateful for it!

@Jinjinov I made a fork for this, as I ran into the same issue:
https://github.com/flyingpie/photino.Native/tree/webkit41

I'm tracking the exact changes in this PR:
flyingpie/photino.Native#1

Notes:

  • Currently only builds a Linux x64 binary
  • If you have Docker installed, just run "docker-build.sh", and you'll get a "Photino.Native.4.0.0-pre1.nupkg" in the root folder

The most impactful parts are in the makefile, the rest is just to make building the package easier.

@flyingpie Thank you!

I assume that I must also build my own photino.Blazor NuGet where I reference my own photino.NET NuGet where I reference Photino.Native.4.0.0-pre1.nupkg?

@Jinjinov You're welcome, hope it helps!

You don't have to recompile Photino.Blazor, just reference Photino.Native.4.0.0-pre1.nupkg from the consuming project and it will be used by Photino.Blazor.

Here's an example:

<ItemGroup>
	<PackageReference Include="Photino.Blazor" Version="3.2.0" />
	<PackageReference Include="Photino.Native" Version="4.0.0-pre1" />
</ItemGroup>

@flyingpie should it be apt-get install -y instead of apt get install -y?

FROM ubuntu:24.04

RUN apt-get update && apt-get install -y \
	build-essential \
	libgtk-3-dev \
	libwebkit2gtk-4.1-dev \
	libnotify4 \
	libnotify-dev

RUN apt-get update && apt get install -y \
	dotnet-sdk-8.0

WORKDIR /src

@Jinjinov Yeah, sorry, fixed. Thanks for noting!

For anyone else trying to install Docker inside Ubuntu inside VirtualBox inside Windows and failing miserably:

You actually don't have to install Docker in Ubuntu, you can use Docker in Windows :)

Instead of using docker-build.sh

#!/bin/bash

docker build -t photinobuilder .
docker run -it --rm -v $(pwd):/src photinobuilder \
	make linux-x64 \
	&& dotnet pack Photino.Native/Photino.Native.csproj --output .

you will have to use docker-build.ps1

# Build the Docker image
docker build -t photinobuilder .

# Run the Docker container, execute make, and then run dotnet pack inside the container
docker run -it --rm -v ${pwd}:/src photinobuilder /bin/bash -c "make linux-x64 && dotnet pack Photino.Native/Photino.Native.csproj --output ."

Thanks to @flyingpie I got it working! :)