about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/misc/bandwidth/default.nix
blob: 5eef6a517f3ab6aa9145dfeee5099a17b37ce844 (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
{ lib, stdenv, fetchurl, nasm }:

let
  inherit (stdenv.hostPlatform.parsed.cpu) bits;
  arch = "bandwidth${toString bits}";
in
stdenv.mkDerivation rec {
  pname = "bandwidth";
  version = "1.10.4";

  src = fetchurl {
    url = "https://zsmith.co/archives/${pname}-${version}.tar.gz";
    sha256 = "sha256-e/eP2rA7ElFrh2Z4qTzRGR/cxY1UI6s+LQ9Og1x46/I=";
  };

  postPatch = ''
    sed -i 's,ar ,$(AR) ,g' OOC/Makefile
    # Remove unnecessary -m32 for 32-bit targets
    sed -i 's,-m32,,g' OOC/Makefile
    # Fix wrong comment character
    sed -i 's,# 32,; 32,g' routines-x86-32bit.asm
    # Fix missing symbol exports for macOS clang
    echo global _VectorToVector128 >> routines-x86-64bit.asm
    echo global _VectorToVector256 >> routines-x86-64bit.asm
  '';

  nativeBuildInputs = [ nasm ];

  buildFlags = [
    "AR=${stdenv.cc.targetPrefix}ar"
    "CC=${stdenv.cc.targetPrefix}cc"
    "ARM_AS=${stdenv.cc.targetPrefix}as"
    "ARM_CC=$(CC)"
    "UNAMEPROC=${stdenv.hostPlatform.parsed.cpu.name}"
    "UNAMEMACHINE=${stdenv.hostPlatform.parsed.cpu.name}"
    arch
  ];

  installPhase = ''
    mkdir -p $out/bin
    cp ${arch} $out/bin/bandwidth
  '';

  meta = with lib; {
    homepage = "https://zsmith.co/bandwidth.html";
    description = "Artificial benchmark for identifying weaknesses in the memory subsystem";
    license = licenses.gpl2Plus;
    platforms = platforms.x86 ++ platforms.arm ++ platforms.aarch64;
    maintainers = with maintainers; [ r-burns ];
  };
}