1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 cmake,
6 python3,
7 autoSignDarwinBinariesHook,
8 cctools,
9}:
10# Like many google projects, shaderc doesn't gracefully support separately
11# compiled dependencies, so we can't easily use the versions of glslang and
12# spirv-tools used by vulkan-loader. Exact revisions are taken from
13# https://github.com/google/shaderc/blob/known-good/known_good.json
14
15# Future work: extract and fetch all revisions automatically based on a revision
16# of shaderc's known-good branch.
17let
18 glslang = fetchFromGitHub {
19 owner = "KhronosGroup";
20 repo = "glslang";
21 rev = "15.3.0";
22 hash = "sha256-HwFP4KJuA+BMQVvBWV0BCRj9U5I3CLEU+5bBtde2f6w=";
23 };
24 spirv-tools = fetchFromGitHub {
25 owner = "KhronosGroup";
26 repo = "SPIRV-Tools";
27 rev = "v2025.1";
28 hash = "sha256-2Wv0dxVQ8NvuDRTcsXkH1GKmuA6lsIuwTl0j6kbTefo=";
29 };
30 spirv-headers = fetchFromGitHub {
31 owner = "KhronosGroup";
32 repo = "SPIRV-Headers";
33 rev = "vulkan-sdk-1.4.309.0";
34 hash = "sha256-Q1i6i5XimULuGufP6mimwDW674anAETUiIEvDQwvg5Y=";
35 };
36in
37stdenv.mkDerivation (finalAttrs: {
38 pname = "shaderc";
39 version = "2025.2";
40
41 outputs = [
42 "out"
43 "lib"
44 "bin"
45 "dev"
46 "static"
47 ];
48
49 src = fetchFromGitHub {
50 owner = "google";
51 repo = "shaderc";
52 rev = "v${finalAttrs.version}";
53 hash = "sha256-u3gmH2lrkwBTZg9j4jInQceXK4MUWhKZPSPsN98mEkk=";
54 };
55
56 postPatch = ''
57 cp -r --no-preserve=mode ${glslang} third_party/glslang
58 cp -r --no-preserve=mode ${spirv-tools} third_party/spirv-tools
59 ln -s ${spirv-headers} third_party/spirv-tools/external/spirv-headers
60 patchShebangs --build utils/
61 '';
62
63 nativeBuildInputs = [
64 cmake
65 python3
66 ]
67 ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]
68 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
69 autoSignDarwinBinariesHook
70 ];
71
72 postInstall = ''
73 moveToOutput "lib/*.a" $static
74 '';
75
76 cmakeFlags = [ "-DSHADERC_SKIP_TESTS=ON" ];
77
78 # Fix the paths in .pc, even though it's unclear if all these .pc are really useful.
79 postFixup = ''
80 substituteInPlace "$dev"/lib/pkgconfig/*.pc \
81 --replace-fail '=''${prefix}//' '=/' \
82 --replace-fail "$dev/$dev/" "$dev/"
83 '';
84
85 meta = {
86 description = "Collection of tools, libraries and tests for shader compilation";
87 inherit (finalAttrs.src.meta) homepage;
88 license = lib.licenses.asl20;
89 platforms = lib.platforms.all;
90 };
91})