Distro for Linux for WebAssembly
1{
2 fetch,
3 run,
4 config,
5 lib,
6
7 bc,
8 bison,
9 clang-no-compiler-rt,
10 clang-host ? clang-no-compiler-rt,
11 esbuild,
12 findutils,
13 flex,
14 gnumake,
15 lld,
16 llvm,
17 perl,
18 rsync,
19 wabt,
20}:
21
22run
23 {
24 name = "linux";
25 src = fetch.github {
26 owner = "tombl";
27 repo = "linux";
28 rev = "refs/heads/wasm";
29 hash = "sha256-F01Q3JUJpWND38KgQ/SONnhNJxeItw8qg8xNsBnjXzU=";
30 };
31 path = [
32 bc
33 bison
34 clang-no-compiler-rt
35 esbuild
36 findutils
37 flex
38 gnumake
39 lld
40 llvm
41 perl
42 rsync
43 wabt
44 ];
45 outputs = [
46 "out"
47 "site"
48 "headers"
49 ];
50 }
51 ''
52 mkdir -p $site
53 cp -r tools/wasm/{run.js,public/*,src} $site
54 ln -sf $out $site/dist
55
56 make() {
57 command make -j$NIX_BUILD_CORES HOSTCC=${clang-host}/bin/clang TSC=true "$@"
58 }
59
60 config() {
61 sed -i "/CONFIG_$1=/d" .config
62 sed -i "/CONFIG_$1 is not set/d" .config
63 case $2 in
64 y|n) echo "CONFIG_$1=$2" >> .config ;;
65 *) echo "CONFIG_$1=\"$2\"" >> .config ;;
66 esac
67 }
68
69 if ! [ -f .config ]; then
70 make defconfig ${lib.optionalString config.debug "debug.config"}
71 config FILE_LOCKING y
72 fi
73
74 # this is a horrible dirty hack but there's some non-deterministic build failure
75 for i in $(seq 1 3); do
76 if make -C tools/wasm; then
77 break
78 fi
79 done
80
81 cp -r tools/wasm/dist $out
82 hash=$(cksum $out/index.js | cut -d' ' -f1)
83 sed -i "s/LIBRARY_VERSION/$hash/" $site/index.html
84
85 make headers_install INSTALL_HDR_PATH=$headers
86 ''