1{
2 stdenv,
3 buildPackages,
4 fetchFromGitHub,
5 lib,
6 firefox-unwrapped,
7 firefox-esr-unwrapped,
8}:
9
10let
11 pname = "wasilibc";
12 version = "22-unstable-2024-10-16";
13in
14stdenv.mkDerivation {
15 inherit pname version;
16
17 src = buildPackages.fetchFromGitHub {
18 owner = "WebAssembly";
19 repo = "wasi-libc";
20 rev = "98897e29fcfc81e2b12e487e4154ac99188330c4";
21 hash = "sha256-NFKhMJj/quvN3mR7lmxzA9w46KhX92iG0rQA9qDeS8I=";
22 fetchSubmodules = true;
23 };
24
25 outputs = [
26 "out"
27 "dev"
28 "share"
29 ];
30
31 # clang-13: error: argument unused during compilation: '-rtlib=compiler-rt' [-Werror,-Wunused-command-line-argument]
32 postPatch = ''
33 substituteInPlace Makefile \
34 --replace "-Werror" ""
35 '';
36
37 preBuild = ''
38 export SYSROOT_LIB=${builtins.placeholder "out"}/lib
39 export SYSROOT_INC=${builtins.placeholder "dev"}/include
40 export SYSROOT_SHARE=${builtins.placeholder "share"}/share
41 mkdir -p "$SYSROOT_LIB" "$SYSROOT_INC" "$SYSROOT_SHARE"
42 makeFlagsArray+=(
43 "SYSROOT_LIB:=$SYSROOT_LIB"
44 "SYSROOT_INC:=$SYSROOT_INC"
45 "SYSROOT_SHARE:=$SYSROOT_SHARE"
46 # https://bugzilla.mozilla.org/show_bug.cgi?id=1773200
47 "BULK_MEMORY_SOURCES:="
48 )
49
50 '';
51
52 enableParallelBuilding = true;
53
54 # We just build right into the install paths, per the `preBuild`.
55 dontInstall = true;
56
57 preFixup = ''
58 ln -s $share/share/undefined-symbols.txt $out/lib/wasi.imports
59 '';
60
61 passthru.tests = {
62 inherit firefox-unwrapped firefox-esr-unwrapped;
63 };
64
65 meta = with lib; {
66 changelog = "https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-${version}";
67 description = "WASI libc implementation for WebAssembly";
68 homepage = "https://wasi.dev";
69 platforms = platforms.wasi;
70 maintainers = with maintainers; [
71 matthewbauer
72 rvolosatovs
73 ];
74 license = with licenses; [
75 asl20
76 llvm-exception
77 mit
78 ];
79 };
80}