lol
1{
2 gccStdenv,
3 fetchFromGitHub,
4 fetchurl,
5
6 fmt_10,
7 nlohmann_json,
8 cli11,
9 microsoft-gsl,
10 libgit2,
11 openssl,
12
13 pkg-config,
14 protobuf,
15 grpc,
16 pandoc,
17 python3,
18 unzip,
19 wget,
20 lib,
21 jq,
22 coreutils,
23
24 curl,
25 libarchive,
26
27 nix-update-script,
28 testers,
29 justbuild,
30}:
31let
32 stdenv = gccStdenv;
33in
34stdenv.mkDerivation rec {
35 pname = "justbuild";
36 version = "1.6.3";
37
38 src = fetchFromGitHub {
39 owner = "just-buildsystem";
40 repo = "justbuild";
41 rev = "refs/tags/v${version}";
42 hash = "sha256-ZTwe6S0AH1yQt5mABtIeWuMbiVSKeOZWMFI26fthLsM=";
43 };
44
45 bazelapi = fetchurl {
46 url = "https://github.com/bazelbuild/remote-apis/archive/9ef19c6b5fbf77d6dd9d84d75fbb5a20a6b62ef1.tar.gz";
47 hash = "sha256-zPV1ObY0fOsKp+k+5Duf/xrrSW02zAl9qRjEo172WDk=";
48 };
49
50 googleapi = fetchurl {
51 url = "https://github.com/googleapis/googleapis/archive/fe8ba054ad4f7eca946c2d14a63c3f07c0b586a0.tar.gz";
52 hash = "sha256:1r33jj8yipxjgiarddcxr1yc5kmn98rwrjl9qxfx0fzn1bsg04q5";
53 };
54
55 nativeBuildInputs = [
56 # Tools for the bootstrap process
57 jq
58 pkg-config
59 python3
60 unzip
61 wget
62 coreutils
63
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.in.json: https://github.com/just-buildsystem/justbuild/blob/master/etc/repos.in.json
70 # under the key .repositories.fmt
71 fmt_10
72 microsoft-gsl
73 nlohmann_json
74
75 # Dependencies of the compiled just-mr
76 curl
77 libarchive
78 ];
79
80 buildInputs = [
81 grpc
82 libgit2
83 openssl
84 protobuf
85 python3
86 ];
87
88 postPatch = ''
89 sed -i -e 's|\./bin/just-mr.py|${python3}/bin/python3 ./bin/just-mr.py|' bin/bootstrap.py
90 sed -i -e 's|#!/usr/bin/env python3|#!${python3}/bin/python3|' bin/parallel-bootstrap-traverser.py
91 jq '.repositories.protobuf.pkg_bootstrap.local_path = "${protobuf}"' etc/repos.in.json > etc/repos.in.json.patched
92 mv etc/repos.in.json.patched etc/repos.in.json
93 jq '.repositories.com_github_grpc_grpc.pkg_bootstrap.local_path = "${grpc}"' etc/repos.in.json > etc/repos.in.json.patched
94 mv etc/repos.in.json.patched etc/repos.in.json
95 jq '.unknown.PATH = []' etc/toolchain/CC/TARGETS > etc/toolchain/CC/TARGETS.patched
96 mv etc/toolchain/CC/TARGETS.patched etc/toolchain/CC/TARGETS
97 ''
98 + lib.optionalString stdenv.hostPlatform.isDarwin ''
99 sed -i -e 's|-Wl,-z,stack-size=8388608|-Wl,-stack_size,0x800000|' bin/bootstrap.py
100 '';
101
102 /*
103 The build phase follows the bootstrap procedure that is explained in
104 https://github.com/just-buildsystem/justbuild/blob/master/INSTALL.md
105
106 The bootstrap of the just binary depends on two proto libraries, which are
107 supplied as external distfiles.
108
109 The microsoft-gsl library does not provide a pkg-config file, so one is
110 created here. In case also the GNU Scientific Library would be used (which
111 has also the pkg-config name gsl) this would cause a conflict. However, it
112 is very unlikely that a build tool will ever depend on a GPL math library.
113
114 The extra build flags (ADD_CFLAGS and ADD_CXXFLAGS) are only needed in the
115 current version of just, the next release will contain a fix from upstream.
116 https://github.com/just-buildsystem/justbuild/commit/5abcd4140a91236c7bda1c21ce69e76a28da7c8a
117 */
118
119 buildPhase = ''
120 runHook preBuild
121
122 mkdir .distfiles
123 ln -s ${bazelapi} .distfiles/9ef19c6b5fbf77d6dd9d84d75fbb5a20a6b62ef1.tar.gz
124 ln -s ${googleapi} .distfiles/fe8ba054ad4f7eca946c2d14a63c3f07c0b586a0.tar.gz
125
126 mkdir .pkgconfig
127 cat << __EOF__ > .pkgconfig/gsl.pc
128 Name: gsl
129 Version: n/a
130 Description: n/a
131 URL: n/a
132 Cflags: -I${microsoft-gsl}/include
133 __EOF__
134 export PKG_CONFIG_PATH=`pwd`/.pkgconfig''${PKG_CONFIG_PATH:+:}$PKG_CONFIG_PATH
135
136 # Bootstrap just
137 export PACKAGE=YES
138 export NON_LOCAL_DEPS='[ "google_apis", "bazel_remote_apis" ]'
139 export JUST_BUILD_CONF=`echo $PATH | jq -R '{ ENV: { PATH: . }, "ADD_CXXFLAGS": ["-D__unix__", "-DFMT_HEADER_ONLY"], "ARCH": "'$(uname -m)'" }'`
140
141 mkdir ../build
142 python3 ./bin/bootstrap.py `pwd` ../build "`pwd`/.distfiles"
143
144 # Build compiled just-mr
145 ../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
146
147 # convert man pages from Markdown to man
148 find "./share/man" -name "*.md" -exec sh -c '${pandoc}/bin/pandoc --standalone --to man -o "''${0%.md}" "''${0}"' {} \;
149
150 runHook postBuild
151 '';
152
153 installPhase = ''
154 runHook preInstall
155 mkdir -p "$out/bin"
156
157
158 install -m 755 -Dt "$out/bin" "../build/out/bin/just"
159 install -m 755 -Dt "$out/bin" "../build/out/bin/just-mr"
160 install -m 755 -DT "bin/just-import-git.py" "$out/bin/just-import-git"
161 install -m 755 -DT "bin/just-deduplicate-repos.py" "$out/bin/just-deduplicate-repos"
162 install -m 755 -DT "bin/just-lock.py" "$out/bin/just-lock"
163
164 mkdir -p "$out/share/bash-completion/completions"
165 install -m 0644 ./share/just_complete.bash "$out/share/bash-completion/completions/just"
166
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
170
171 runHook postInstall
172 '';
173
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 };
182
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 };
192}