linuxHeaders: fix cross-compilation from darwin to mips

mips tools require endian headers which are different on darwin.
Add stub headers to define the appropriate byte swap functions.

Co-authored-by: Adam Joseph <54836058+amjoseph-nixpkgs@users.noreply.github.com>

+30
+30
pkgs/os-specific/linux/kernel-headers/default.nix
··· 1 { stdenvNoCC, lib, buildPackages, fetchurl, perl, elf-header 2 , bison ? null, flex ? null, python ? null, rsync ? null 3 }: 4 5 assert stdenvNoCC.hostPlatform.isAndroid -> 6 (flex != null && bison != null && python != null && rsync != null); 7 8 let 9 makeLinuxHeaders = { src, version, patches ? [] }: stdenvNoCC.mkDerivation { 10 inherit src; 11 ··· 25 perl elf-header 26 ] ++ lib.optionals stdenvNoCC.hostPlatform.isAndroid [ 27 flex bison python rsync 28 ]; 29 30 extraIncludeDirs = lib.optional (with stdenvNoCC.hostPlatform; isPower && is32bit && isBigEndian) ["ppc"];
··· 1 { stdenvNoCC, lib, buildPackages, fetchurl, perl, elf-header 2 , bison ? null, flex ? null, python ? null, rsync ? null 3 + , writeTextFile 4 }: 5 6 assert stdenvNoCC.hostPlatform.isAndroid -> 7 (flex != null && bison != null && python != null && rsync != null); 8 9 let 10 + 11 + # As part of building a hostPlatform=mips kernel, Linux creates and runs a 12 + # tiny utility `arch/mips/boot/tools/relocs_main.c` for the buildPlatform. 13 + # This utility references a glibc-specific header `byteswap.h`. There is a 14 + # compatibility header in gnulib for most BSDs, but not for Darwin, so we 15 + # synthesize one here. 16 + darwin-endian-h = writeTextFile { 17 + name = "endian-h"; 18 + text = '' 19 + #include <byteswap.h> 20 + ''; 21 + destination = "/include/endian.h"; 22 + }; 23 + darwin-byteswap-h = writeTextFile { 24 + name = "byteswap-h"; 25 + text = '' 26 + #pragma once 27 + #include <libkern/OSByteOrder.h> 28 + #define bswap_16 OSSwapInt16 29 + #define bswap_32 OSSwapInt32 30 + #define bswap_64 OSSwapInt64 31 + ''; 32 + destination = "/include/byteswap.h"; 33 + }; 34 + 35 makeLinuxHeaders = { src, version, patches ? [] }: stdenvNoCC.mkDerivation { 36 inherit src; 37 ··· 51 perl elf-header 52 ] ++ lib.optionals stdenvNoCC.hostPlatform.isAndroid [ 53 flex bison python rsync 54 + ] ++ lib.optionals (stdenvNoCC.buildPlatform.isDarwin && 55 + stdenvNoCC.hostPlatform.isMips) [ 56 + darwin-endian-h 57 + darwin-byteswap-h 58 ]; 59 60 extraIncludeDirs = lib.optional (with stdenvNoCC.hostPlatform; isPower && is32bit && isBigEndian) ["ppc"];