Unverified Commit 2829592b authored by jopejoe1's avatar jopejoe1 Committed by GitHub
Browse files

alvr: build from source (#308097)

parents fa47680e 7c2572e5
Loading
Loading
Loading
Loading
+7328 −0

File added.

Preview size limit exceeded, changes collapsed.

+45 −0
Original line number Diff line number Diff line
From 1e792a4e7356f070856e4bf5775a07b18c3cc5ee Mon Sep 17 00:00:00 2001
From: jopejoe1 <johannes@joens.email>
Date: Sat, 7 Sep 2024 23:28:25 +0200
Subject: [PATCH] fix finding libs

---
 alvr/server_openvr/build.rs | 18 +++---------------
 alvr/session/build.rs       |  4 +---
 2 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/alvr/server_openvr/build.rs b/alvr/server_openvr/build.rs
index b9bc4bd8..0581de0d 100644
--- a/alvr/server_openvr/build.rs
+++ b/alvr/server_openvr/build.rs
@@ -1,24 +1,12 @@
-use std::{env, path::PathBuf};
+use std::{env, path::{Path, PathBuf}};
 
 fn get_ffmpeg_path() -> PathBuf {
-    let ffmpeg_path = alvr_filesystem::deps_dir()
-        .join(if cfg!(target_os = "linux") {
-            "linux"
-        } else {
-            "windows"
-        })
-        .join("ffmpeg");
-
-    if cfg!(target_os = "linux") {
-        ffmpeg_path.join("alvr_build")
-    } else {
-        ffmpeg_path
-    }
+    Path::new("@ffmpeg@").to_owned()
 }
 
 #[cfg(all(target_os = "linux", feature = "gpl"))]
 fn get_linux_x264_path() -> PathBuf {
-    alvr_filesystem::deps_dir().join("linux/x264/alvr_build")
+     Path::new("@x264@").to_owned()
 }
 
 fn main() {
-- 
2.46.0
+139 −19
Original line number Diff line number Diff line
{ lib,
  appimageTools,
  fetchurl,
{
  lib,
  rustPlatform,
  fetchFromGitHub,
  substituteAll,
  nix-update-script,
  pkg-config,
  autoAddDriverRunpath,
  alsa-lib,
  brotli,
  bzip2,
  celt,
  ffmpeg,
  jack2,
  lame,
  libX11,
  libXi,
  libXrandr,
  libXcursor,
  libdrm,
  libglvnd,
  libogg,
  libpng,
  libtheora,
  libunwind,
  libva,
  libvdpau,
  libxkbcommon,
  openssl,
  openvr,
  pipewire,
  rust-cbindgen,
  soxr,
  vulkan-headers,
  vulkan-loader,
  wayland,
  x264,
  xvidcore,
}:
let

rustPlatform.buildRustPackage rec {
  pname = "alvr";
  version = "20.6.1";
  src = fetchurl {
    url = "https://github.com/alvr-org/ALVR/releases/download/v${version}/ALVR-x86_64.AppImage";
    hash = "sha256-IYw3D18xUGWiFu74c4d8d4tohZztAD6mmZCYsDNxR+A=";
  version = "20.11.0";

  src = fetchFromGitHub {
    owner = "alvr-org";
    repo = "ALVR";
    rev = "refs/tags/v${version}";
    fetchSubmodules = true; #TODO devendor openvr
    hash = "sha256-zqeh9U0A/KHlRieq9Lf+7f04K3JG/vpE2gZ916ReXLc=";
  };

  cargoLock = {
    lockFile = ./Cargo.lock;
    outputHashes = {
      "openxr-0.19.0" = "sha256-bnMSjJh+zjLw4Pdxr7LLm6qYAJOK7hz5xORKZ2pVcGw=";
      "settings-schema-0.2.0" = "sha256-luEdAKDTq76dMeo5kA+QDTHpRMFUg3n0qvyQ7DkId0k=";
    };
  };

  patches = [
    (substituteAll {
      src = ./fix-finding-libs.patch;
      ffmpeg = lib.getDev ffmpeg;
      x264 = lib.getDev x264;
    })
  ];

  env = {
    NIX_CFLAGS_COMPILE = toString [
      "-lbrotlicommon"
      "-lbrotlidec"
      "-lcrypto"
      "-lpng"
      "-lssl"
    ];
  };

  appimageContents = appimageTools.extractType2 { inherit pname version src; };
in
appimageTools.wrapType2 {
  inherit pname version src;
  RUSTFLAGS = map (a: "-C link-arg=${a}") [
    "-Wl,--push-state,--no-as-needed"
    "-lEGL"
    "-lwayland-client"
    "-lxkbcommon"
    "-Wl,--pop-state"
  ];

  nativeBuildInputs = [
    rust-cbindgen
    pkg-config
    rustPlatform.bindgenHook
    autoAddDriverRunpath
  ];

  extraInstallCommands = ''
    install -Dm444 ${appimageContents}/alvr.desktop -t $out/share/applications
    substituteInPlace $out/share/applications/alvr.desktop \
      --replace-fail 'Exec=alvr_dashboard' 'Exec=alvr'
    cp -r ${appimageContents}/usr/share/icons $out/share
  buildInputs = [
    alsa-lib
    brotli
    bzip2
    celt
    ffmpeg
    jack2
    lame
    libX11
    libXcursor
    libXi
    libXrandr
    libdrm
    libglvnd
    libogg
    libpng
    libtheora
    libunwind
    libva
    libvdpau
    libxkbcommon
    openssl
    openvr
    pipewire
    soxr
    vulkan-headers
    vulkan-loader
    wayland
    x264
    xvidcore
  ];

  postBuild = ''
    # Build SteamVR driver ("streamer")
    cargo xtask build-streamer --release
  '';

  postInstall = ''
    install -Dm755 ${src}/alvr/xtask/resources/alvr.desktop $out/share/applications/alvr.desktop
    install -Dm644 ${src}/resources/alvr.png $out/share/icons/hicolor/256x256/apps/alvr.png

    # Install SteamVR driver
    mkdir -p $out/{libexec,lib/alvr,share}
    cp -r ./build/alvr_streamer_linux/lib64/. $out/lib
    cp -r ./build/alvr_streamer_linux/libexec/. $out/libexec
    cp -r ./build/alvr_streamer_linux/share/. $out/share
    ln -s $out/lib $out/lib64
  '';

  passthru.updateScript = nix-update-script { };

  meta = with lib; {
    description = "Stream VR games from your PC to your headset via Wi-Fi";
    homepage = "https://github.com/alvr-org/ALVR/";
    changelog = "https://github.com/alvr-org/ALVR/releases/tag/v${version}";
    license = licenses.mit;
    mainProgram = "alvr";
    mainProgram = "alvr_dashboard";
    maintainers = with maintainers; [ passivelemon ];
    platforms = [ "x86_64-linux" ];
    platforms = platforms.linux;
  };
}