Merge pull request #56261 from eadwu/mesa/extract-stubs

mesa: extract stubs
This commit is contained in:
Matthew Bauer 2019-06-26 17:00:52 -04:00 committed by GitHub
commit 24fea40d92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 84 additions and 78 deletions

View File

@ -68,8 +68,9 @@ let
branch = head (splitString "." version); branch = head (splitString "." version);
in in
let self = stdenv.mkDerivation { stdenv.mkDerivation rec {
name = "mesa-${version}"; pname = "mesa";
inherit version;
src = fetchurl { src = fetchurl {
urls = [ urls = [
@ -228,80 +229,8 @@ let self = stdenv.mkDerivation {
''; '';
passthru = { passthru = {
inherit libdrm version; inherit libdrm;
inherit (libglvnd) driverLink; inherit (libglvnd) driverLink;
# Use stub libraries from libglvnd and headers from Mesa.
stubs = stdenv.mkDerivation {
name = "libGL-${libglvnd.version}";
outputs = [ "out" "dev" ];
# On macOS, libglvnd is not supported, so we just use what mesa
# build. We need to also include OpenGL.framework, and some
# extra tricks to go along with. We add mesas libGLX to support
# the X extensions to OpenGL.
buildCommand = if stdenv.hostPlatform.isDarwin then ''
mkdir -p $out/nix-support $dev
echo ${OpenGL} >> $out/nix-support/propagated-build-inputs
ln -s ${self.out}/lib $out/lib
mkdir -p $dev/lib/pkgconfig $dev/nix-support
echo "$out" > $dev/nix-support/propagated-build-inputs
ln -s ${self.dev}/include $dev/include
cat <<EOF >$dev/lib/pkgconfig/gl.pc
Name: gl
Description: gl library
Version: ${self.version}
Libs: -L${self.out}/lib -lGL
Cflags: -I${self.dev}/include
EOF
cat <<EOF >$dev/lib/pkgconfig/glesv1_cm.pc
Name: glesv1_cm
Description: glesv1_cm library
Version: ${self.version}
Libs: -L${self.out}/lib -lGLESv1_CM
Cflags: -I${self.dev}/include
EOF
cat <<EOF >$dev/lib/pkgconfig/glesv2.pc
Name: glesv2
Description: glesv2 library
Version: ${self.version}
Libs: -L${self.out}/lib -lGLESv2
Cflags: -I${self.dev}/include
EOF
''
# Otherwise, setup gl stubs to use libglvnd.
else ''
mkdir -p $out/nix-support
ln -s ${libglvnd.out}/lib $out/lib
mkdir -p $dev/{,lib/pkgconfig,nix-support}
echo "$out" > $dev/nix-support/propagated-build-inputs
ln -s ${self.dev}/include $dev/include
genPkgConfig() {
local name="$1"
local lib="$2"
cat <<EOF >$dev/lib/pkgconfig/$name.pc
Name: $name
Description: $lib library
Version: ${self.version}
Libs: -L${libglvnd.out}/lib -l$lib
Cflags: -I${self.dev}/include
EOF
}
genPkgConfig gl GL
genPkgConfig egl EGL
genPkgConfig glesv1_cm GLESv1_CM
genPkgConfig glesv2 GLESv2
'';
};
}; };
meta = with stdenv.lib; { meta = with stdenv.lib; {
@ -311,5 +240,5 @@ let self = stdenv.mkDerivation {
platforms = platforms.mesaPlatforms; platforms = platforms.mesaPlatforms;
maintainers = with maintainers; [ vcunat ]; maintainers = with maintainers; [ vcunat ];
}; };
}; }
in self

View File

@ -0,0 +1,75 @@
{ stdenv
, libglvnd, mesa
, OpenGL }:
stdenv.mkDerivation {
inherit (libglvnd) version;
pname = "libGL";
outputs = [ "out" "dev" ];
# On macOS, libglvnd is not supported, so we just use what mesa
# build. We need to also include OpenGL.framework, and some
# extra tricks to go along with. We add mesas libGLX to support
# the X extensions to OpenGL.
buildCommand = if stdenv.hostPlatform.isDarwin then ''
mkdir -p $out/nix-support $dev
echo ${OpenGL} >> $out/nix-support/propagated-build-inputs
ln -s ${mesa.out}/lib $out/lib
mkdir -p $dev/lib/pkgconfig $dev/nix-support
echo "$out" > $dev/nix-support/propagated-build-inputs
ln -s ${mesa.dev}/include $dev/include
cat <<EOF >$dev/lib/pkgconfig/gl.pc
Name: gl
Description: gl library
Version: ${mesa.version}
Libs: -L${mesa.out}/lib -lGL
Cflags: -I${mesa.dev}/include
EOF
cat <<EOF >$dev/lib/pkgconfig/glesv1_cm.pc
Name: glesv1_cm
Description: glesv1_cm library
Version: ${mesa.version}
Libs: -L${mesa.out}/lib -lGLESv1_CM
Cflags: -I${mesa.dev}/include
EOF
cat <<EOF >$dev/lib/pkgconfig/glesv2.pc
Name: glesv2
Description: glesv2 library
Version: ${mesa.version}
Libs: -L${mesa.out}/lib -lGLESv2
Cflags: -I${mesa.dev}/include
EOF
''
# Otherwise, setup gl stubs to use libglvnd.
else ''
mkdir -p $out/nix-support
ln -s ${libglvnd.out}/lib $out/lib
mkdir -p $dev/{,lib/pkgconfig,nix-support}
echo "$out" > $dev/nix-support/propagated-build-inputs
ln -s ${mesa.dev}/include $dev/include
genPkgConfig() {
local name="$1"
local lib="$2"
cat <<EOF >$dev/lib/pkgconfig/$name.pc
Name: $name
Description: $lib library
Version: ${mesa.version}
Libs: -L${libglvnd.out}/lib -l$lib
Cflags: -I${mesa.dev}/include
EOF
}
genPkgConfig gl GL
genPkgConfig egl EGL
genPkgConfig glesv1_cm GLESv1_CM
genPkgConfig glesv2 GLESv2
'';
}

View File

@ -12277,7 +12277,9 @@ in
# libGL.so/libEGL.so/... to link agains them. Android NDK provides # libGL.so/libEGL.so/... to link agains them. Android NDK provides
# an OpenGL implementation, we can just use that. # an OpenGL implementation, we can just use that.
libGL = if stdenv.hostPlatform.useAndroidPrebuilt then stdenv libGL = if stdenv.hostPlatform.useAndroidPrebuilt then stdenv
else mesa.stubs; else callPackage ../development/libraries/mesa/stubs.nix {
inherit (darwin.apple_sdk.frameworks) OpenGL;
};
# Default libGLU # Default libGLU
libGLU = mesa_glu; libGLU = mesa_glu;