From 755e955f9bd58013e0f2b455f3e34578c17e0ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Thu, 18 Apr 2024 15:04:42 +0200 Subject: [PATCH 1/6] gnome: add gpu-2404 integration --- snapcraft/extensions/gnome.py | 54 ++++++++++++++++++++++++-- tests/unit/extensions/test_gnome.py | 59 +++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 4 deletions(-) diff --git a/snapcraft/extensions/gnome.py b/snapcraft/extensions/gnome.py index 32f27de940..a97bc18255 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, "bin/gpu-2404-wrapper") return { - "command-chain": ["snap/command-chain/desktop-launch"], + "command-chain": command_chain, "plugs": [ "desktop", "desktop-legacy", @@ -130,6 +133,33 @@ 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", + "default-provider": "mesa-2404", + }, + } + + gpu_layouts = { + "/usr/share/libdrm": {"bind": "$SNAP/gpu/libdrm"}, + "/usr/share/drirc.d": {"symlink": "$SNAP/gpu/drirc.d"}, + "/usr/share/X11/XErrorDB": {"symlink": "$SNAP/gpu/X11/XErrorDB"}, + "/usr/share/X11/locale": {"symlink": "$SNAP/gpu/X11/locale"}, + } + case _: + raise AssertionError(f"Unsupported base: {base}") return { "assumes": ["snapd2.43"], # for 'snapctl is-connected' @@ -155,6 +185,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 +213,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 +322,19 @@ def get_parts_snippet(self) -> Dict[str, Any]: """ source = get_extensions_data_dir() / "desktop" / "command-chain" + gpu_parts = {} + if self.yaml_data["base"] == "core24": + gpu_parts["gpu-2404"] = { + "after": list(self.yaml_data["parts"].keys()), + "source": "https://github.com/canonical/gpu-snap.git", + "plugin": "dump", + "override-prime": ( + "craftctl default\n" + "${CRAFT_PART_SRC}/bin/gpu-2404-cleanup mesa-2404" + ), + "prime": ["bin/gpu-2404-wrapper"], + } + if self.gnome_snaps.builtin: base = self.yaml_data["base"] sdk_snap = _SDK_SNAP[base] @@ -299,12 +343,14 @@ def get_parts_snippet(self) -> Dict[str, Any]: "source": str(source), "plugin": "make", "build-snaps": [sdk_snap], - } + }, + **gpu_parts, } return { "gnome/sdk": { "source": str(source), "plugin": "make", - } + }, + **gpu_parts, } diff --git a/tests/unit/extensions/test_gnome.py b/tests/unit/extensions/test_gnome.py index fcc7d1d191..399ca44bfe 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,13 @@ 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": ["bin/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 +151,32 @@ 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", + } + + assert snippet["layout"]["/usr/share/libdrm"] == { + "bind": "$SNAP/gpu/libdrm", + } + + assert snippet["layout"]["/usr/share/drirc.d"] == { + "symlink": "$SNAP/gpu/drirc.d", + } + + assert snippet["layout"]["/usr/share/X11/XErrorDB"] == { + "symlink": "$SNAP/gpu/X11/XErrorDB", + } + + assert snippet["layout"]["/usr/share/X11/locale"] == { + "symlink": "$SNAP/gpu/X11/locale", + } + + 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 +408,25 @@ 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", + "build-snaps": ["gnome-46-2404-sdk"], + }, + "gpu-2404": { + "after": [], + "source": "https://github.com/canonical/gpu-snap.git", + "plugin": "dump", + "override-prime": ( + "craftctl default\n" "${CRAFT_PART_SRC}/bin/gpu-2404-cleanup mesa-2404" + ), + "prime": ["bin/gpu-2404-wrapper"], + }, + } + + def test_get_parts_snippet_with_external_sdk(gnome_extension_with_build_snap): assert gnome_extension_with_build_snap.get_parts_snippet() == { "gnome/sdk": { From f76c842e69c0af835966b5902972b7cf4d8c386e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Thu, 25 Apr 2024 13:31:27 +0200 Subject: [PATCH 2/6] gnome: bring gpu-2404-wrapper in --- extensions/desktop/command-chain/Makefile | 7 +++++-- .../desktop/command-chain/gpu-2404-wrapper | 5 +++++ snapcraft/extensions/gnome.py | 19 +++++-------------- tests/unit/extensions/test_gnome.py | 12 ++---------- 4 files changed, 17 insertions(+), 26 deletions(-) create mode 100644 extensions/desktop/command-chain/gpu-2404-wrapper 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 a97bc18255..17bdd854e5 100644 --- a/snapcraft/extensions/gnome.py +++ b/snapcraft/extensions/gnome.py @@ -93,7 +93,7 @@ def is_experimental(base: Optional[str]) -> bool: 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, "bin/gpu-2404-wrapper") + command_chain.insert(0, "snap/command-chain/gpu-2404-wrapper") return { "command-chain": command_chain, "plugs": [ @@ -322,18 +322,9 @@ def get_parts_snippet(self) -> Dict[str, Any]: """ source = get_extensions_data_dir() / "desktop" / "command-chain" - gpu_parts = {} + gpu_opts = {} if self.yaml_data["base"] == "core24": - gpu_parts["gpu-2404"] = { - "after": list(self.yaml_data["parts"].keys()), - "source": "https://github.com/canonical/gpu-snap.git", - "plugin": "dump", - "override-prime": ( - "craftctl default\n" - "${CRAFT_PART_SRC}/bin/gpu-2404-cleanup mesa-2404" - ), - "prime": ["bin/gpu-2404-wrapper"], - } + gpu_opts["make-parameters"] = "GPU_WRAPPER=gpu-2404-wrapper" if self.gnome_snaps.builtin: base = self.yaml_data["base"] @@ -343,14 +334,14 @@ def get_parts_snippet(self) -> Dict[str, Any]: "source": str(source), "plugin": "make", "build-snaps": [sdk_snap], + **gpu_opts, }, - **gpu_parts, } return { "gnome/sdk": { "source": str(source), "plugin": "make", + **gpu_opts, }, - **gpu_parts, } diff --git a/tests/unit/extensions/test_gnome.py b/tests/unit/extensions/test_gnome.py index 399ca44bfe..85598078d5 100644 --- a/tests/unit/extensions/test_gnome.py +++ b/tests/unit/extensions/test_gnome.py @@ -95,7 +95,7 @@ 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": ["bin/gpu-2404-wrapper", "snap/command-chain/desktop-launch"], + "command-chain": ["snap/command-chain/gpu-2404-wrapper", "snap/command-chain/desktop-launch"], "plugs": ["desktop", "desktop-legacy", "gsettings", "opengl", "wayland", "x11"], } @@ -413,17 +413,9 @@ def test_get_parts_snippet_core24(gnome_extension_core24): "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"], }, - "gpu-2404": { - "after": [], - "source": "https://github.com/canonical/gpu-snap.git", - "plugin": "dump", - "override-prime": ( - "craftctl default\n" "${CRAFT_PART_SRC}/bin/gpu-2404-cleanup mesa-2404" - ), - "prime": ["bin/gpu-2404-wrapper"], - }, } From 78e92e18c790d892154a3f3cf0822df2371bdf7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Thu, 25 Apr 2024 13:33:02 +0200 Subject: [PATCH 3/6] gnome: refresh gpu-2404 usage - add explicit `-2404` to the content target. - drop `X11/locale` layout, now served through `XLOCALEDIR` --- snapcraft/extensions/gnome.py | 9 ++++----- tests/unit/extensions/test_gnome.py | 12 ++++-------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/snapcraft/extensions/gnome.py b/snapcraft/extensions/gnome.py index 17bdd854e5..d121d8f941 100644 --- a/snapcraft/extensions/gnome.py +++ b/snapcraft/extensions/gnome.py @@ -147,16 +147,15 @@ def get_root_snippet(self) -> Dict[str, Any]: gpu_plugs = { "gpu-2404": { "interface": "content", - "target": "$SNAP/gpu", + "target": "$SNAP/gpu-2404", "default-provider": "mesa-2404", }, } gpu_layouts = { - "/usr/share/libdrm": {"bind": "$SNAP/gpu/libdrm"}, - "/usr/share/drirc.d": {"symlink": "$SNAP/gpu/drirc.d"}, - "/usr/share/X11/XErrorDB": {"symlink": "$SNAP/gpu/X11/XErrorDB"}, - "/usr/share/X11/locale": {"symlink": "$SNAP/gpu/X11/locale"}, + "/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}") diff --git a/tests/unit/extensions/test_gnome.py b/tests/unit/extensions/test_gnome.py index 85598078d5..a6909ec1d2 100644 --- a/tests/unit/extensions/test_gnome.py +++ b/tests/unit/extensions/test_gnome.py @@ -157,23 +157,19 @@ def test_get_root_snippet_with_gpu(gnome_extension_core24): assert snippet["plugs"]["gpu-2404"] == { "default-provider": "mesa-2404", "interface": "content", - "target": "$SNAP/gpu", + "target": "$SNAP/gpu-2404", } assert snippet["layout"]["/usr/share/libdrm"] == { - "bind": "$SNAP/gpu/libdrm", + "bind": "$SNAP/gpu-2404/libdrm", } assert snippet["layout"]["/usr/share/drirc.d"] == { - "symlink": "$SNAP/gpu/drirc.d", + "symlink": "$SNAP/gpu-2404/drirc.d", } assert snippet["layout"]["/usr/share/X11/XErrorDB"] == { - "symlink": "$SNAP/gpu/X11/XErrorDB", - } - - assert snippet["layout"]["/usr/share/X11/locale"] == { - "symlink": "$SNAP/gpu/X11/locale", + "symlink": "$SNAP/gpu-2404/X11/XErrorDB", } From e2d7a699e2e3ab160caaf1806df43de97a39c25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Fri, 26 Apr 2024 11:20:44 +0200 Subject: [PATCH 4/6] gnome: fix too long line --- snapcraft/extensions/gnome.py | 4 +++- tests/unit/extensions/test_gnome.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/snapcraft/extensions/gnome.py b/snapcraft/extensions/gnome.py index d121d8f941..8179e06e83 100644 --- a/snapcraft/extensions/gnome.py +++ b/snapcraft/extensions/gnome.py @@ -155,7 +155,9 @@ def get_root_snippet(self) -> Dict[str, Any]: 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"}, + "/usr/share/X11/XErrorDB": { + "symlink": "$SNAP/gpu-2404/X11/XErrorDB" + }, } case _: raise AssertionError(f"Unsupported base: {base}") diff --git a/tests/unit/extensions/test_gnome.py b/tests/unit/extensions/test_gnome.py index a6909ec1d2..73896dc33f 100644 --- a/tests/unit/extensions/test_gnome.py +++ b/tests/unit/extensions/test_gnome.py @@ -95,7 +95,10 @@ 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"], + "command-chain": [ + "snap/command-chain/gpu-2404-wrapper", + "snap/command-chain/desktop-launch" + ], "plugs": ["desktop", "desktop-legacy", "gsettings", "opengl", "wayland", "x11"], } From 2ef86ae5a55316f7a4d918c4330e13e9f392ab1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Fri, 26 Apr 2024 10:47:03 +0000 Subject: [PATCH 5/6] gnome: fix lint more --- tests/unit/extensions/test_gnome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/extensions/test_gnome.py b/tests/unit/extensions/test_gnome.py index 73896dc33f..05d1814819 100644 --- a/tests/unit/extensions/test_gnome.py +++ b/tests/unit/extensions/test_gnome.py @@ -97,7 +97,7 @@ 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" + "snap/command-chain/desktop-launch", ], "plugs": ["desktop", "desktop-legacy", "gsettings", "opengl", "wayland", "x11"], } From e0f82f0a84cfe780a3232856da073a36e25d0cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sawicz?= Date: Fri, 26 Apr 2024 16:46:20 +0200 Subject: [PATCH 6/6] gnome: fix make-parameter --- snapcraft/extensions/gnome.py | 2 +- tests/unit/extensions/test_gnome.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/snapcraft/extensions/gnome.py b/snapcraft/extensions/gnome.py index 8179e06e83..dbf9a9af39 100644 --- a/snapcraft/extensions/gnome.py +++ b/snapcraft/extensions/gnome.py @@ -325,7 +325,7 @@ def get_parts_snippet(self) -> Dict[str, Any]: gpu_opts = {} if self.yaml_data["base"] == "core24": - gpu_opts["make-parameters"] = "GPU_WRAPPER=gpu-2404-wrapper" + gpu_opts["make-parameters"] = ["GPU_WRAPPER=gpu-2404-wrapper"] if self.gnome_snaps.builtin: base = self.yaml_data["base"] diff --git a/tests/unit/extensions/test_gnome.py b/tests/unit/extensions/test_gnome.py index 05d1814819..59df9d13d3 100644 --- a/tests/unit/extensions/test_gnome.py +++ b/tests/unit/extensions/test_gnome.py @@ -412,7 +412,7 @@ def test_get_parts_snippet_core24(gnome_extension_core24): "gnome/sdk": { "source": str(get_extensions_data_dir() / "desktop" / "command-chain"), "plugin": "make", - "make-parameters": "GPU_WRAPPER=gpu-2404-wrapper", + "make-parameters": ["GPU_WRAPPER=gpu-2404-wrapper"], "build-snaps": ["gnome-46-2404-sdk"], }, }