toxic: 0.15.1 -> 0.16.0
[NixPkgs.git] / pkgs / by-name / ju / justbuild / package.nix
blob18827578650140520a59f02d0a4326b8287b93f5
2   gccStdenv,
3   fetchFromGitHub,
4   fetchurl,
6   fmt_10,
7   nlohmann_json,
8   cli11,
9   microsoft-gsl,
10   libgit2,
11   openssl,
13   pkg-config,
14   protobuf,
15   grpc,
16   pandoc,
17   python3,
18   unzip,
19   wget,
20   lib,
21   jq,
22   coreutils,
24   curl,
25   libarchive,
27   nix-update-script,
28   testers,
29   justbuild,
31 let
32   stdenv = gccStdenv;
34 stdenv.mkDerivation rec {
35   pname = "justbuild";
36   version = "1.3.2";
38   src = fetchFromGitHub {
39     owner = "just-buildsystem";
40     repo = "justbuild";
41     rev = "refs/tags/v${version}";
42     hash = "sha256-N9K1n2ttxhD0q2BXprt/nQdQseUtpaFmEZUcxRJV5C8=";
43   };
45   bazelapi = fetchurl {
46     url = "https://github.com/bazelbuild/remote-apis/archive/e1fe21be4c9ae76269a5a63215bb3c72ed9ab3f0.tar.gz";
47     hash = "sha256-dCGr1TUsz5J8IFBFOk2/ofexxxcOw+hwK2/i05uIBf4=";
48   };
50   googleapi = fetchurl {
51     url = "https://github.com/googleapis/googleapis/archive/2f9af297c84c55c8b871ba4495e01ade42476c92.tar.gz";
52     hash = "sha256-W7awJTzPZLU9bHJJYlp+P2w7xkAqvVLTd4v6SCWHA6A=";
53   };
55   nativeBuildInputs = [
56     # Tools for the bootstrap process
57     jq
58     pkg-config
59     python3
60     unzip
61     wget
62     coreutils
64     # Dependencies of just
65     cli11
66     # Using fmt 10 because this is the same version upstream currently
67     # uses for bundled builds
68     # For future updates: The currently used version can be found in the file
69     # etc/repos.json: https://github.com/just-buildsystem/justbuild/blob/master/etc/repos.json
70     # under the key .repositories.fmt
71     fmt_10
72     microsoft-gsl
73     nlohmann_json
75     # Dependencies of the compiled just-mr
76     curl
77     libarchive
78   ];
80   buildInputs = [
81     grpc
82     libgit2
83     openssl
84     protobuf
85     python3
86   ];
88   postPatch =
89     ''
90       sed -ie 's|\./bin/just-mr.py|${python3}/bin/python3 ./bin/just-mr.py|' bin/bootstrap.py
91       sed -ie 's|#!/usr/bin/env python3|#!${python3}/bin/python3|' bin/parallel-bootstrap-traverser.py
92       jq '.repositories.protobuf.pkg_bootstrap.local_path = "${protobuf}"' etc/repos.json > etc/repos.json.patched
93       mv etc/repos.json.patched etc/repos.json
94       jq '.repositories.com_github_grpc_grpc.pkg_bootstrap.local_path = "${grpc}"' etc/repos.json > etc/repos.json.patched
95       mv etc/repos.json.patched etc/repos.json
96       jq '.unknown.PATH = []' etc/toolchain/CC/TARGETS > etc/toolchain/CC/TARGETS.patched
97       mv etc/toolchain/CC/TARGETS.patched etc/toolchain/CC/TARGETS
98     ''
99     + lib.optionalString stdenv.hostPlatform.isDarwin ''
100       sed -ie 's|-Wl,-z,stack-size=8388608|-Wl,-stack_size,0x800000|' bin/bootstrap.py
101     '';
103   /*
104     The build phase follows the bootstrap procedure that is explained in
105     https://github.com/just-buildsystem/justbuild/blob/master/INSTALL.md
107     The bootstrap of the just binary depends on two proto libraries, which are
108     supplied as external distfiles.
110     The microsoft-gsl library does not provide a pkg-config file, so one is
111     created here. In case also the GNU Scientific Library would be used (which
112     has also the pkg-config name gsl) this would cause a conflict. However, it
113     is very unlikely that a build tool will ever depend on a GPL math library.
115     The extra build flags (ADD_CFLAGS and ADD_CXXFLAGS) are only needed in the
116     current version of just, the next release will contain a fix from upstream.
117     https://github.com/just-buildsystem/justbuild/commit/5abcd4140a91236c7bda1c21ce69e76a28da7c8a
118   */
120   buildPhase = ''
121     runHook preBuild
123     mkdir .distfiles
124     ln -s ${bazelapi} .distfiles/e1fe21be4c9ae76269a5a63215bb3c72ed9ab3f0.tar.gz
125     ln -s ${googleapi} .distfiles/2f9af297c84c55c8b871ba4495e01ade42476c92.tar.gz
127     mkdir .pkgconfig
128     cat << __EOF__ > .pkgconfig/gsl.pc
129     Name: gsl
130     Version: n/a
131     Description: n/a
132     URL: n/a
133     Cflags: -I${microsoft-gsl}/include
134     __EOF__
135     export PKG_CONFIG_PATH=`pwd`/.pkgconfig''${PKG_CONFIG_PATH:+:}$PKG_CONFIG_PATH
137     # Bootstrap just
138     export PACKAGE=YES
139     export NON_LOCAL_DEPS='[ "google_apis", "bazel_remote_apis" ]'
140     export JUST_BUILD_CONF=`echo $PATH | jq -R '{ ENV: { PATH: . }, "ADD_CXXFLAGS": ["-D__unix__", "-DFMT_HEADER_ONLY"], "ARCH": "'$(uname -m)'" }'`
142     mkdir ../build
143     python3 ./bin/bootstrap.py `pwd` ../build "`pwd`/.distfiles"
145     # Build compiled just-mr
146     ../build/out/bin/just install 'installed just-mr' -c ../build/build-conf.json -C ../build/repo-conf.json --output-dir ../build/out --local-build-root ../build/.just
148     # convert man pages from Markdown to man
149     find "./share/man" -name "*.md" -exec sh -c '${pandoc}/bin/pandoc --standalone --to man -o "''${0%.md}" "''${0}"' {} \;
151     runHook postBuild
152   '';
154   installPhase = ''
155     runHook preInstall
156     mkdir -p "$out/bin"
159     install -m 755 -Dt "$out/bin" "../build/out/bin/just"
160     install -m 755 -Dt "$out/bin" "../build/out/bin/just-mr"
161     install -m 755 -DT "bin/just-import-git.py" "$out/bin/just-import-git"
162     install -m 755 -DT "bin/just-deduplicate-repos.py" "$out/bin/just-deduplicate-repos"
164     mkdir -p "$out/share/bash-completion/completions"
165     install -m 0644 ./share/just_complete.bash "$out/share/bash-completion/completions/just"
167     mkdir -p "$out/share/man/"{man1,man5}
168     install -m 0644 -t "$out/share/man/man1" ./share/man/*.1
169     install -m 0644 -t "$out/share/man/man5" ./share/man/*.5
171     runHook postInstall
172   '';
174   passthru = {
175     updateScript = nix-update-script { };
176     tests.version = testers.testVersion {
177       package = justbuild;
178       command = "just version";
179       version = builtins.replaceStrings [ "." ] [ "," ] version;
180     };
181   };
183   meta = {
184     broken = stdenv.hostPlatform.isDarwin;
185     description = "Generic build tool";
186     homepage = "https://github.com/just-buildsystem/justbuild";
187     changelog = "https://github.com/just-buildsystem/justbuild/releases/tag/v${version}";
188     mainProgram = "just";
189     license = lib.licenses.asl20;
190     maintainers = with lib.maintainers; [ clkamp ];
191   };