summary refs log tree commit diff
path: root/pkgs/development/tools/build-managers/muon/default.nix
blob: 92593bb60e5fe40688e45ba5c270f2dcd6dbfa25 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{ lib
, stdenv
, fetchFromSourcehut
, fetchurl
, curl
, libarchive
, libpkgconf
, pkgconf
, python3
, samurai
, scdoc
, zlib
, embedSamurai ? false
, buildDocs ? true
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "muon"
          + lib.optionalString embedSamurai "-embedded-samurai";
  version = "0.2.0";

  src = fetchFromSourcehut {
    name = "muon-src";
    owner = "~lattis";
    repo = "muon";
    rev = finalAttrs.version;
    hash = "sha256-ZHWyUV/BqM3ihauXDqDVkZURDDbBiRcEzptyGQmw94I=";
  };

  outputs = [ "out" ] ++ lib.optionals buildDocs [ "man" ];

  nativeBuildInputs = [
    pkgconf
    samurai
  ]
  ++ lib.optionals buildDocs [
    (python3.withPackages (ps: [ ps.pyyaml ]))
    scdoc
  ];

  buildInputs = [
    curl
    libarchive
    libpkgconf
    samurai
    zlib
  ];

  strictDeps = true;

  postUnpack = let
    # URLs manually extracted from subprojects directory
    meson-docs-wrap = fetchurl {
      name = "meson-docs-wrap";
      url = "https://mochiro.moe/wrap/meson-docs-1.0.1-19-gdd8d4ee22.tar.gz";
      hash = "sha256-jHSPdLFR5jUeds4e+hLZ6JOblor5iuCV5cIwoc4K9gI=";
    };

    samurai-wrap = fetchurl {
      name = "samurai-wrap";
      url = "https://mochiro.moe/wrap/samurai-1.2-32-g81cef5d.tar.gz";
      hash = "sha256-aPMAtScqweGljvOLaTuR6B0A0GQQQrVbRviXY4dpCoc=";
  };
  in ''
    pushd $sourceRoot/subprojects
    ${lib.optionalString buildDocs "tar xvf ${meson-docs-wrap}"}
    ${lib.optionalString embedSamurai "tar xvf ${samurai-wrap}"}
    popd
  '';

  postPatch = ''
    patchShebangs bootstrap.sh
  ''
  + lib.optionalString buildDocs ''
    patchShebangs subprojects/meson-docs/docs/genrefman.py
  '';

  # tests try to access "~"
  postConfigure = ''
    export HOME=$(mktemp -d)
  '';

  buildPhase = let
    muonBool = lib.mesonBool;
    muonEnable = lib.mesonEnable;

    cmdlineForMuon = lib.concatStringsSep " " [
      (muonBool "static" stdenv.targetPlatform.isStatic)
      (muonEnable "docs" buildDocs)
      (muonEnable "samurai" embedSamurai)
    ];
    cmdlineForSamu = "-j$NIX_BUILD_CORES";
  in ''
    runHook preBuild

    ./bootstrap.sh stage-1

    ./stage-1/muon setup ${cmdlineForMuon} stage-2
    samu ${cmdlineForSamu} -C stage-2

    stage-2/muon setup -Dprefix=$out ${cmdlineForMuon} stage-3
    samu ${cmdlineForSamu} -C stage-3

    runHook postBuild
  '';

  # tests are failing because they don't find Python
  doCheck = false;

  checkPhase = ''
    runHook preCheck

    ./stage-3/muon -C stage-3 test

    runHook postCheck
  '';

  installPhase = ''
    runHook preInstall

    stage-3/muon -C stage-3 install

    runHook postInstall
  '';

  meta = with lib; {
    homepage = "https://muon.build/";
    description = "An implementation of Meson build system in C99";
    license = licenses.gpl3Only;
    maintainers = with maintainers; [ AndersonTorres ];
    platforms = platforms.unix;
    broken = stdenv.isDarwin; # typical `ar failure`
    mainProgram = "muon";
  };
})
# TODO LIST:
# 1. automate sources acquisition (especially wraps)
# 2. setup hook
# 3. tests