diff --git a/extensions/desktop/command-chain/Makefile b/extensions/desktop/command-chain/Makefile index 86a85757a2..4ace2fd0de 100644 --- a/extensions/desktop/command-chain/Makefile +++ b/extensions/desktop/command-chain/Makefile @@ -1,10 +1,13 @@ #!/usr/bin/make -f BIN_DIR := $(DESTDIR)/snap/command-chain +GPU_WRAPPER := + +scripts = hooks-configure-fonts desktop-launch run $(GPU_WRAPPER) *: install -D -m755 "$@" "$(BIN_DIR)"/"$@" -install: hooks-configure-fonts desktop-launch run +install: $(scripts) -.PHONY: hooks-configure-fonts desktop-launch run +.PHONY: $(scripts) diff --git a/extensions/desktop/command-chain/gpu-2404-wrapper b/extensions/desktop/command-chain/gpu-2404-wrapper new file mode 100644 index 0000000000..997466660d --- /dev/null +++ b/extensions/desktop/command-chain/gpu-2404-wrapper @@ -0,0 +1,5 @@ +#!/bin/bash + +set -- "${SNAP}/gpu-2404/bin/gpu-2404-provider-wrapper" "$@" +# shellcheck source=/dev/null +source "${SNAP}/snap/command-chain/run" diff --git a/snapcraft/extensions/gnome.py b/snapcraft/extensions/gnome.py index e0d77fc4a9..d23b6be442 100644 --- a/snapcraft/extensions/gnome.py +++ b/snapcraft/extensions/gnome.py @@ -91,8 +91,11 @@ def is_experimental(base: Optional[str]) -> bool: @overrides def get_app_snippet(self) -> Dict[str, Any]: + command_chain = ["snap/command-chain/desktop-launch"] + if self.yaml_data["base"] == "core24": + command_chain.insert(0, "snap/command-chain/gpu-2404-wrapper") return { - "command-chain": ["snap/command-chain/desktop-launch"], + "command-chain": command_chain, "plugs": [ "desktop", "desktop-legacy", @@ -130,6 +133,34 @@ def gnome_snaps(self) -> GNOMESnaps: @overrides def get_root_snippet(self) -> Dict[str, Any]: platform_snap = self.gnome_snaps.content + base = self.yaml_data["base"] + + match base: + case "core22": + gpu_plugs = {} + gpu_layouts = { + "/usr/share/libdrm": { + "bind": "$SNAP/gnome-platform/usr/share/libdrm" + }, + } + case "core24": + gpu_plugs = { + "gpu-2404": { + "interface": "content", + "target": "$SNAP/gpu-2404", + "default-provider": "mesa-2404", + }, + } + + gpu_layouts = { + "/usr/share/libdrm": {"bind": "$SNAP/gpu-2404/libdrm"}, + "/usr/share/drirc.d": {"symlink": "$SNAP/gpu-2404/drirc.d"}, + "/usr/share/X11/XErrorDB": { + "symlink": "$SNAP/gpu-2404/X11/XErrorDB" + }, + } + case _: + raise AssertionError(f"Unsupported base: {base}") return { "assumes": ["snapd2.43"], # for 'snapctl is-connected' @@ -155,6 +186,7 @@ def get_root_snippet(self) -> Dict[str, Any]: "target": "$SNAP/gnome-platform", "default-provider": platform_snap, }, + **gpu_plugs, }, "environment": { "SNAP_DESKTOP_RUNTIME": "$SNAP/gnome-platform", @@ -182,7 +214,7 @@ def get_root_snippet(self) -> Dict[str, Any]: "/usr/share/xml/iso-codes": { "bind": "$SNAP/gnome-platform/usr/share/xml/iso-codes" }, - "/usr/share/libdrm": {"bind": "$SNAP/gnome-platform/usr/share/libdrm"}, + **gpu_layouts, }, } @@ -291,6 +323,10 @@ def get_parts_snippet(self) -> Dict[str, Any]: """ source = get_extensions_data_dir() / "desktop" / "command-chain" + gpu_opts = {} + if self.yaml_data["base"] == "core24": + gpu_opts["make-parameters"] = ["GPU_WRAPPER=gpu-2404-wrapper"] + if self.gnome_snaps.builtin: base = self.yaml_data["base"] sdk_snap = _SDK_SNAP[base] @@ -299,12 +335,14 @@ def get_parts_snippet(self) -> Dict[str, Any]: "source": str(source), "plugin": "make", "build-snaps": [sdk_snap], - } + **gpu_opts, + }, } return { "gnome/sdk": { "source": str(source), "plugin": "make", - } + **gpu_opts, + }, } diff --git a/tests/unit/extensions/test_gnome.py b/tests/unit/extensions/test_gnome.py index 2cc25f6d5e..2c061c710b 100644 --- a/tests/unit/extensions/test_gnome.py +++ b/tests/unit/extensions/test_gnome.py @@ -31,6 +31,13 @@ def gnome_extension(): ) +@pytest.fixture +def gnome_extension_core24(): + return gnome.GNOME( + yaml_data={"base": "core24", "parts": {}}, arch="amd64", target_arch="amd64" + ) + + @pytest.fixture def gnome_extension_with_build_snap(): return gnome.GNOME( @@ -86,6 +93,16 @@ def test_get_app_snippet(gnome_extension): } +def test_get_app_snippet_core24(gnome_extension_core24): + assert gnome_extension_core24.get_app_snippet() == { + "command-chain": [ + "snap/command-chain/gpu-2404-wrapper", + "snap/command-chain/desktop-launch", + ], + "plugs": ["desktop", "desktop-legacy", "gsettings", "opengl", "wayland", "x11"], + } + + def test_get_root_snippet(gnome_extension): assert gnome_extension.get_root_snippet() == { "assumes": ["snapd2.43"], @@ -137,6 +154,28 @@ def test_get_root_snippet(gnome_extension): } +def test_get_root_snippet_with_gpu(gnome_extension_core24): + snippet = gnome_extension_core24.get_root_snippet() + + assert snippet["plugs"]["gpu-2404"] == { + "default-provider": "mesa-2404", + "interface": "content", + "target": "$SNAP/gpu-2404", + } + + assert snippet["layout"]["/usr/share/libdrm"] == { + "bind": "$SNAP/gpu-2404/libdrm", + } + + assert snippet["layout"]["/usr/share/drirc.d"] == { + "symlink": "$SNAP/gpu-2404/drirc.d", + } + + assert snippet["layout"]["/usr/share/X11/XErrorDB"] == { + "symlink": "$SNAP/gpu-2404/X11/XErrorDB", + } + + def test_get_root_snippet_with_external_sdk(gnome_extension_with_build_snap): assert gnome_extension_with_build_snap.get_root_snippet() == { "assumes": ["snapd2.43"], @@ -368,6 +407,17 @@ def test_get_parts_snippet(gnome_extension): } +def test_get_parts_snippet_core24(gnome_extension_core24): + assert gnome_extension_core24.get_parts_snippet() == { + "gnome/sdk": { + "source": str(get_extensions_data_dir() / "desktop" / "command-chain"), + "plugin": "make", + "make-parameters": ["GPU_WRAPPER=gpu-2404-wrapper"], + "build-snaps": ["gnome-46-2404-sdk"], + }, + } + + def test_get_parts_snippet_with_external_sdk(gnome_extension_with_build_snap): assert gnome_extension_with_build_snap.get_parts_snippet() == { "gnome/sdk": {