22 lib ,
33 stdenv ,
44 fetchFromGitHub ,
5+ fetchurl ,
56 rustPlatform ,
67 cargo ,
78 rustc ,
8- llvmPackages_18 ,
9+ nix-update ,
10+ curl ,
11+ writeShellApplication ,
12+ llvmPackages_21 ,
913 libffi ,
1014 libxml2 ,
1115 withLLVM ?
1216 stdenv . hostPlatform . isLinux || ( stdenv . hostPlatform . isDarwin && stdenv . hostPlatform . isx86_64 ) ,
17+ withV8 ? ( stdenv . hostPlatform . isLinux && stdenv . hostPlatform . isx86_64 ) ,
1318} :
1419
15- stdenv . mkDerivation ( finalAttrs : {
20+ let
21+ v8Version = "11.9.2" ;
22+
23+ # Prebuilt V8 from wasmerio's custom builds, only evaluated when withV8 = true.
24+
25+ # Per-platform hashes, auto-updated via the general updateScript
26+ v8Hashes = {
27+ "v8-linux-amd64.tar.xz" = "sha256-nTCVdBKtyVMb7lE+Db4RDsShKkLbG/0r980ejd+EAvo=" ;
28+ "v8-linux-musl-amd64.tar.xz" = "sha256-XgRs3I46B2PG7Jrv5E+KSeuNfXLhgB7R66cAkA/Bvv8=" ;
29+ "v8-darwin-arm64.tar.xz" = "sha256-xAG1PcAGw8a0A9k8d78/whTUXnqdfRZBz8yrg/+iz0M=" ;
30+ } ;
31+
32+ v8Prebuilt =
33+ let
34+ assetName =
35+ if stdenv . hostPlatform . isLinux && stdenv . hostPlatform . isx86_64 && stdenv . hostPlatform . isMusl then
36+ "v8-linux-musl-amd64.tar.xz"
37+ else if stdenv . hostPlatform . isLinux && stdenv . hostPlatform . isx86_64 then
38+ "v8-linux-amd64.tar.xz"
39+ else if stdenv . hostPlatform . isDarwin && stdenv . hostPlatform . isAarch64 then
40+ "v8-darwin-arm64.tar.xz"
41+ else
42+ throw "withV8 = true is not supported on ${ stdenv . hostPlatform . system } " ;
43+ in
44+ stdenv . mkDerivation {
45+ name = "wasmer-v8-prebuilt-${ v8Version } " ;
46+ src = fetchurl {
47+ url = "https://github.com/wasmerio/v8-custom-builds/releases/download/${ v8Version } /${ assetName } " ;
48+ hash = v8Hashes . ${ assetName } ;
49+ } ;
50+ sourceRoot = "." ;
51+ dontBuild = true ;
52+ installPhase = ''
53+ cp -r . $out
54+ '' ;
55+ } ;
56+ in
57+
58+ stdenv . mkDerivation ( finalAttrs : {
1659 pname = "wasmer" ;
17- version = "6.0.1" ;
60+ version = "7.1.0" ;
61+
62+ __structuredAttrs = true ;
63+ strictDeps = true ;
1864
1965 src = fetchFromGitHub {
2066 owner = "wasmerio" ;
2167 repo = "wasmer" ;
2268 tag = "v${ finalAttrs . version } " ;
23- hash = "sha256-nw/4hcEDkAabcpatVBRozxvVLzYOKbj3ylrGeQtNzMQ=" ;
69+ hash = "sha256-A1SkZY+iSR9xlu6R1p9uZYsGFPAOifuYTHtEXaEgves=" ;
70+ fetchSubmodules = true ;
2471 } ;
2572
2673 cargoDeps = rustPlatform . fetchCargoVendor {
2774 inherit ( finalAttrs ) pname version src ;
28- hash = "sha256-Nui8KxDk4+sqcmzeoZ6hGRb9Ux71+Nckz8seqq07cdE =" ;
75+ hash = "sha256-wBEwGKjj9DdZESFlXS8T7B0Xdp7yMe08DYTGr4wnTVI =" ;
2976 } ;
3077
3178 nativeBuildInputs = [
@@ -36,28 +83,71 @@ stdenv.mkDerivation (finalAttrs: {
3683 ] ;
3784
3885 buildInputs = lib . optionals withLLVM [
39- llvmPackages_18 . llvm
86+ llvmPackages_21 . llvm
4087 libffi
4188 libxml2
4289 ] ;
4390
91+ # In 7.1.0 there is no nice flag to toggle napi/v8 on or off,
92+ # so we manually delete the Makefile entry when we don't want v8
93+ # TODO: v7.2.0 pre-release has a flag, when updating to 7.2.0
94+ # add "ENABLE_NAPI_V8=${if withV8 then "1" else "0"}" to makeFlags
95+ postPatch =
96+ lib . optionalString ( ! withV8 ) ''
97+ substituteInPlace Makefile \
98+ --replace-fail ' build_wasmer_extra_features += napi-v8' ""
99+ ''
100+ + lib . optionalString stdenv . hostPlatform . isDarwin ''
101+ substituteInPlace Makefile \
102+ --replace-fail 'install: install-wasmer install-capi-headers install-capi-lib install-pkgconfig install-misc' \
103+ 'install: install-wasmer install-capi-headers install-misc'
104+ '' ;
105+
44106 makeFlags = [
45107 "WASMER_INSTALL_PREFIX=${ placeholder "out" } "
46108 "DESTDIR=${ placeholder "out" } "
109+ "ENABLE_LLVM=${ if withLLVM then "1" else "0" } "
47110 ] ;
48111
112+ # Default all target includes headless C API which doesn't get installed
113+ # by their Makefile and is quite niche to include, so we opt out
49114 buildFlags = [
50- "ENABLE_LLVM=${ if withLLVM then "1" else "0" } "
115+ "build-wasmer"
116+ "build-capi"
51117 ] ;
52118
53- env = lib . optionalAttrs withLLVM {
54- LLVM_SYS_180_PREFIX = llvmPackages_18 . llvm . dev ;
55- } ;
119+ env =
120+ lib . optionalAttrs withLLVM {
121+ LLVM_SYS_211_PREFIX = llvmPackages_21 . llvm . dev ;
122+ }
123+ // lib . optionalAttrs withV8 {
124+ # build.rs skips the download when these are set; see resolve_explicit_v8 in lib/napi/build.rs
125+ NAPI_V8_INCLUDE_DIR = "${ v8Prebuilt } /include" ;
126+ V8_LIB_DIR = "${ v8Prebuilt } /lib" ;
127+ } ;
128+
129+ postInstall = lib . optionalString stdenv . hostPlatform . isDarwin ''
130+ install -Dm755 target/release/libwasmer.dylib $out/lib/libwasmer.dylib
131+ if pc="$(WASMER_DIR="" target/release/wasmer config --pkg-config 2>/dev/null)"; then
132+ mkdir -p "$out/lib/pkgconfig"
133+ printf '%s\n' "$pc" > "$out/lib/pkgconfig/wasmer.pc"
134+ fi
135+ '' ;
136+
137+ passthru . updateScript = lib . getExe ( writeShellApplication {
138+ name = "update-wasmer" ;
139+ runtimeInputs = [
140+ nix-update
141+ curl
142+ ] ;
143+ text = builtins . readFile ./update.sh ;
144+ } ) ;
56145
57146 # Tests are failing due to `Cannot allocate memory` and other reasons
58147 doCheck = false ;
59148
60149 meta = {
150+ sourceProvenance = with lib . sourceTypes ; [ fromSource ] ++ lib . optional withV8 binaryNativeCode ;
61151 description = "Universal WebAssembly Runtime" ;
62152 mainProgram = "wasmer" ;
63153 longDescription = ''
0 commit comments