2022-06-16 17:23:12 +00:00
|
|
|
{ stdenv
|
|
|
|
, runCommand
|
|
|
|
, makeBinaryWrapper
|
|
|
|
, binutils
|
2023-10-09 19:29:22 +00:00
|
|
|
, lib
|
2022-06-16 17:23:12 +00:00
|
|
|
, expectedArch ? stdenv.hostPlatform.parsed.cpu.name
|
|
|
|
}:
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
runCommand "make-binary-wrapper-test-cross" {
|
|
|
|
nativeBuildInputs = [
|
|
|
|
makeBinaryWrapper
|
|
|
|
binutils
|
|
|
|
];
|
2023-10-09 19:29:22 +00:00
|
|
|
# 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;
|
2022-06-16 17:23:12 +00:00
|
|
|
} ''
|
|
|
|
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
|
|
|
|
''
|