Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / compilers / shaderc / default.nix
blob3a75c9b8c9592019b264cd6c52852925fed91cd5
1 { lib, stdenv, fetchFromGitHub, cmake, python3, autoSignDarwinBinariesHook, cctools }:
2 # Like many google projects, shaderc doesn't gracefully support separately compiled dependencies, so we can't easily use
3 # the versions of glslang and spirv-tools used by vulkan-loader. Exact revisions are taken from
4 # https://github.com/google/shaderc/blob/known-good/known_good.json
6 # Future work: extract and fetch all revisions automatically based on a revision of shaderc's known-good branch.
7 let
8   glslang = fetchFromGitHub {
9     owner = "KhronosGroup";
10     repo = "glslang";
11     rev = "728c689574fba7e53305b475cd57f196c1a21226";
12     hash = "sha256-BAgDQosiO3e4yy2DpQ6SjrJNrHTUDSduHFRvzWvd4v0=";
13   };
14   spirv-tools = fetchFromGitHub {
15     owner = "KhronosGroup";
16     repo = "SPIRV-Tools";
17     rev = "d9446130d5165f7fafcb3599252a22e264c7d4bd";
18     hash = "sha256-fuYhzfkWXDm1icLHifc32XZCNQ6Dj5f5WJslT2JoMbc=";
19   };
20   spirv-headers = fetchFromGitHub {
21     owner = "KhronosGroup";
22     repo = "SPIRV-Headers";
23     rev = "c214f6f2d1a7253bb0e9f195c2dc5b0659dc99ef";
24     hash = "sha256-/9EDOiqN6ZzDhRKP/Kv8D/BT2Cs7G8wyzEsGATLpmrA=";
25   };
27 stdenv.mkDerivation rec {
28   pname = "shaderc";
29   version = "2022.4";
31   outputs = [ "out" "lib" "bin" "dev" "static" ];
33   src = fetchFromGitHub {
34     owner = "google";
35     repo = "shaderc";
36     rev = "v${version}";
37     hash = "sha256-/p2gJ7Lnh8IfvwBwHPDtmfLJ8j+Rbv+Oxu9lxY6fxfk=";
38   };
40   patchPhase = ''
41     cp -r --no-preserve=mode ${glslang} third_party/glslang
42     cp -r --no-preserve=mode ${spirv-tools} third_party/spirv-tools
43     ln -s ${spirv-headers} third_party/spirv-tools/external/spirv-headers
44   '';
46   nativeBuildInputs = [ cmake python3 ]
47     ++ lib.optionals stdenv.isDarwin [ cctools ]
48     ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ autoSignDarwinBinariesHook ];
50   postInstall = ''
51     moveToOutput "lib/*.a" $static
52   '';
54   cmakeFlags = [ "-DSHADERC_SKIP_TESTS=ON" ];
56   # Fix the paths in .pc, even though it's unclear if all these .pc are really useful.
57   postFixup = ''
58     substituteInPlace "$dev"/lib/pkgconfig/*.pc \
59       --replace '=''${prefix}//' '=/' \
60       --replace "$dev/$dev/" "$dev/"
61   '';
63   meta = with lib; {
64     inherit (src.meta) homepage;
65     description = "A collection of tools, libraries and tests for shader compilation";
66     platforms = platforms.all;
67     license = [ licenses.asl20 ];
68   };