1{
2 lib,
3 stdenv,
4 fetchurl,
5 pkgs,
6 buildPackages,
7 fixDarwinDylibNames,
8}:
9stdenv.mkDerivation rec {
10 pname = "build2-bootstrap";
11 version = "0.17.0";
12 src = fetchurl {
13 url = "https://download.build2.org/${version}/build2-toolchain-${version}.tar.xz";
14 hash = "sha256-NyKonqht90JTnQ+Ru0Qp/Ua79mhVOjUHgKY0EbZIv10=";
15 };
16 patches = [
17 # Pick up sysdirs from NIX_LDFLAGS
18 ./nix-ldflags-sysdirs.patch
19 ];
20
21 sourceRoot = "build2-toolchain-${version}/build2";
22 makefile = "bootstrap.gmake";
23 enableParallelBuilding = true;
24
25 setupHook = ./setup-hook.sh;
26
27 strictDeps = true;
28
29 propagatedBuildInputs = lib.optionals stdenv.targetPlatform.isDarwin [
30 fixDarwinDylibNames
31
32 # Build2 needs to use lld on Darwin because it creates thin archives when it detects `llvm-ar`,
33 # which ld64 does not support.
34 (lib.getBin buildPackages.llvmPackages.lld)
35 ];
36
37 doCheck = true;
38 checkPhase = ''
39 runHook preCheck
40 build2/b-boot --version
41 runHook postCheck
42 '';
43
44 installPhase = ''
45 runHook preInstall
46 install -D build2/b-boot $out/bin/b
47 runHook postInstall
48 '';
49
50 postFixup = ''
51 substituteInPlace $out/nix-support/setup-hook \
52 --subst-var-by isTargetDarwin '${toString stdenv.targetPlatform.isDarwin}'
53 '';
54
55 inherit (pkgs.build2) passthru;
56}