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 ]
33 ++ buildInputs;
34 nativeBuildInputs = [
35 emscripten
36 python3
37 ]
38 ++ nativeBuildInputs;
39
40 # fake conftest results with emscripten's python magic
41 EMCONFIGURE_JS = 2;
42
43 # removes archive indices
44 dontStrip = args.dontStrip or true;
45
46 configurePhase =
47 args.configurePhase or ''
48 # FIXME: Some tests require writing at $HOME
49 HOME=$TMPDIR
50 runHook preConfigure
51
52 emconfigure ./configure --prefix=$out
53
54 mkdir -p .emscriptencache
55 export EM_CACHE=$(pwd)/.emscriptencache
56
57 runHook postConfigure
58 '';
59
60 buildPhase =
61 args.buildPhase or ''
62 runHook preBuild
63
64 HOME=$TMPDIR
65
66 emmake make
67
68 runHook postBuild
69 '';
70
71 doCheck = true;
72
73 checkPhase =
74 args.checkPhase or ''
75 runHook preCheck
76
77 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"
78 echo ""
79 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."
80 echo " -> https://github.com/kripken/emscripten/wiki/Linking"
81 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!"
82 exit 1
83
84 runHook postCheck
85 '';
86
87 enableParallelBuilding = args.enableParallelBuilding or true;
88
89 meta = {
90 # Add default meta information
91 platforms = lib.platforms.all;
92 # Do not build this automatically
93 hydraPlatforms = [ ];
94 }
95 // meta
96 // {
97 # add an extra maintainer to every package
98 maintainers = (meta.maintainers or [ ]) ++ [ lib.maintainers.qknight ];
99 };
100 }
101)