acr-cli: init at 0.14 (#359508)
[NixPkgs.git] / pkgs / by-name / ni / ninja / package.nix
blob744932e0c2ff3543dd7829f5aab93932c12f359f
1 { lib
2 , stdenv
3 , fetchFromGitHub
4 , asciidoc
5 , docbook_xml_dtd_45
6 , docbook_xsl
7 , installShellFiles
8 , libxslt
9 , python3
10 , re2c
11 , buildPackages
12 , buildDocs ? true
13 , nix-update-script
14 , ninjaRelease ? "latest"
17 stdenv.mkDerivation (finalAttrs: {
18   pname = "ninja";
19   version = lib.removePrefix "v" finalAttrs.src.rev;
21   src = {
22     # TODO: Remove Ninja 1.11 as soon as possible.
23     "1.11" = fetchFromGitHub {
24       owner = "ninja-build";
25       repo = "ninja";
26       rev = "v1.11.1";
27       hash = "sha256-LvV/Fi2ARXBkfyA1paCRmLUwCh/rTyz+tGMg2/qEepI=";
28     };
30     latest = fetchFromGitHub {
31       owner = "ninja-build";
32       repo = "ninja";
33       rev = "v1.12.1";
34       hash = "sha256-RT5u+TDvWxG5EVQEYj931EZyrHUSAqK73OKDAascAwA=";
35     };
36   }.${ninjaRelease} or (throw "Unsupported Ninja release: ${ninjaRelease}");
38   depsBuildBuild = [ buildPackages.stdenv.cc ];
40   nativeBuildInputs = [
41     python3
42     re2c
43     installShellFiles
44   ]
45   ++ lib.optionals buildDocs [
46     asciidoc
47     docbook_xml_dtd_45
48     docbook_xsl
49     libxslt.bin
50   ];
52   postPatch = ''
53     # write rebuild args to file after bootstrap
54     substituteInPlace configure.py --replace "subprocess.check_call(rebuild_args)" "open('rebuild_args','w').write(rebuild_args[0])"
55   '';
57   buildPhase = ''
58     runHook preBuild
60     # for list of env vars
61     # see https://github.com/ninja-build/ninja/blob/v1.11.1/configure.py#L264
62     CXX="$CXX_FOR_BUILD" \
63     AR="$AR_FOR_BUILD" \
64     CFLAGS="$CFLAGS_FOR_BUILD" \
65     CXXFLAGS="$CXXFLAGS_FOR_BUILD" \
66     LDFLAGS="$LDFLAGS_FOR_BUILD" \
67     python configure.py --bootstrap
68     python configure.py
70     source rebuild_args
71   '' + lib.optionalString buildDocs ''
72     # "./ninja -vn manual" output copied here to support cross compilation.
73     asciidoc -b docbook -d book -o build/manual.xml doc/manual.asciidoc
74     xsltproc --nonet doc/docbook.xsl build/manual.xml > doc/manual.html
75   '' + ''
77     runHook postBuild
78   '';
80   installPhase = ''
81     runHook preInstall
83     install -Dm555 -t $out/bin ninja
84     installShellCompletion --name ninja \
85       --bash misc/bash-completion \
86       --zsh misc/zsh-completion
87   '' + lib.optionalString buildDocs ''
88     install -Dm444 -t $out/share/doc/ninja doc/manual.asciidoc doc/manual.html
89   '' + ''
91     runHook postInstall
92   '';
94   setupHook = ./setup-hook.sh;
96   passthru.updateScript = nix-update-script {};
98   meta = {
99     description = "Small build system with a focus on speed";
100     mainProgram = "ninja";
101     longDescription = ''
102       Ninja is a small build system with a focus on speed. It differs from
103       other build systems in two major respects: it is designed to have its
104       input files generated by a higher-level build system, and it is designed
105       to run builds as fast as possible.
106     '';
107     homepage = "https://ninja-build.org/";
108     license = lib.licenses.asl20;
109     platforms = lib.platforms.unix;
110     maintainers = with lib.maintainers; [ thoughtpolice bjornfor orivej ];
111   };