1{ lib, stdenv
2, fetchFromGitHub
3, fetchpatch
4, bison
5, cmake
6, jq
7, python3
8, spirv-headers
9, spirv-tools
10}:
11stdenv.mkDerivation rec {
12 pname = "glslang";
13 version = "12.1.0";
14
15 src = fetchFromGitHub {
16 owner = "KhronosGroup";
17 repo = "glslang";
18 rev = version;
19 hash = "sha256-U45/7G02o82EP4zh7i2Go0VCnsO1B7vxDwIokjyo5Rk=";
20 };
21
22 # These get set at all-packages, keep onto them for child drvs
23 passthru = {
24 spirv-tools = spirv-tools;
25 spirv-headers = spirv-headers;
26 };
27
28 nativeBuildInputs = [ cmake python3 bison jq ];
29
30 patches = [
31 # Related PR: https://github.com/KhronosGroup/glslang/pull/3067
32 ./use-CMAKE_INSTALL_FULL_LIBDIR-in-compat-cmake-files.patch
33 # Upstream tries to detect the Darwin linker by checking for AppleClang, but it’s just Clang in nixpkgs.
34 # Revert the commit to allow the build to work on Darwin with the nixpkg Darwin Clang toolchain.
35 (fetchpatch {
36 name = "Fix-Darwin-linker-error.patch";
37 url = "https://github.com/KhronosGroup/glslang/commit/586baa35a47b3aa6ad3fa829a27f0f4206400668.patch";
38 hash = "sha256-paAl4E8GzogcxDEzn/XuhNH6XObp+i7WfArqAiuH4Mk=";
39 revert = true;
40 })
41 ];
42
43 postPatch = ''
44 cp --no-preserve=mode -r "${spirv-tools.src}" External/spirv-tools
45 ln -s "${spirv-headers.src}" External/spirv-tools/external/spirv-headers
46 '';
47
48 # This is a dirty fix for lib/cmake/SPIRVTargets.cmake:51 which includes this directory
49 postInstall = ''
50 mkdir $out/include/External
51 '';
52
53 # Fix the paths in .pc, even though it's unclear if these .pc are really useful.
54 postFixup = ''
55 substituteInPlace "$out"/lib/pkgconfig/SPIRV-Tools{,-shared}.pc \
56 --replace '=''${prefix}//' '=/'
57 '';
58
59 meta = with lib; {
60 inherit (src.meta) homepage;
61 description = "Khronos reference front-end for GLSL and ESSL";
62 license = licenses.asl20;
63 platforms = platforms.unix;
64 maintainers = [ maintainers.ralith ];
65 };
66}