1{
2 pkgs,
3 lib,
4 emscripten,
5 python3,
6}:
7
8argsFun:
9
10let
11 wrapDerivation = f: pkgs.stdenv.mkDerivation (finalAttrs: f (lib.toFunction argsFun finalAttrs));
12in
13wrapDerivation (
14 {
15 buildInputs ? [ ],
16 nativeBuildInputs ? [ ],
17
18 enableParallelBuilding ? true,
19
20 meta ? { },
21 ...
22 }@args:
23
24 args
25 // {
26
27 pname = "emscripten-${lib.getName args}";
28 version = lib.getVersion args;
29 buildInputs = [
30 emscripten
31 python3
32 ] ++ buildInputs;
33 nativeBuildInputs = [
34 emscripten
35 python3
36 ] ++ nativeBuildInputs;
37
38 # fake conftest results with emscripten's python magic
39 EMCONFIGURE_JS = 2;
40
41 # removes archive indices
42 dontStrip = args.dontStrip or true;
43
44 configurePhase =
45 args.configurePhase or ''
46 # FIXME: Some tests require writing at $HOME
47 HOME=$TMPDIR
48 runHook preConfigure
49
50 emconfigure ./configure --prefix=$out
51
52 mkdir -p .emscriptencache
53 export EM_CACHE=$(pwd)/.emscriptencache
54
55 runHook postConfigure
56 '';
57
58 buildPhase =
59 args.buildPhase or ''
60 runHook preBuild
61
62 HOME=$TMPDIR
63
64 emmake make
65
66 runHook postBuild
67 '';
68
69 doCheck = true;
70
71 checkPhase =
72 args.checkPhase or ''
73 runHook preCheck
74
75 echo "Please provide a test for your emscripten based library/tool, see libxml2 as an exmple on how to use emcc/node to verify your build"
76 echo ""
77 echo "In normal C 'unresolved symbols' would yield an error and a breake of execution. In contrast, in emscripten they are only a warning which is ok given that emscripten assumptions about shared libraries."
78 echo " -> https://github.com/kripken/emscripten/wiki/Linking"
79 echo "So just assume the dependencies were built using hydra, then YOU WILL NEVER see the warning and your code depending on a library will always fail!"
80 exit 1
81
82 runHook postCheck
83 '';
84
85 enableParallelBuilding = args.enableParallelBuilding or true;
86
87 meta =
88 {
89 # Add default meta information
90 platforms = lib.platforms.all;
91 # Do not build this automatically
92 hydraPlatforms = [ ];
93 }
94 // meta
95 // {
96 # add an extra maintainer to every package
97 maintainers = (meta.maintainers or [ ]) ++ [ lib.maintainers.qknight ];
98 };
99 }
100)