@@ -0,0 +1,63 @@
1+{ stdenv, fetchgit, python3, cmake, jq, libX11, libXext }:
2+
3+stdenv.mkDerivation rec {
4+ pname = "swiftshader";
5+ version = "2020-06-17";
6+
7+ src = fetchgit {
8+ url = "https://swiftshader.googlesource.com/SwiftShader";
9+ rev = "763957e6b4fc1aa360ab19c4109b8b26686783e8";
10+ sha256 = "0sdh48swx0qyq2nfkv1nggs14am0qc7z239qrxb69p2ddqm76g1s";
11+ };
12+
13+ nativeBuildInputs = [ cmake python3 jq ];
14+ buildInputs = [ libX11 libXext ];
15+
16+ # Make sure we include the drivers and icd files in the output as the cmake
17+ # generated install command only puts in the spirv-tools stuff.
18+ installPhase = ''
19+ runHook preInstall
20+
21+ #
22+ # Vulkan driver
23+ #
24+ vk_so_path="$out/lib/libvk_swiftshader.so"
25+ mkdir -p "$(dirname "$vk_so_path")"
26+ mv Linux/libvk_swiftshader.so "$vk_so_path"
27+
28+ vk_icd_json="$out/share/vulkan/icd.d/vk_swiftshader_icd.json"
29+ mkdir -p "$(dirname "$vk_icd_json")"
30+ jq ".ICD.library_path = \"$vk_so_path\"" <Linux/vk_swiftshader_icd.json >"$vk_icd_json"
31+
32+ #
33+ # GL driver
34+ #
35+ gl_so_path="$out/lib/libEGL.so"
36+ mkdir -p "$(dirname "$gl_so_path")"
37+ mv Linux/libEGL.so "$gl_so_path"
38+
39+ gl_icd_json="$out/share/glvnd/egl_vendor.d/swiftshader.json"
40+ mkdir -p "$(dirname "$gl_icd_json")"
41+ cat >"$gl_icd_json" <<EOF
42+ {
43+ "file_format_version" : "1.0.0",
44+ "ICD" : {
45+ "library_path" : "$gl_so_path"
46+ }
47+ }
48+ EOF
49+
50+ runHook postInstall
51+ '';
52+
53+ meta = with stdenv.lib; {
54+ description =
55+ "A high-performance CPU-based implementation of the Vulkan, OpenGL ES, and Direct3D 9 graphics APIs";
56+ homepage = "https://opensource.google/projects/swiftshader";
57+ license = licenses.asl20;
58+ # Should be possible to support Darwin by changing the install phase with
59+ # 's/Linux/Darwin/' and 's/so/dylib/' or something similar.
60+ platforms = [ "i686-linux" "x86_64-linux" "armv7l-linux" "mipsel-linux" ];
61+ maintainers = with maintainers; [ expipiplus1 ];
62+ };
63+}