summaryrefslogtreecommitdiffstats
path: root/pkgs/test/make-binary-wrapper/cross.nix
blob: b2caae738cd8f104196859949df2e1d16b05f79b (plain)
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
{
  stdenv,
  runCommand,
  makeBinaryWrapper,
  binutils,
  lib,
  expectedArch ? stdenv.hostPlatform.parsed.cpu.name,
}:

runCommand "make-binary-wrapper-test-cross"
  {
    nativeBuildInputs = [
      makeBinaryWrapper
      binutils
    ];
    # For x86_64-linux the machine field is
    # Advanced Micro Devices X86-64
    # and uses a dash instead of a underscore unlike x86_64-linux in hostPlatform.parsed.cpu.name
    expectedArch = lib.replaceStrings [ "_" ] [ "-" ] expectedArch;
  }
  ''
    touch prog
    chmod +x prog
    makeWrapper prog $out
    read -r _ arch < <($READELF --file-header $out | grep Machine:)
    if [[ ''${arch,,} != *"''${expectedArch,,}"* ]]; then
      echo "expected $expectedArch, got $arch"
      exit 1
    fi
  ''