Skip to content

Commit

Permalink
base: Introduce wayland-cdi service
Browse files Browse the repository at this point in the history
This change introduces logic to generate a CDI definition for the Weston
display created at boot. With CDI enabled in a container runtime like
Docker, you could run Wayland apps with a command like:
running:
```
 docker run --rm -it --device=org.wayland/display=wayland-1 ubuntu
```

Signed-off-by: Andy Doan <[email protected]>
  • Loading branch information
doanac committed Oct 3, 2024
1 parent 621e0fd commit 83264e0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

cditmp="/run/cdi/.wayland.yaml.tmp"

mkdir -p /run/cdi
cat >${cditmp} <<EOF
cdiVersion: "0.6.0"
kind: org.wayland/display
devices:
EOF

mounts=""
for x in `find /run/user -mindepth 2 -maxdepth 2 -type s -name wayland-\*` ; do
echo Found Wayland instance: $x
found=1
xdg_dir="$(dirname $x)"
display_name="$(basename $x)"
mounts="${mounts} ${xdg_dir}"
cat >>${cditmp} <<EOF
- name: ${display_name}
containerEdits:
env:
- WAYLAND_DISPLAY=${display_name}
- XDG_RUNTIME_DIR=${xdg_dir}
EOF
done

if [ -n "${mounts}" ] ; then
cat >>${cditmp} <<EOF
containerEdits:
mounts:
EOF

for x in ${mounts} ; do
cat >>${cditmp} <<EOF
- type: bind
hostPath: ${x}
containerPath: ${x}
options:
- rbind
- rprivate
EOF
done
mv ${cditmp} /run/cdi/wayland.yaml
else
rm ${cditmp}
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=CDI device entry generator for Wayland
After=weston.service
Before=docker.service

[Service]
Type=oneshot
ExecStart=/usr/bin/wayland-cdi-generate
RemainAfterExit=yes

[Install]
WantedBy=weston.service
RequiredBy=docker.service
24 changes: 24 additions & 0 deletions meta-lmp-base/recipes-containers/wayland-cdi/wayland-cdi_0.1.bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
SUMMARY = "Sets up a CDI device entry for the Wayland display"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

inherit allarch systemd

RDEPENDS:${PN} = "systemd"

SRC_URI = "file://wayland-cdi.service \
file://wayland-cdi-generate \
"

PACKAGE_ARCH = "${MACHINE_ARCH}"

SYSTEMD_SERVICE:${PN} = "wayland-cdi.service"
SYSTEMD_AUTO_ENABLE:${PN} = "enable"

do_install() {
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/wayland-cdi-generate ${D}${bindir}/wayland-cdi-generate

install -d ${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/wayland-cdi.service ${D}${systemd_system_unitdir}
}

0 comments on commit 83264e0

Please sign in to comment.