Skip to content

Commit

Permalink
extensions: add 'basic-graphics' extension
Browse files Browse the repository at this point in the history
This extension provides a shortcut for snaps that make use of the 'mesa-core22' snap
of graphics libraries & resources.  It configures the conventional 'graphics-core22'
content plug and provides the 'graphics-launch' helper script for setting-up
the environment.
  • Loading branch information
mboudr35 committed Aug 23, 2023
1 parent 20696c8 commit 2ccd924
Show file tree
Hide file tree
Showing 10 changed files with 3,543 additions and 0 deletions.
14 changes: 14 additions & 0 deletions extensions/basic-graphics/bin/graphics-cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -euo pipefail

SELF="$( cd -- "$(dirname "$0")/.." ; pwd -P )"

rm -f $(
(
for provider in "$@"; do
cat ${SELF}/lists/$provider.${CRAFT_TARGET_ARCH}.list
done
) | sort -u | awk "/.+/ { print \"${CRAFT_PRIME}/\" \$0 }"
)

find "${CRAFT_PRIME}" -type d -empty -delete
40 changes: 40 additions & 0 deletions extensions/basic-graphics/bin/graphics-launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh
set -e

# '%GRAPHICS%' interface is required
if ! snapctl is-connected %GRAPHICS%
then
echo "ERROR: the %GRAPHICS% interface isn't connected."
echo " Please install and connect a graphics userspace provider."
echo ""
echo "The default provider is %MESA%, you can install it and connect by issuing:"
echo " sudo snap install %MESA%"
echo " sudo snap connect ${SNAP_INSTANCE_NAME}:%GRAPHICS% %MESA%"
echo ""
echo "See https://mir-server.io/docs/the-graphics-core22-snap-interface for more information."
exit 1
fi

# These interfaces may be optional (varies by snap)
for PLUG in opengl wayland x11; do
if ! snapctl is-connected ${PLUG}
then
echo "WARNING: ${PLUG} interface not connected!"
fi
done

real_xdg_runtime_dir=$(dirname "${XDG_RUNTIME_DIR}")
real_wayland=${real_xdg_runtime_dir}/${WAYLAND_DISPLAY:-wayland-0}

[ -d "${real_xdg_runtime_dir}" ] || echo "WARNING: missing ${real_xdg_runtime_dir}, is a Wayland compositor running?"
[ -O "${real_wayland}" ] || echo "WARNING: missing ${real_wayland}, is a Wayland compositor running?"

if mkdir -p "$XDG_RUNTIME_DIR" -m 700; then
ln -sf "${real_wayland}" "$XDG_RUNTIME_DIR"
ln -sf "${real_wayland}.lock" "$XDG_RUNTIME_DIR"
else
echo "WARNING: XDG_RUNTIME_DIR ($XDG_RUNTIME_DIR) missing, Wayland will not work"
fi

exec "${SNAP}/graphics/bin/%GRAPHICS%-provider-wrapper" "$@"

0 comments on commit 2ccd924

Please sign in to comment.