1{ lib, stdenv, fetchFromGitiles, fetchpatch, meson, ninja, pkg-config, python3
2, aemu, darwin, libdrm, libglvnd, vulkan-headers, vulkan-loader, xorg
3}:
4
5stdenv.mkDerivation {
6 pname = "gfxstream";
7 version = "0.1.2";
8
9 src = fetchFromGitiles {
10 url = "https://android.googlesource.com/platform/hardware/google/gfxstream";
11 rev = "a29282666c0e2fdbb2c98cfe68a7c0677163ef91";
12 hash = "sha256-IYXkaHZPEYIE9KW731GN6x6yRS+FYtP1zyHcaSofhIM=";
13 };
14
15 patches = [
16 # Make libdrm an optional dependency, which is required to build on Darwin.
17 (fetchpatch {
18 url = "https://android.googlesource.com/platform/hardware/google/gfxstream/+/a8df2a3eb099b419a7b3638e68ea30b4cffb751b%5E%21/?format=TEXT";
19 decode = "base64 -d";
20 hash = "sha256-shjeNuxtQokscCGBKEUbOPKOWRELBAnHFNj3Y5w87Nw=";
21 })
22 ];
23
24 # Ensure that meson can find an Objective-C compiler on Darwin.
25 postPatch = lib.optionalString stdenv.isDarwin ''
26 substituteInPlace meson.build \
27 --replace-fail "project('gfxstream_backend', 'cpp', 'c'" "project('gfxstream_backend', 'cpp', 'c', 'objc'"
28 '';
29
30 nativeBuildInputs = [ meson ninja pkg-config python3 ];
31 buildInputs = [ aemu libglvnd vulkan-headers vulkan-loader xorg.libX11 ]
32 ++ lib.optionals (lib.meta.availableOn stdenv.hostPlatform libdrm) [ libdrm ]
33 ++ lib.optionals stdenv.isDarwin [
34 darwin.apple_sdk.frameworks.Cocoa
35 darwin.apple_sdk.frameworks.CoreGraphics
36 darwin.apple_sdk.frameworks.IOKit
37 darwin.apple_sdk.frameworks.IOSurface
38 darwin.apple_sdk.frameworks.OpenGL
39 darwin.apple_sdk.frameworks.QuartzCore
40 ];
41
42 env = lib.optionalAttrs stdenv.isDarwin {
43 NIX_LDFLAGS = toString [
44 "-framework Cocoa"
45 "-framework IOKit"
46 "-framework IOSurface"
47 "-framework OpenGL"
48 "-framework QuartzCore"
49 "-needed-lvulkan"
50 ];
51 };
52
53 # dlopens libvulkan.
54 preConfigure = lib.optionalString (!stdenv.isDarwin) ''
55 mesonFlagsArray=(-Dcpp_link_args="-Wl,--push-state -Wl,--no-as-needed -lvulkan -Wl,--pop-state")
56 '';
57
58 meta = with lib; {
59 homepage = "https://android.googlesource.com/platform/hardware/google/gfxstream";
60 description = "Graphics Streaming Kit";
61 license = licenses.free; # https://android.googlesource.com/platform/hardware/google/gfxstream/+/refs/heads/main/LICENSE
62 maintainers = with maintainers; [ qyliss ];
63 platforms = aemu.meta.platforms;
64 };
65}