Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnome: add gpu-2404 integration #4744

Merged
merged 9 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions extensions/desktop/command-chain/Makefile
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions extensions/desktop/command-chain/gpu-2404-wrapper
Original file line number Diff line number Diff line change
@@ -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"
46 changes: 42 additions & 4 deletions snapcraft/extensions/gnome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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'
Expand All @@ -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",
Expand Down Expand Up @@ -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,
},
}

Expand Down Expand Up @@ -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"]
sergiusens marked this conversation as resolved.
Show resolved Hide resolved

if self.gnome_snaps.builtin:
base = self.yaml_data["base"]
sdk_snap = _SDK_SNAP[base]
Expand All @@ -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,
},
}
50 changes: 50 additions & 0 deletions tests/unit/extensions/test_gnome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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": {
Expand Down
Loading