I’m currently building a classic snap that has use of OpenGL. However, even after packaging the required driver as mentioned on this thread, the application still ends up with a segmentation fault.
The snap was able to run “fine” on Ubuntu 22.04 once mentioned dependencies were included, but running on any other system caused the application to have a segmentation fault.
After some investigation, the segfault seems to come from this file /snap/tess/x1/usr/lib/x86_64-linux-gnu/dri/kms_swrast_dri.so. Running ldd on it shows that all dependencies are correctly resolved, either from the snap itself or from the core22 base snap. Additionally, none of the libraries used by the application appear to be loaded from the host.
Here is the snapcraft.yaml:
base: core22
name: tess
version: 1.0.0
title: Tess
summary: Lorem ipsum
description: |
Lorem ipsum
grade: stable
confinement: classic
parts:
tess:
plugin: rust
source: .
rust-path:
- src-tauri
build-snaps:
- node/20/stable
build-packages:
- libglib2.0-dev
- libgtk-3-dev
- libjavascriptcoregtk-4.1-dev
- libsoup-3.0-dev
- libwebkit2gtk-4.1-dev
stage-packages:
- libwebkit2gtk-4.1-0
- libibus-1.0-5
- ibus-gtk3
- libgtk-3-0
- libgtk-3-bin
- libltdl7
- libcanberra-gtk3-module
- libcanberra0
- gvfs
- gvfs-daemons
- gvfs-libs
- libcurl3-gnutls
stage:
- -usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/dri
build-attributes:
- enable-patchelf
override-build: |
npm install
craftctl default
override-stage: |
craftctl default
mkdir -p $SNAPCRAFT_PRIME/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/
$SNAPCRAFT_STAGE/usr/lib/x86_64-linux-gnu/libgtk-3-0/gtk-query-immodules-3.0 > $SNAPCRAFT_PRIME/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules.cache
sed -i "s|/usr/lib|/snap/tess/current/usr/lib|g" $SNAPCRAFT_PRIME/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules.cache
find "$SNAPCRAFT_STAGE/usr/lib" -name 'libwebkit*' -exec sed -i -e "s|/usr/lib/x86_64-linux-gnu/webkit2gtk-4.1|/snap/tess/current/webkit2gtk-4.1/./././|g" '{}' \;
cp -a "$SNAPCRAFT_STAGE/usr/lib/x86_64-linux-gnu/webkit2gtk-4.1" "$SNAPCRAFT_PRIME/"
mesa-patchelf:
plugin: nil
stage-packages:
- libgl1-mesa-dri
- freeglut3-dev
- libglu1-mesa
build-attributes:
- enable-patchelf
stage:
- -usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/dri
mesa-no-patchelf:
plugin: nil
stage-packages:
- libgl1-mesa-dri
- freeglut3-dev
- libglu1-mesa
stage:
- usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/dri
apps:
tess:
command: bin/tess
environment:
LD_LIBRARY_PATH: $SNAP/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu/webkit2gtk-4.1:$LD_LIBRARY_PATH
GIO_MODULE_DIR: $SNAP/usr/lib/x86_64-linux-gnu/gio/modules
GTK_IM_MODULE_FILE: $SNAP/usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules.cache
__EGL_VENDOR_LIBRARY_DIRS: $SNAP/etc/glvnd/egl_vendor.d:$SNAP/usr/share/glvnd/egl_vendor.d
LIBGL_DRIVERS_PATH: $SNAP/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/dri