patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 0e439974d1c4a904d8d0d57d1051c3f5e3c00ff5 4711 bytes (raw)
name: tools/default.nix 	 # note: path name is non-authoritative(*)

  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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
 
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2022-2025 Alyssa Ross <hi@alyssa.is>
# SPDX-FileCopyrightText: 2025 Yureka Lilian <yureka@cyberchaos.dev>

import ../lib/call-package.nix (
{ src, lib, stdenv, fetchCrate, fetchurl, runCommand, buildPackages
, meson, ninja, pkg-config, rustc
, clang-tools, clippy
, dbus
# clang 19 (current nixpkgs default) is too old to support -fwrapv-pointer
, clang_21, libbpf
, appSupport ? true
, hostSupport ? false
, driverSupport ? false
}:

let
  packageCache = [
    (fetchCrate {
      pname = "itoa";
      version = "1.0.11";
      unpack = false;
      hash = "sha256-SfHxSHMzVFRQDVlhHxz0pLD3hvmsEfQxKnjkzyVmaVs=";
    })
    (fetchurl {
      name = "miniserde-0.1.41.tar.gz";
      url = "https://github.com/dtolnay/miniserde/archive/0.1.41.tar.gz";
      hash = "sha256-2u3mIyslKzImtTJpK4M2nwN1PZJhJPa0ZxUDP/TaCAk=";
    })
    (fetchCrate {
      pname = "proc-macro2";
      version = "1.0.93";
      unpack = false;
      hash = "sha256-YJRqaOX50osNwcIbuKl+59AYqLMi+leDi6McyHjiLZk=";
    })
    (fetchCrate {
      pname = "quote";
      version = "1.0.38";
      unpack = false;
      hash = "sha256-Dk3Mqq+JUU9UbGk93BQPcp+VjCR5GKEzgMzMYHg5Gsw=";
    })
    (fetchCrate {
      pname = "ryu";
      version = "1.0.17";
      unpack = false;
      hash = "sha256-6GaXyRYBmoWIyZtfrDzq107AtLgZcHpoL9TSP6DOG6E=";
    })
    (fetchCrate {
      pname = "syn";
      version = "2.0.58";
      unpack = false;
      hash = "sha256-RM+5PzgHC+7jaz/vfU9aFvJ3UdlLGHtmalzF6bDTBoc=";
    })
    (fetchCrate {
      pname = "unicode-ident";
      version = "1.0.12";
      unpack = false;
      hash = "sha256-M1S5rD+uH/Z1XLbbU2g622YWNPZ1V5Qt6k+s6+wP7ks=";
    })
  ];
in

stdenv.mkDerivation (finalAttrs: {
  name = "spectrum-tools";

  src = lib.fileset.toSource {
    root = ../.;
    fileset = lib.fileset.intersection src (lib.fileset.unions ([
      ./meson.build
      ./meson_options.txt
    ] ++ lib.optionals appSupport [
      ./xdg-desktop-portal-spectrum
    ] ++ lib.optionals hostSupport [
      ./lsvm
      ./start-vmm
      ./subprojects
    ] ++ lib.optionals driverSupport [
      ./xdp-forwarder
    ]));
  };
  sourceRoot = "source/tools";

  depsBuildBuild = lib.optionals hostSupport [ buildPackages.stdenv.cc ];
  nativeBuildInputs = [ meson ninja ]
    ++ lib.optionals (appSupport || driverSupport) [ pkg-config ]
    ++ lib.optionals hostSupport [ rustc ]
    ++ lib.optionals driverSupport [ clang_21 ];
  buildInputs = lib.optionals appSupport [ dbus ] ++ lib.optionals driverSupport [ libbpf ];

  postPatch = lib.optionals hostSupport (lib.concatMapStringsSep "\n" (crate: ''
    mkdir -p subprojects/packagecache
    ln -s ${crate} subprojects/packagecache/${crate.name}
  '') packageCache);

  mesonFlags = [
    (lib.mesonBool "app" appSupport)
    (lib.mesonBool "host" hostSupport)
    (lib.mesonBool "driver" driverSupport)
    "-Dhostfsrootdir=/run/virtiofs/virtiofs0"
    "-Dtests=false"
    "-Dunwind=false"
    "-Dwerror=true"
  ];

  # Not supported for target bpf
  hardeningDisable = lib.optionals driverSupport [ "zerocallusedregs" ];

  passthru.tests = {
    clang-tidy = finalAttrs.finalPackage.overrideAttrs (
      { name, src, nativeBuildInputs ? [], ... }:
      {
        name = "${name}-clang-tidy";

        src = lib.fileset.toSource {
          root = ../.;
          fileset = lib.fileset.union (lib.fileset.fromSource src) ../.clang-tidy;
        };

        # clang-tools needs to be before clang, otherwise it will not use
        # the Nix include path correctly and fail to find headers
        nativeBuildInputs = [ clang-tools ] ++ nativeBuildInputs;

        buildPhase = ''
          clang-tidy --warnings-as-errors='*' ../**/*.c
          touch $out
          exit 0
        '';
      }
    );

    tests = finalAttrs.finalPackage.overrideAttrs (
      { name, mesonFlags ? [], ... }:
      {
        name = "${name}-tests";

        mesonFlags = mesonFlags ++ [
          "-Dunwind=true"
          "-Dtests=true"
        ];

        doCheck = true;
      }
    );
  } // lib.optionalAttrs hostSupport {
    clippy = finalAttrs.finalPackage.overrideAttrs (
      { name, nativeBuildInputs ? [], ... }:
      {
        name = "${name}-clippy";
        nativeBuildInputs = nativeBuildInputs ++ [ clippy ];
        dontBuild = true;
        doCheck = true;
        dontUseMesonCheck = true;
        checkTarget = "clippy";
        installPhase = ''touch $out && exit 0'';
      }
    );
  };

  meta = with lib; {
    description = "First-party Spectrum programs";
    license = licenses.eupl12;
    maintainers = with maintainers; [ qyliss ];
    platforms = platforms.linux;
  };
})
) (_: {})


debug log:

solving 0e43997 ...
found 0e43997 in https://inbox.spectrum-os.org/spectrum-devel/20250924114300.100541-2-yureka@cyberchaos.dev/
found 201afae in https://spectrum-os.org/git/spectrum
preparing index
index prepared:
100644 201afaee3c0610b62484aec9e493c3f597a8ccce	tools/default.nix

applying [1/1] https://inbox.spectrum-os.org/spectrum-devel/20250924114300.100541-2-yureka@cyberchaos.dev/
diff --git a/tools/default.nix b/tools/default.nix
index 201afae..0e43997 100644

Checking patch tools/default.nix...
Applied patch tools/default.nix cleanly.

index at:
100644 0e439974d1c4a904d8d0d57d1051c3f5e3c00ff5	tools/default.nix

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).