| 1 |
{ stdenv, fetchFromGitHub, fetchgit, fetchurl, lib, cmake, git, perl, ninja, python3 }: |
| 2 |
|
| 3 |
let wasilibc = fetchFromGitHub { |
| 4 |
owner = "WebAssembly"; |
| 5 |
repo = "wasi-libc"; |
| 6 |
rev = "ad5133410f66b93a2381db5b542aad5e0964db96"; |
| 7 |
sha256 = "sha256-gw6flqJv4x//V3FdqDx6yXhYVQjJ2S2xx0tZShFjmsQ="; |
| 8 |
}; |
| 9 |
|
| 10 |
llvm-project = fetchFromGitHub { |
| 11 |
owner = "llvm"; |
| 12 |
repo = "llvm-project"; |
| 13 |
rev = "309f1e4ac8cca1ba1f0e28eeae8e2926dc387d04"; |
| 14 |
sha256 = "WwDcWRf7Gu7b2a17mHbke31xSHDYA7CHEi28gR+Zd90="; |
| 15 |
}; |
| 16 |
|
| 17 |
config = fetchgit { |
| 18 |
url = "https://git.savannah.gnu.org/git/config.git"; |
| 19 |
rev = "2593751ef276497e312d7c4ce7fd049614c7bf80"; |
| 20 |
sha256 = "1sh410ncfs9fwxw03m1r4lcm10iv305g0jb2bb2yvgzlpb28lsz9"; |
| 21 |
}; |
| 22 |
|
| 23 |
emscripten_new_cpp_patch = fetchurl { |
| 24 |
url = "https://raw.githubusercontent.com/emscripten-core/emscripten/a153b417d34cb6f872310f5969e522d255d7294a/system/lib/libcxx/new.cpp"; |
| 25 |
sha256 = "0ghdfdjx71gxsxhkl6y7ri9x841h32y140m9n2qjhd27p013sphb"; |
| 26 |
}; |
| 27 |
|
| 28 |
emscripten_new_delete_cppabi_patch = fetchurl { |
| 29 |
url = "https://raw.githubusercontent.com/emscripten-core/emscripten/a153b417d34cb6f872310f5969e522d255d7294a/system/lib/libcxxabi/src/stdlib_new_delete.cpp"; |
| 30 |
sha256 = "099d5458xcbrcrhv3l1643ms529753q1yrr6m349rcwd33ad6g9r"; |
| 31 |
}; |
| 32 |
|
| 33 |
in stdenv.mkDerivation { |
| 34 |
name = "wasi-sdk-0.0.0"; |
| 35 |
src = fetchFromGitHub { |
| 36 |
owner = "WebAssembly"; |
| 37 |
repo = "wasi-sdk"; |
| 38 |
rev = "77ba98a998cb9f2a63ab3a5f94bbabd069f65ff0"; |
| 39 |
sha256 = "sha256-IG0kxt6geu1Y7qHWSWjp0LrPevU8eC+kCS/yZD/j5YE="; |
| 40 |
fetchSubmodules = false; |
| 41 |
}; |
| 42 |
|
| 43 |
dontUseCmakeConfigure = true; |
| 44 |
dontUseNinjaBuild = true; |
| 45 |
dontUseNinjaInstall = true; |
| 46 |
dontStrip = true; |
| 47 |
WASM_CFLAGS = "-fPIC -D__wasi__=1 -D__wasm32__=1"; |
| 48 |
PREFIX = "${placeholder "out"}"; |
| 49 |
|
| 50 |
postPatch = '' |
| 51 |
rm -rf src/* |
| 52 |
cp -rf ${wasilibc} src/wasi-libc |
| 53 |
cp -rf ${llvm-project} src/llvm-project |
| 54 |
cp -rf ${config} src/config |
| 55 |
chmod -R +rw src/ |
| 56 |
sed -i -e 's/diff -wur.*//g' src/wasi-libc/Makefile |
| 57 |
cp ${emscripten_new_cpp_patch} src/llvm-project/libcxx/src/new.cpp |
| 58 |
cp ${emscripten_new_delete_cppabi_patch} src/llvm-project/libcxxabi/src/stdlib_new_delete.cpp |
| 59 |
|
| 60 |
substituteInPlace src/wasi-libc/Makefile \ |
| 61 |
--replace 'wasm32-wasi' 'wasm32-unknown-emscripten' |
| 62 |
|
| 63 |
substituteInPlace Makefile \ |
| 64 |
--replace 'DESTDIR=$(abspath build/install)' \ |
| 65 |
'DESTDIR=' \ |
| 66 |
--replace 'COMPILER_RT_HAS_FPIC_FLAG=OFF' \ |
| 67 |
'COMPILER_RT_HAS_FPIC_FLAG=ON' \ |
| 68 |
--replace 'DLIBCXXABI_ENABLE_PIC:BOOL=OFF' \ |
| 69 |
'DLIBCXXABI_ENABLE_PIC:BOOL=ON' \ |
| 70 |
--replace 'wasi-sysroot"' \ |
| 71 |
'wasi-sysroot -fPIC -fno-exceptions -D__wasi__=1 -D__wasm32__=1 -D_LIBCXXABI_NO_EXCEPTIONS=1"' \ |
| 72 |
--replace 'wasm32-wasi' \ |
| 73 |
'wasm32-unknown-emscripten' |
| 74 |
|
| 75 |
substituteInPlace wasi-sdk.cmake \ |
| 76 |
--replace 'wasm32-wasi' 'wasm32-unknown-emscripten' |
| 77 |
substituteInPlace src/llvm-project/libcxx/include/__locale \ |
| 78 |
--replace '<xlocale.h>' '<__support/musl/xlocale.h>' |
| 79 |
substituteInPlace src/llvm-project/libcxxabi/src/stdlib_new_delete.cpp \ |
| 80 |
--replace '__EMSCRIPTEN__' '__wasi__' || exit 1 |
| 81 |
substituteInPlace src/llvm-project/libcxx/src/new.cpp \ |
| 82 |
--replace '__EMSCRIPTEN__' '__wasi__' || exit 1 |
| 83 |
''; |
| 84 |
|
| 85 |
buildInputs = [ cmake git perl ninja python3 ]; |
| 86 |
installPhase = "true"; |
| 87 |
} |