Commit b45cf446 authored by Ryan Burns's avatar Ryan Burns
Browse files

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: default avatarAdam Joseph <54836058+amjoseph-nixpkgs@users.noreply.github.com>
parent 4b73e231
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
{ stdenvNoCC, lib, buildPackages, fetchurl, perl, elf-header
, bison ? null, flex ? null, python ? null, rsync ? null
, writeTextFile
}:

assert stdenvNoCC.hostPlatform.isAndroid ->
  (flex != null && bison != null && python != null && rsync != null);

let

  # As part of building a hostPlatform=mips kernel, Linux creates and runs a
  # tiny utility `arch/mips/boot/tools/relocs_main.c` for the buildPlatform.
  # This utility references a glibc-specific header `byteswap.h`.  There is a
  # compatibility header in gnulib for most BSDs, but not for Darwin, so we
  # synthesize one here.
  darwin-endian-h = writeTextFile {
    name = "endian-h";
    text = ''
      #include <byteswap.h>
    '';
    destination = "/include/endian.h";
  };
  darwin-byteswap-h = writeTextFile {
    name = "byteswap-h";
    text = ''
      #pragma once
      #include <libkern/OSByteOrder.h>
      #define bswap_16 OSSwapInt16
      #define bswap_32 OSSwapInt32
      #define bswap_64 OSSwapInt64
    '';
    destination = "/include/byteswap.h";
  };

  makeLinuxHeaders = { src, version, patches ? [] }: stdenvNoCC.mkDerivation {
    inherit src;

@@ -25,6 +51,10 @@ let
      perl elf-header
    ] ++ lib.optionals stdenvNoCC.hostPlatform.isAndroid [
      flex bison python rsync
    ] ++ lib.optionals (stdenvNoCC.buildPlatform.isDarwin &&
                        stdenvNoCC.hostPlatform.isMips) [
      darwin-endian-h
      darwin-byteswap-h
    ];

    extraIncludeDirs = lib.optional (with stdenvNoCC.hostPlatform; isPower && is32bit && isBigEndian) ["ppc"];