Unverified Commit 656e50ab authored by K900's avatar K900 Committed by GitHub
Browse files

mesa: more cleanups (#387292)

parents cca5036b 5240588e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10,6 +10,6 @@ The NixOS desktop or other non-headless configurations are the primary target fo

## Nix on GNU/Linux {#nix-on-gnulinux}

If you are using a non-NixOS GNU/Linux/X11 desktop with free software video drivers, consider launching OpenGL-dependent programs from Nixpkgs with Nixpkgs versions of `libglvnd` and `mesa.drivers` in `LD_LIBRARY_PATH`. For Mesa drivers, the Linux kernel version doesn't have to match nixpkgs.
If you are using a non-NixOS GNU/Linux/X11 desktop with free software video drivers, consider launching OpenGL-dependent programs from Nixpkgs with Nixpkgs versions of `libglvnd` and `mesa` in `LD_LIBRARY_PATH`. For Mesa drivers, the Linux kernel version doesn't have to match nixpkgs.

For proprietary video drivers, you might have luck with also adding the corresponding video driver package.
+2 −2
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ in
          { "r" = {}; };
    };

    hardware.graphics.package = lib.mkDefault pkgs.mesa.drivers;
    hardware.graphics.package32 = lib.mkDefault pkgs.pkgsi686Linux.mesa.drivers;
    hardware.graphics.package = lib.mkDefault pkgs.mesa;
    hardware.graphics.package32 = lib.mkDefault pkgs.pkgsi686Linux.mesa;
  };
}
+4 −2
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
  arcan,
  audit,
  dbus,
  dri-pkgconfig-stub,
  libepoxy,
  fontutil,
  libGL,
@@ -21,7 +22,7 @@
  libxkbfile,
  libxshmfence,
  libgbm,
  mesa,
  mesa-gl-headers,
  meson,
  nettle,
  ninja,
@@ -60,6 +61,7 @@ stdenv.mkDerivation (finalPackages: {
    arcan
    audit
    dbus
    dri-pkgconfig-stub
    libepoxy
    fontutil
    libGL
@@ -76,7 +78,7 @@ stdenv.mkDerivation (finalPackages: {
    libxkbfile
    libxshmfence
    libgbm
    mesa # uses dri_interface.h
    mesa-gl-headers
    nettle
    openssl
    pixman
+34 −83
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
, intltool
, jdupes
, libdrm
, libgbm
, libglvnd
, libunwind
, libva-minimal
@@ -139,19 +140,12 @@ in stdenv.mkDerivation {

  patches = [
    ./opencl.patch
    ./system-gbm.patch
  ];

  postPatch = ''
    patchShebangs .

    # The drirc.d directory cannot be installed to $drivers as that would cause a cyclic dependency:
    substituteInPlace src/util/xmlconfig.c --replace \
      'DATADIR "/drirc.d"' '"${placeholder "out"}/share/drirc.d"'
    substituteInPlace src/util/meson.build --replace \
      "get_option('datadir')" "'${placeholder "out"}/share'"
    substituteInPlace src/amd/vulkan/meson.build --replace \
      "get_option('datadir')" "'${placeholder "out"}/share'"

    for header in ${toString mesa-gl-headers.headers}; do
      if ! diff -q $header ${mesa-gl-headers}/$header; then
        echo "File $header does not match between mesa and mesa-gl-headers, please update mesa-gl-headers first!"
@@ -163,8 +157,7 @@ in stdenv.mkDerivation {
  '';

  outputs = [
    "out" "dev"
    "drivers"
    "out"
    # OpenCL drivers pull in ~1G of extra LLVM stuff, so don't install them
    # if the user didn't explicitly ask for it
    "opencl"
@@ -193,7 +186,6 @@ in stdenv.mkDerivation {

  mesonFlags = [
    "--sysconfdir=/etc"
    "--datadir=${placeholder "drivers"}/share"

    # What to build
    (lib.mesonOption "platforms" (lib.concatStringsSep "," eglPlatforms))
@@ -201,17 +193,10 @@ in stdenv.mkDerivation {
    (lib.mesonOption "vulkan-drivers" (lib.concatStringsSep "," vulkanDrivers))
    (lib.mesonOption "vulkan-layers" (lib.concatStringsSep "," vulkanLayers))

    # Make sure we know where to put all the drivers
    (lib.mesonOption "dri-drivers-path" "${placeholder "drivers"}/lib/dri")
    (lib.mesonOption "vdpau-libs-path" "${placeholder "drivers"}/lib/vdpau")
    (lib.mesonOption "va-libs-path" "${placeholder "drivers"}/lib/dri")
    (lib.mesonOption "d3d-drivers-path" "${placeholder "drivers"}/lib/d3d")

    # Set search paths for non-Mesa drivers (e.g. Nvidia)
    (lib.mesonOption "gbm-backends-path" "${libglvnd.driverLink}/lib/gbm:${placeholder "out"}/lib/gbm")

    # Enable glvnd for dynamic libGL dispatch
    (lib.mesonEnable "glvnd" true)
    (lib.mesonEnable "gbm" true)
    (lib.mesonBool "libgbm-external" true)

    (lib.mesonBool "gallium-nine" false) # Direct3D9 in Wine, largely supplanted by DXVK
    (lib.mesonBool "osmesa" false) # deprecated upstream
@@ -260,6 +245,8 @@ in stdenv.mkDerivation {
    elfutils
    expat
    spirv-tools
    libdrm
    libgbm
    libglvnd
    libunwind
    libva-minimal
@@ -326,109 +313,73 @@ in stdenv.mkDerivation {
    (buildPackages.mesa.cross_tools or null)
  ];

  propagatedBuildInputs = [ libdrm ];

  doCheck = false;

  postInstall = ''
    # Move driver-related bits to $drivers
    moveToOutput "lib/gallium-pipe" $drivers
    moveToOutput "lib/gbm" $drivers
    moveToOutput "lib/lib*_mesa*" $drivers
    moveToOutput "lib/libgallium*" $drivers
    moveToOutput "lib/libglapi*" $drivers
    moveToOutput "lib/libpowervr_rogue*" $drivers
    moveToOutput "lib/libvulkan_*" $drivers
    moveToOutput "lib/libteflon.so" $drivers

    # Update search path used by glvnd (it's pointing to $out but drivers are in $drivers)
    for js in $drivers/share/glvnd/egl_vendor.d/*.json; do
      substituteInPlace "$js" --replace-fail '"libEGL_' '"'"$drivers/lib/libEGL_"
    done

    # And same for Vulkan
    for js in $drivers/share/vulkan/icd.d/*.json; do
      substituteInPlace "$js" --replace-fail "$out" "$drivers"
    done

    # Move Vulkan layers to $drivers and update manifests
    moveToOutput "lib/libVkLayer*" $drivers
    for js in $drivers/share/vulkan/{im,ex}plicit_layer.d/*.json; do
      substituteInPlace "$js" --replace '"libVkLayer_' '"'"$drivers/lib/libVkLayer_"
    done

    # Construct our own .icd files that contain absolute paths.
    mkdir -p $opencl/etc/OpenCL/vendors/
    echo $opencl/lib/libMesaOpenCL.so > $opencl/etc/OpenCL/vendors/mesa.icd
    echo $opencl/lib/libRusticlOpenCL.so > $opencl/etc/OpenCL/vendors/rusticl.icd

    moveToOutput bin/intel_clc $cross_tools
    moveToOutput bin/mesa_clc $cross_tools
    moveToOutput bin/vtn_bindgen $cross_tools

    moveToOutput "lib/lib*OpenCL*" $opencl
    # Construct our own .icd files that contain absolute paths.
    mkdir -p $opencl/etc/OpenCL/vendors/
    echo $opencl/lib/libMesaOpenCL.so > $opencl/etc/OpenCL/vendors/mesa.icd
    echo $opencl/lib/libRusticlOpenCL.so > $opencl/etc/OpenCL/vendors/rusticl.icd

    moveToOutput bin/spirv2dxil $spirv2dxil
    moveToOutput "lib/libspirv_to_dxil*" $spirv2dxil
  '';

  postFixup = ''
    # set the default search path for DRI drivers; used e.g. by X server
    for pc in lib/pkgconfig/{dri,d3d}.pc; do
      [ -f "$dev/$pc" ] && substituteInPlace "$dev/$pc" --replace "$drivers" "${libglvnd.driverLink}"
    # set full path in EGL driver manifest
    for js in $out/share/glvnd/egl_vendor.d/*.json; do
      substituteInPlace "$js" --replace-fail '"libEGL_' '"'"$out/lib/libEGL_"
    done

    # and in Vulkan layer manifests
    for js in $out/share/vulkan/{im,ex}plicit_layer.d/*.json; do
      substituteInPlace "$js" --replace '"libVkLayer_' '"'"$out/lib/libVkLayer_"
    done

    # remove pkgconfig files for GL/EGL; they are provided by libGL.
    rm -f $dev/lib/pkgconfig/{gl,egl}.pc
    # remove DRI pkg-config file, provided by dri-pkgconfig-stub
    rm -f $out/lib/pkgconfig/dri.pc

    # remove headers moved to mesa-gl-headers
    for header in ${toString mesa-gl-headers.headers}; do
      rm -f $dev/$header
      rm -f $out/$header
    done

    # update symlinks pointing to libgallium in $out
    for link in $drivers/lib/dri/*_drv_video.so $drivers/lib/vdpau/*.so.1.0.0; do
      ln -sf $drivers/lib/libgallium*.so $link
    done
    # clean up after removing stuff
    find $out -type d -empty -delete

    # Don't depend on build python
    patchShebangs --host --update $out/bin/*

    # NAR doesn't support hard links, so convert them to symlinks to save space.
    jdupes --hard-links --link-soft --recurse "$drivers"

    # add RPATH so the drivers can find the moved libgallium and libdricore9
    # moved here to avoid problems with stripping patchelfed files
    for lib in $drivers/lib/*.so* $drivers/lib/*/*.so*; do
      if [[ ! -L "$lib" ]]; then
        patchelf --set-rpath "$(patchelf --print-rpath $lib):$drivers/lib" "$lib"
      fi
    done
    jdupes --hard-links --link-soft --recurse "$out"

    # add RPATH here so Zink can find libvulkan.so
    patchelf --add-rpath ${vulkan-loader}/lib $drivers/lib/libgallium*.so
    patchelf --add-rpath ${vulkan-loader}/lib $out/lib/libgallium*.so
  '';

  env.NIX_CFLAGS_COMPILE = toString ([
    "-UPIPE_SEARCH_DIR"
    "-DPIPE_SEARCH_DIR=\"${placeholder "drivers"}/lib/gallium-pipe\""
  ]);

  passthru = {
    inherit (libglvnd) driverLink;
    inherit llvmPackages;

    tests.devDoesNotDependOnLLVM = stdenv.mkDerivation {
      name = "mesa-dev-does-not-depend-on-llvm";
    # for compatibility
    drivers = lib.warn "`mesa.drivers` is deprecated, use `mesa` instead" mesa;

    tests.outDoesNotDependOnLLVM = stdenv.mkDerivation {
      name = "mesa-does-not-depend-on-llvm";
      buildCommand = ''
        echo ${mesa.dev} >>$out
        echo ${mesa} >>$out
      '';
      disallowedRequisites = [ llvmPackages.llvm mesa.drivers ];
      disallowedRequisites = [ llvmPackages.llvm ];
    };

    llvmpipeHook = makeSetupHook {
      name = "llvmpipe-hook";
      substitutions.drivers = mesa.drivers;
      substitutions.mesa = mesa;
    } ./llvmpipe-hook.sh;
  };
}
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
let
  common = import ./common.nix { inherit lib fetchFromGitLab; };
  headers = [
    "include/GL/internal/dri_interface.h"
    "include/EGL/eglext_angle.h"
    "include/EGL/eglmesaext.h"
  ];
Loading