about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/interpreters/quickjs/default.nix
blob: 2f548207ea047633260d459d8cc6ef4c9a170dfd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{ lib
, stdenv
, fetchFromGitHub
, texinfo
}:

stdenv.mkDerivation rec {
  pname = "quickjs";
  version = "2021-12-09";

  src = fetchFromGitHub {
    owner = "bellard";
    repo = pname;
    rev = "daa35bc1e5d43192098af9b51caeb4f18f73f9f9";
    hash = "sha256-BhAsa8tumCQ4jK/TbRbptj2iOIUFFjU1MQYdIrDMpko=";
  };

  postPatch = lib.optionalString stdenv.isDarwin ''
    substituteInPlace Makefile --replace "CONFIG_LTO=y" ""
  '';

  makeFlags = [ "prefix=${placeholder "out"}" ];
  enableParallelBuilding = true;

  nativeBuildInputs = [
    texinfo
  ];

  postBuild = ''
    (cd doc
     makeinfo *texi)
  '';

  postInstall = ''
    (cd doc
     install -Dt $out/share/doc *texi *info)
  '';

  doInstallCheck = true;
  installCheckPhase = ''
    PATH="$out/bin:$PATH"

    # Programs exit with code 1 when testing help, so grep for a string
    set +o pipefail
    qjs     --help 2>&1 | grep "QuickJS version"
    qjscalc --help 2>&1 | grep "QuickJS version"
    set -o pipefail

    temp=$(mktemp).js
    echo "console.log('Output from compiled program');" > "$temp"
    set -o verbose
    out=$(mktemp) && qjsc         -o "$out" "$temp" && "$out" | grep -q "Output from compiled program"
    out=$(mktemp) && qjsc   -flto -o "$out" "$temp" && "$out" | grep -q "Output from compiled program"
  '';

  meta = with lib; {
    description = "A small and embeddable Javascript engine";
    homepage = "https://bellard.org/quickjs/";
    maintainers = with maintainers; [ stesie AndersonTorres ];
    platforms = platforms.unix;
    license = licenses.mit;
    mainProgram = "qjs";
  };
}