Skip to content

Commit

Permalink
crosvm: add support for virgl_renderer{,_next}
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssais committed Mar 21, 2022
1 parent 6aefdaf commit 67d03e4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
35 changes: 31 additions & 4 deletions pkgs/applications/virtualization/crosvm/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ stdenv, lib, rustPlatform, fetchgit
, pkg-config, wayland-scanner, libcap, minijail, wayland, wayland-protocols
{ stdenv, lib, rust, rustPlatform, fetchgit
, meson, ninja, pkg-config, python3, wayland-scanner
, libcap, libdrm, libepoxy, libglvnd, minijail, wayland, wayland-protocols, xorg
, linux
}:

Expand All @@ -12,6 +13,13 @@ let
else if isx86_64 then "x86_64"
else throw "no seccomp policy files available for host platform";

rustTarget = rust.toRustTarget stdenv.hostPlatform;
rustArch = lib.head (builtins.match "([^-]*).*" rustTarget);

defaultMesonFlags = (stdenv.mkDerivation { name = "meson-cross-hack"; mesonFlags = []; }).mesonFlags;
mesonCrossFile = with builtins;
head (head (map (match "--cross-file=(.*)") defaultMesonFlags ++ [ [ null ] ]));

in

rustPlatform.buildRustPackage rec {
Expand All @@ -22,24 +30,43 @@ in

patches = [
./default-seccomp-policy-dir.diff
./rutabaga_gfx-don-t-clobber-PKG_CONFIG_PATH.patch
];

cargoLock.lockFile = ./Cargo.lock;

nativeBuildInputs = [ pkg-config wayland-scanner ];
nativeBuildInputs = [ meson ninja pkg-config python3 wayland-scanner ];

buildInputs = [ libcap minijail wayland wayland-protocols ];
buildInputs = [
libcap libdrm libepoxy libglvnd minijail wayland wayland-protocols
xorg.libX11
];

postPatch = ''
cp ${./Cargo.lock} Cargo.lock
sed -i "s|/usr/share/policy/crosvm/|$out/share/policy/|g" \
seccomp/*/*.policy
substituteInPlace third_party/minigbm/common.mk --replace /bin/ ""
sed -i '/fn main() {/a println!("cargo:rustc-link-lib=X11");' gpu_display/build.rs
# rutabaga_gfx/build.rs tests for the existence of this.
touch third_party/{minigbm,virglrenderer}/.git
'';

preBuild = ''
export DEFAULT_SECCOMP_POLICY_DIR=$out/share/policy
'' + lib.optionalString (mesonCrossFile != null) ''
dataDir="$(mktemp -d)"
mkdir -p "$dataDir/meson/cross"
ln -s ${mesonCrossFile} "$dataDir/meson/cross/${rustArch}"
export XDG_DATA_DIRS="$dataDir"
'';

dontUseNinjaBuild = true;
dontUseNinjaInstall = true;

buildFeatures = [ "default" "virgl_renderer" "virgl_renderer_next" ];

postInstall = ''
mkdir -p $out/share/policy/
cp seccomp/${arch}/* $out/share/policy/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From 5415aa75266099ab9f0e396fb2eaf24db14303ec Mon Sep 17 00:00:00 2001
From: Alyssa Ross <hi@alyssa.is>
Date: Mon, 21 Mar 2022 13:39:04 +0000
Subject: [PATCH] rutabaga_gfx: don't clobber PKG_CONFIG_PATH

The OS or user might have other important paths in here for dependencies.
---
rutabaga_gfx/build.rs | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/rutabaga_gfx/build.rs b/rutabaga_gfx/build.rs
index 198d8ea4..eb109a29 100644
--- a/rutabaga_gfx/build.rs
+++ b/rutabaga_gfx/build.rs
@@ -103,8 +103,14 @@ fn build_virglrenderer(out_dir: &Path) -> Result<()> {
}

let minigbm_src_abs = PathBuf::from(MINIGBM_SRC).canonicalize()?;
+ let mut pkg_config_path = minigbm_src_abs.clone().into_os_string();
+ if let Some(prev) = env::var_os("PKG_CONFIG_PATH") {
+ pkg_config_path.push(":");
+ pkg_config_path.push(prev);
+ }
+
let status = Command::new("meson")
- .env("PKG_CONFIG_PATH", &minigbm_src_abs)
+ .env("PKG_CONFIG_PATH", &pkg_config_path)
.arg("setup")
.arg("-Ddefault_library=static")
.args(get_meson_cross_args())
--
2.35.1

0 comments on commit 67d03e4

Please sign in to comment.