summaryrefslogtreecommitdiff
path: root/shaderc_my.nix
blob: f4c6e0178fb40791a5cace08c17ae76fa63d27bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{ inputs }:
self: super: {
  shaderc_my =
    with super;
    let
      glslang = fetchGit {
        url = "https://github.com/KhronosGroup/glslang";
        ref = "main";
        rev = "963588074b26326ff0426c8953c1235213309bdb";
      };
      spirv-tools = fetchGit {
        url = "https://github.com/KhronosGroup/SPIRV-Tools";
        ref = "main";
        rev = "66fe610946a6d98169f8ebe9ca483f64c4009fa5";
      };
      spirv-headers = fetchGit {
        url = "https://github.com/KhronosGroup/SPIRV-Headers";
        ref = "main";
        rev = "c9aad99f9276817f18f72a4696239237c83cb775";
      };
    in
    stdenv.mkDerivation {
      pname = "shaderc";
      version = "git";

      outputs = [
        "out"
        "lib"
        "bin"
        "dev"
        "static"
      ];
      src = fetchGit {
        url = "https://github.com/google/shaderc";
        ref = "main";
        rev = "3362e24c42ab5bf7ad32c0fec64b0a0ddeb2fda1";
      };

      postPatch = ''
        cp -r --no-preserve=mode ${glslang} third_party/glslang
        cp -r --no-preserve=mode ${spirv-tools} third_party/spirv-tools
        ln -s ${spirv-headers} third_party/spirv-tools/external/spirv-headers
        patchShebangs --build utils/
      '';

      nativeBuildInputs =
        [
          cmake
          python3
        ]
        ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]
        ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
          autoSignDarwinBinariesHook
        ];

      postInstall = ''
        moveToOutput "lib/*.a" $static
      '';

      cmakeFlags = [ "-DSHADERC_SKIP_TESTS=ON" ];

      # Fix the paths in .pc, even though it's unclear if all these .pc are really useful.
      postFixup = ''
        substituteInPlace "$dev"/lib/pkgconfig/*.pc \
          --replace '=''${prefix}//' '=/' \
          --replace "$dev/$dev/" "$dev/"
      '';

      meta = with lib; {
        inherit (src.meta) homepage;
        description = "Collection of tools, libraries and tests for shader compilation";
        platforms = platforms.all;
        license = [ licenses.asl20 ];
      };
    };
}