|
| 1 | +{ |
| 2 | + pkgs ? import ./pkgs.nix { }, |
| 3 | +}: |
| 4 | + |
| 5 | +let |
| 6 | + inherit (pkgs) writeScript icu; |
| 7 | + |
| 8 | + nodejs = pkgs.nodejs-slim_latest; |
| 9 | + sharedLibDeps = import ./sharedLibDeps.nix { inherit pkgs; }; |
| 10 | + configureFlags = import ./configureFlags.nix { |
| 11 | + inherit pkgs icu sharedLibDeps; |
| 12 | + cachedV8 = null; |
| 13 | + loadJSBuiltinsDynamically = false; |
| 14 | + }; |
| 15 | +in |
| 16 | +pkgs.stdenv.mkDerivation (finalAttrs: { |
| 17 | + pname = "libv8"; |
| 18 | + version = "0.0.0-unstable"; |
| 19 | + src = |
| 20 | + let |
| 21 | + inherit (pkgs.lib) fileset; |
| 22 | + in |
| 23 | + fileset.toSource { |
| 24 | + root = ../../.; |
| 25 | + fileset = fileset.unions [ |
| 26 | + ../../common.gypi |
| 27 | + ../../configure |
| 28 | + ../../configure.py |
| 29 | + ../../deps/inspector_protocol/inspector_protocol.gyp |
| 30 | + ../../deps/ncrypto/ncrypto.gyp |
| 31 | + ../../deps/v8 |
| 32 | + ../../node.gyp |
| 33 | + ../../node.gypi |
| 34 | + ../../src/inspector/node_inspector.gypi |
| 35 | + ../../src/node_version.h |
| 36 | + ../../tools/configure.d |
| 37 | + ../../tools/getmoduleversion.py |
| 38 | + ../../tools/getnapibuildversion.py |
| 39 | + ../../tools/gyp |
| 40 | + ../../tools/gyp_node.py |
| 41 | + ../../tools/icu/icu_versions.json |
| 42 | + ../../tools/icu/icu-system.gyp |
| 43 | + ../../tools/utils.py |
| 44 | + ../../tools/v8_gypfiles |
| 45 | + ]; |
| 46 | + }; |
| 47 | + |
| 48 | + prePatch = '' |
| 49 | + # Filter patches to only include changes under deps/npm/ and strip that prefix |
| 50 | + patches=() |
| 51 | + for patch in ${pkgs.lib.concatStringsSep " " nodejs.patches}; do |
| 52 | + filtered=$(mktemp) |
| 53 | + filterdiff -p1 -i 'tools/gyp/*' "$patch" > "$filtered" |
| 54 | + if [ -s "$filtered" ]; then |
| 55 | + patches+=("$filtered") |
| 56 | + fi |
| 57 | + done |
| 58 | + ''; |
| 59 | + |
| 60 | + inherit (nodejs) configureScript; |
| 61 | + inherit configureFlags; |
| 62 | + |
| 63 | + nativeBuildInputs = nodejs.nativeBuildInputs ++ [ pkgs.patchutils ]; |
| 64 | + buildInputs = [ icu ] ++ builtins.attrValues sharedLibDeps; |
| 65 | + |
| 66 | + buildPhase = '' |
| 67 | + ninja -C out/Release v8_snapshot v8_libplatform |
| 68 | + ''; |
| 69 | + installPhase = '' |
| 70 | + # assemble a static v8 library and put it in the 'out' output |
| 71 | + mkdir -p $out/lib |
| 72 | + pushd out/Release/obj |
| 73 | + find . -path "**/torque_*/**/*.o" -or -path "**/v8*/**/*.o" \ |
| 74 | + -and -not -name "torque.*" \ |
| 75 | + -and -not -name "mksnapshot.*" \ |
| 76 | + -and -not -name "gen-regexp-special-case.*" \ |
| 77 | + -and -not -name "bytecode_builtins_list_generator.*" \ |
| 78 | + | sort -u >files |
| 79 | + test -s files # ensure that the list is not empty |
| 80 | + $AR -cqs $out/lib/out.a @files |
| 81 | + popd |
| 82 | +
|
| 83 | + # copy v8 headers |
| 84 | + cp -r deps/v8/include $out/ |
| 85 | +
|
| 86 | + # create a pkgconfig file for v8 |
| 87 | + major=$(grep V8_MAJOR_VERSION deps/v8/include/v8-version.h | cut -d ' ' -f 3) |
| 88 | + minor=$(grep V8_MINOR_VERSION deps/v8/include/v8-version.h | cut -d ' ' -f 3) |
| 89 | + patch=$(grep V8_PATCH_LEVEL deps/v8/include/v8-version.h | cut -d ' ' -f 3) |
| 90 | + mkdir -p $out/lib/pkgconfig |
| 91 | + cat > $out/lib/pkgconfig/v8.pc << EOF |
| 92 | + Name: v8 |
| 93 | + Description: V8 JavaScript Engine |
| 94 | + Version: $major.$minor.$patch |
| 95 | + Libs: -L$out/lib -lv8 -pthread -licui18n -licuuc |
| 96 | + Cflags: -I$out/include |
| 97 | + EOF |
| 98 | + ''; |
| 99 | +}) |
0 commit comments