summaryrefslogtreecommitdiff
path: root/modules/webgl/.nix/derivation.nix
blob: 3654615870d1733fa2daa2e9115b4acc78a12f3f (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
{ lib
, stdenv
, scons
, clang-tools
, emscripten
, python3
, nodejs
, pname
, version
, kel
}:

stdenv.mkDerivation {
	pname = "${pname}-webgl";
	inherit version;
	src = ./..;

	nativeBuildInputs = [
		scons
		clang-tools
		emscripten
		python3
		nodejs
	];

	# Deliberately empty. em++ is not a nix cc-wrapper, so it never reads
	# NIX_CFLAGS_COMPILE and cannot consume buildInputs the way core and sycl do.
	# Include roots are handed to scons explicitly below, which also has the
	# virtue of making the dependency visible rather than ambient.
	buildInputs = [ ];

	sconsFlags = [
		"kel_include=${kel.lbm.core.dev}/include:${kel.lbm.swarm.dev}/include"
	];

	# Same class of problem as the `export HOME="$TMPDIR"` AdaptiveCpp hack in
	# modules/sycl/.nix/derivation.nix: a toolchain that insists on a writable
	# cache inside a read-only build.
	#
	# emscripten's wrappers source locate_cache.sh, which points EM_CACHE at a
	# /tmp path. In the sandbox that is writable but empty, so emcc would
	# rebuild the entire sysroot for every target. Seed it from the cache the
	# emscripten derivation already precompiled (~81MB, with sysroot and
	# sysroot_install.stamp) and make it writable.
	preBuild = ''
		export HOME="$TMPDIR"
		export EM_CACHE="$TMPDIR/em_cache"
		cp -r ${emscripten}/share/emscripten/cache "$EM_CACHE"
		chmod -R u+w "$EM_CACHE"
	'';

	# Nothing here can run without a browser; the probe only has to link.
	doCheck = false;

	preferLocalBuild = true;

	outputs = [ "out" "dev" ];
}