depot/third_party/nixpkgs/pkgs/test/make-binary-wrapper/cross.nix
Default email 5e7c2d6cef Project import generated by Copybara.
GitOrigin-RevId: f99e5f03cc0aa231ab5950a15ed02afec45ed51a
2023-10-09 21:29:22 +02:00

28 lines
705 B
Nix

{ 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
''