2019-03-26 16:41:50 -07:00
|
|
|
{ stdenv, lib, fetchurl, fetchpatch
|
|
|
|
, pkgconfig, intltool, ninja, meson
|
|
|
|
, file, flex, bison, expat, libdrm, xorg, wayland, wayland-protocols, openssl
|
2018-02-08 20:05:38 -08:00
|
|
|
, llvmPackages, libffi, libomxil-bellagio, libva-minimal
|
2019-03-26 16:41:50 -07:00
|
|
|
, libelf, libvdpau, python3Packages
|
2018-03-17 08:44:40 -07:00
|
|
|
, libglvnd
|
2017-10-07 06:19:13 -07:00
|
|
|
, enableRadv ? true
|
2017-02-15 05:25:16 -08:00
|
|
|
, galliumDrivers ? null
|
|
|
|
, driDrivers ? null
|
|
|
|
, vulkanDrivers ? null
|
2018-08-25 13:53:30 -07:00
|
|
|
, eglPlatforms ? [ "x11" ] ++ lib.optionals stdenv.isLinux [ "wayland" "drm" ]
|
|
|
|
, OpenGL, Xplugin
|
2019-05-08 18:47:11 -07:00
|
|
|
, withValgrind ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAarch32, valgrind-light
|
2013-05-16 08:16:02 -07:00
|
|
|
}:
|
2004-06-09 10:53:30 -07:00
|
|
|
|
2013-05-16 08:16:02 -07:00
|
|
|
/** Packaging design:
|
2018-03-05 05:53:38 -08:00
|
|
|
- The basic mesa ($out) contains headers and libraries (GLU is in libGLU now).
|
2014-01-28 02:34:05 -08:00
|
|
|
This or the mesa attribute (which also contains GLU) are small (~ 2 MB, mostly headers)
|
2013-05-16 08:16:02 -07:00
|
|
|
and are designed to be the buildInput of other packages.
|
2015-02-22 10:11:38 -08:00
|
|
|
- DRI drivers are compiled into $drivers output, which is much bigger and
|
|
|
|
depends on LLVM. These should be searched at runtime in
|
|
|
|
"/run/opengl-driver{,-32}/lib/*" and so are kind-of impure (given by NixOS).
|
2013-05-16 08:16:02 -07:00
|
|
|
(I suppose on non-NixOS one would create the appropriate symlinks from there.)
|
2014-01-28 02:34:05 -08:00
|
|
|
- libOSMesa is in $osmesa (~4 MB)
|
2013-05-16 08:16:02 -07:00
|
|
|
*/
|
|
|
|
|
2016-08-24 04:35:30 -07:00
|
|
|
with stdenv.lib;
|
|
|
|
|
2017-02-15 05:25:16 -08:00
|
|
|
let
|
2018-08-22 14:48:38 -07:00
|
|
|
# platforms that have PCIe slots and thus can use most non-integrated GPUs
|
2019-05-02 14:37:20 -07:00
|
|
|
pciePlatform = !stdenv.hostPlatform.isAarch32 && !stdenv.hostPlatform.isAarch64;
|
|
|
|
defaultGalliumDrivers = optionals (elem "drm" eglPlatforms) ([ "virgl" ]
|
2018-08-22 14:48:38 -07:00
|
|
|
++ lib.optionals pciePlatform [ "r300" "r600" "radeonsi" ]
|
2019-05-02 14:37:20 -07:00
|
|
|
++ lib.optionals (pciePlatform || stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isAarch64) [ "nouveau" ]
|
2019-03-26 16:41:50 -07:00
|
|
|
++ lib.optionals stdenv.hostPlatform.isx86 [ "svga" ]
|
2019-05-02 14:37:20 -07:00
|
|
|
++ lib.optionals (stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isAarch64) [ "vc4" ]
|
|
|
|
++ lib.optionals stdenv.hostPlatform.isAarch64 [ "freedreno" "etnaviv" "imx" ]
|
|
|
|
);
|
|
|
|
defaultDriDrivers = optionals (elem "drm" eglPlatforms) ([ ]
|
2019-03-26 16:41:50 -07:00
|
|
|
++ lib.optionals pciePlatform [ "r200" ]
|
2019-05-02 14:37:20 -07:00
|
|
|
++ lib.optionals (pciePlatform || stdenv.hostPlatform.isAarch32 || stdenv.hostPlatform.isAarch64) [ "nouveau" ]
|
|
|
|
++ lib.optionals stdenv.hostPlatform.isx86 [ "i915" "i965" ]);
|
|
|
|
defaultVulkanDrivers = optionals stdenv.hostPlatform.isLinux ([ ]
|
|
|
|
++ lib.optional stdenv.hostPlatform.isx86 "intel"
|
2019-03-26 16:41:50 -07:00
|
|
|
++ lib.optional enableRadv "amd");
|
2017-02-15 05:25:16 -08:00
|
|
|
in
|
|
|
|
|
|
|
|
let gallium_ = galliumDrivers; dri_ = driDrivers; vulkan_ = vulkanDrivers; in
|
|
|
|
|
|
|
|
let
|
|
|
|
galliumDrivers =
|
2017-10-10 11:34:38 -07:00
|
|
|
(if gallium_ == null
|
2017-02-15 05:25:16 -08:00
|
|
|
then defaultGalliumDrivers
|
|
|
|
else gallium_)
|
2018-08-25 13:53:30 -07:00
|
|
|
++ lib.optional stdenv.isLinux "swrast";
|
2017-02-15 05:25:16 -08:00
|
|
|
driDrivers =
|
|
|
|
(if dri_ == null
|
2018-08-25 13:53:30 -07:00
|
|
|
then optionals (elem "drm" eglPlatforms) defaultDriDrivers
|
2019-03-26 16:41:50 -07:00
|
|
|
else dri_);
|
2017-02-15 05:25:16 -08:00
|
|
|
vulkanDrivers =
|
|
|
|
if vulkan_ == null
|
|
|
|
then defaultVulkanDrivers
|
|
|
|
else vulkan_;
|
|
|
|
in
|
|
|
|
|
2013-01-28 08:38:42 -08:00
|
|
|
let
|
2019-02-18 14:06:39 -08:00
|
|
|
version = "18.3.4";
|
2016-08-24 04:35:30 -07:00
|
|
|
branch = head (splitString "." version);
|
2013-01-28 08:38:42 -08:00
|
|
|
in
|
2013-10-05 12:18:07 -07:00
|
|
|
|
2019-06-12 14:18:19 -07:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "mesa";
|
|
|
|
inherit version;
|
2010-04-29 07:57:02 -07:00
|
|
|
|
2013-10-05 12:18:07 -07:00
|
|
|
src = fetchurl {
|
2015-01-24 13:37:16 -08:00
|
|
|
urls = [
|
2017-03-07 12:48:18 -08:00
|
|
|
"ftp://ftp.freedesktop.org/pub/mesa/mesa-${version}.tar.xz"
|
2015-03-28 13:57:03 -07:00
|
|
|
"ftp://ftp.freedesktop.org/pub/mesa/${version}/mesa-${version}.tar.xz"
|
2016-08-24 04:35:30 -07:00
|
|
|
"ftp://ftp.freedesktop.org/pub/mesa/older-versions/${branch}.x/${version}/mesa-${version}.tar.xz"
|
2017-11-13 09:49:46 -08:00
|
|
|
"https://mesa.freedesktop.org/archive/mesa-${version}.tar.xz"
|
2015-01-24 13:37:16 -08:00
|
|
|
];
|
2019-02-18 14:06:39 -08:00
|
|
|
sha256 = "01xv03ah4l5lcfx015n3fg1620dh4nbbv6gmhh6zhdsx6sj4sc9j";
|
2007-02-26 09:05:27 -08:00
|
|
|
};
|
2010-01-13 04:43:17 -08:00
|
|
|
|
2012-01-16 09:48:33 -08:00
|
|
|
prePatch = "patchShebangs .";
|
2011-07-14 05:22:55 -07:00
|
|
|
|
2016-08-24 04:35:30 -07:00
|
|
|
# TODO:
|
|
|
|
# revive ./dricore-gallium.patch when it gets ported (from Ubuntu), as it saved
|
|
|
|
# ~35 MB in $drivers; watch https://launchpad.net/ubuntu/+source/mesa/+changelog
|
2014-01-28 02:34:05 -08:00
|
|
|
patches = [
|
2018-07-18 07:41:21 -07:00
|
|
|
./missing-includes.patch # dev_t needs sys/stat.h, time_t needs time.h, etc.-- fixes build w/musl
|
2019-03-26 16:41:50 -07:00
|
|
|
./opencl-install-dir.patch
|
2018-08-06 12:23:02 -07:00
|
|
|
./disk_cache-include-dri-driver-path-in-cache-key.patch
|
2019-03-26 16:41:50 -07:00
|
|
|
] # do not prefix user provided dri-drivers-path
|
|
|
|
++ lib.optional (lib.versionOlder version "19.0.0") (fetchpatch {
|
|
|
|
url = "https://gitlab.freedesktop.org/mesa/mesa/commit/f6556ec7d126b31da37c08d7cb657250505e01a0.patch";
|
|
|
|
sha256 = "0z6phi8hbrbb32kkp1js7ggzviq7faz1ria36wi4jbc4in2392d9";
|
|
|
|
})
|
|
|
|
++ lib.optionals (lib.versionOlder version "19.1.0") [
|
|
|
|
# do not prefix user provided d3d-drivers-path
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://gitlab.freedesktop.org/mesa/mesa/commit/dcc48664197c7e44684ccfb970a4ae083974d145.patch";
|
|
|
|
sha256 = "1nhs0xpx3hiy8zfb5gx1zd7j7xha6h0hr7yingm93130a5902lkb";
|
|
|
|
})
|
|
|
|
|
|
|
|
# don't build libGLES*.so with GLVND
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://gitlab.freedesktop.org/mesa/mesa/commit/b01524fff05eef66e8cd24f1c5aacefed4209f03.patch";
|
|
|
|
sha256 = "1pszr6acx2xw469zq89n156p3bf3xf84qpbjw5fr1sj642lbyh7c";
|
|
|
|
})
|
|
|
|
];
|
2013-05-16 08:16:02 -07:00
|
|
|
|
2018-08-25 13:53:30 -07:00
|
|
|
outputs = [ "out" "dev" "drivers" ]
|
|
|
|
++ lib.optional (elem "swrast" galliumDrivers) "osmesa";
|
2013-05-16 08:16:02 -07:00
|
|
|
|
2016-08-24 04:35:30 -07:00
|
|
|
# TODO: Figure out how to enable opencl without having a runtime dependency on clang
|
2019-03-26 16:41:50 -07:00
|
|
|
mesonFlags = [
|
|
|
|
"--sysconfdir=/etc"
|
|
|
|
|
|
|
|
# Don't build in debug mode
|
|
|
|
# https://gitlab.freedesktop.org/mesa/mesa/blob/master/docs/meson.html#L327
|
|
|
|
"-Db_ndebug=true"
|
|
|
|
|
|
|
|
"-Ddisk-cache-key=${placeholder "drivers"}"
|
|
|
|
"-Ddri-search-path=${libglvnd.driverLink}/lib/dri"
|
|
|
|
|
|
|
|
"-Dplatforms=${concatStringsSep "," eglPlatforms}"
|
|
|
|
"-Ddri-drivers=${concatStringsSep "," driDrivers}"
|
|
|
|
"-Dgallium-drivers=${concatStringsSep "," galliumDrivers}"
|
|
|
|
"-Dvulkan-drivers=${concatStringsSep "," vulkanDrivers}"
|
|
|
|
|
|
|
|
"-Ddri-drivers-path=${placeholder "drivers"}/lib/dri"
|
|
|
|
"-Dvdpau-libs-path=${placeholder "drivers"}/lib/vdpau"
|
|
|
|
"-Dxvmc-libs-path=${placeholder "drivers"}/lib"
|
|
|
|
"-Domx-libs-path=${placeholder "drivers"}/lib/bellagio"
|
|
|
|
"-Dva-libs-path=${placeholder "drivers"}/lib/dri"
|
|
|
|
"-Dd3d-drivers-path=${placeholder "drivers"}/lib/d3d"
|
|
|
|
|
|
|
|
"-Dgallium-vdpau=true"
|
|
|
|
"-Dgallium-xvmc=true"
|
|
|
|
"-Dgallium-opencl=disabled"
|
|
|
|
"-Dshared-glapi=true"
|
|
|
|
"-Dgles1=true"
|
|
|
|
"-Dgles2=true"
|
|
|
|
"-Dglx=dri"
|
|
|
|
"-Dglvnd=true"
|
|
|
|
"-Dllvm=true"
|
|
|
|
"-Dshared-llvm=true"
|
|
|
|
"-Dglx-direct=true"
|
|
|
|
] ++ optional (elem "swrast" galliumDrivers) "-Dosmesa=gallium" # used by wine
|
|
|
|
++ optionals (stdenv.isLinux) [
|
|
|
|
"-Ddri3=true"
|
|
|
|
"-Dgallium-omx=bellagio"
|
|
|
|
"-Dgallium-va=true"
|
|
|
|
"-Dgallium-xa=true" # used in vmware driver
|
|
|
|
"-Dgallium-nine=true" # Direct3D in Wine
|
|
|
|
"-Dgbm=true"
|
|
|
|
"-Degl=true"
|
|
|
|
];
|
2015-03-28 13:57:03 -07:00
|
|
|
|
2013-05-16 08:16:02 -07:00
|
|
|
buildInputs = with xorg; [
|
2018-12-30 19:40:47 -08:00
|
|
|
expat llvmPackages.llvm libglvnd xorgproto
|
2018-09-21 11:25:12 -07:00
|
|
|
libX11 libXext libxcb libXt libXfixes libxshmfence libXrandr
|
2018-08-25 13:53:30 -07:00
|
|
|
libffi libvdpau libelf libXvMC
|
2018-12-09 07:18:34 -08:00
|
|
|
libpthreadstubs openssl /*or another sha1 provider*/
|
2018-11-18 07:36:24 -08:00
|
|
|
] ++ lib.optionals (elem "wayland" eglPlatforms) [ wayland wayland-protocols ]
|
2019-05-08 18:47:11 -07:00
|
|
|
++ lib.optionals stdenv.isLinux [ libomxil-bellagio libva-minimal ]
|
|
|
|
++ lib.optional withValgrind valgrind-light;
|
2010-04-29 07:57:02 -07:00
|
|
|
|
2019-03-26 16:41:50 -07:00
|
|
|
nativeBuildInputs = [
|
|
|
|
pkgconfig meson ninja
|
|
|
|
intltool bison flex file
|
|
|
|
python3Packages.python python3Packages.Mako
|
|
|
|
];
|
|
|
|
|
|
|
|
propagatedBuildInputs = with xorg; [
|
|
|
|
libXdamage libXxf86vm
|
|
|
|
] ++ optional stdenv.isLinux libdrm
|
|
|
|
++ optionals stdenv.isDarwin [ OpenGL Xplugin ];
|
|
|
|
|
2011-02-18 01:16:11 -08:00
|
|
|
enableParallelBuilding = true;
|
2015-02-22 10:11:38 -08:00
|
|
|
doCheck = false;
|
2013-05-16 08:16:02 -07:00
|
|
|
|
2019-01-04 21:25:48 -08:00
|
|
|
postInstall = ''
|
|
|
|
# Some installs don't have any drivers so this directory is never created.
|
|
|
|
mkdir -p $drivers
|
|
|
|
'' + optionalString (galliumDrivers != []) ''
|
2019-03-26 16:41:50 -07:00
|
|
|
mkdir -p $drivers/lib
|
|
|
|
|
2016-08-24 04:35:30 -07:00
|
|
|
# move gallium-related stuff to $drivers, so $out doesn't depend on LLVM
|
2019-03-26 16:41:50 -07:00
|
|
|
mv -t $drivers/lib \
|
2016-08-24 04:35:30 -07:00
|
|
|
$out/lib/libxatracker* \
|
2016-11-21 12:14:19 -08:00
|
|
|
$out/lib/libvulkan_*
|
2016-10-05 15:33:10 -07:00
|
|
|
|
2018-03-17 08:44:40 -07:00
|
|
|
# Move other drivers to a separate output
|
|
|
|
mv $out/lib/lib*_mesa* $drivers/lib
|
2013-05-22 08:09:00 -07:00
|
|
|
|
2016-08-24 04:35:30 -07:00
|
|
|
# move libOSMesa to $osmesa, as it's relatively big
|
2019-03-26 16:41:50 -07:00
|
|
|
mkdir -p $osmesa/lib
|
2016-08-24 04:35:30 -07:00
|
|
|
mv -t $osmesa/lib/ $out/lib/libOSMesa*
|
2013-11-17 01:53:41 -08:00
|
|
|
|
2018-03-17 08:44:40 -07:00
|
|
|
# move vendor files
|
2017-01-27 03:51:16 -08:00
|
|
|
mv $out/share/ $drivers/
|
2018-03-17 08:44:40 -07:00
|
|
|
|
|
|
|
# Update search path used by glvnd
|
|
|
|
for js in $drivers/share/glvnd/egl_vendor.d/*.json; do
|
|
|
|
substituteInPlace "$js" --replace '"libEGL_' '"'"$drivers/lib/libEGL_"
|
|
|
|
done
|
|
|
|
'' + optionalString (vulkanDrivers != []) ''
|
2017-01-27 03:51:16 -08:00
|
|
|
# Update search path used by Vulkan (it's pointing to $out but
|
|
|
|
# drivers are in $drivers)
|
|
|
|
for js in $drivers/share/vulkan/icd.d/*.json; do
|
|
|
|
substituteInPlace "$js" --replace "$out" "$drivers"
|
|
|
|
done
|
2015-04-14 13:41:22 -07:00
|
|
|
'';
|
2013-05-22 08:09:00 -07:00
|
|
|
|
2016-08-24 04:35:30 -07:00
|
|
|
# TODO:
|
|
|
|
# check $out doesn't depend on llvm: builder failures are ignored
|
|
|
|
# for some reason grep -qv '${llvmPackages.llvm}' -R "$out";
|
2018-08-25 13:53:30 -07:00
|
|
|
postFixup = optionalString (galliumDrivers != []) ''
|
2019-03-26 16:41:50 -07:00
|
|
|
# set the default search path for DRI drivers; used e.g. by X server
|
|
|
|
substituteInPlace "$dev/lib/pkgconfig/dri.pc" --replace "$drivers" "${libglvnd.driverLink}"
|
|
|
|
|
|
|
|
# remove pkgconfig files for GL/EGL; they are provided by libGL.
|
|
|
|
rm $dev/lib/pkgconfig/{gl,egl}.pc
|
|
|
|
|
|
|
|
# Update search path used by pkg-config
|
|
|
|
for pc in $dev/lib/pkgconfig/{d3d,dri,xatracker}.pc; do
|
|
|
|
substituteInPlace "$pc" --replace $out $drivers
|
|
|
|
done
|
|
|
|
|
2015-04-14 13:41:22 -07:00
|
|
|
# add RPATH so the drivers can find the moved libgallium and libdricore9
|
|
|
|
# moved here to avoid problems with stripping patchelfed files
|
2013-05-16 08:16:02 -07:00
|
|
|
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
|
|
|
|
'';
|
2011-02-18 01:16:11 -08:00
|
|
|
|
2018-03-17 08:44:40 -07:00
|
|
|
passthru = {
|
2019-06-12 14:18:19 -07:00
|
|
|
inherit libdrm;
|
2018-03-17 08:44:40 -07:00
|
|
|
inherit (libglvnd) driverLink;
|
|
|
|
};
|
2010-04-29 07:57:02 -07:00
|
|
|
|
2015-04-14 13:41:22 -07:00
|
|
|
meta = with stdenv.lib; {
|
2008-03-01 09:44:50 -08:00
|
|
|
description = "An open source implementation of OpenGL";
|
2018-01-05 11:42:46 -08:00
|
|
|
homepage = https://www.mesa3d.org/;
|
2015-04-14 13:41:22 -07:00
|
|
|
license = licenses.mit; # X11 variant, in most files
|
2019-05-08 18:46:31 -07:00
|
|
|
platforms = platforms.mesaPlatforms;
|
2018-07-11 14:22:57 -07:00
|
|
|
maintainers = with maintainers; [ vcunat ];
|
2007-11-05 15:59:55 -08:00
|
|
|
};
|
2019-06-12 14:18:19 -07:00
|
|
|
}
|