Commit 1e47c87f authored by Adam Joseph's avatar Adam Joseph Committed by Adam Joseph
Browse files

newlib: fix newlib host/target workaround

The newlib configury uses `host` to refer to the platform which is
being used to compile newlib.  Ugh.  It does this because of its
history: newlib used to be distributed with and built as part of
gcc.

To prevent nixpkgs from going insane, this package presents the
"normal" view to the outside world: the binaries in $out will
execute on `stdenv.hostPlatform`.  We then fool newlib's build
process into doing the right thing.
parent 4c5a455c
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -31,14 +31,36 @@ stdenv.mkDerivation (finalAttrs: {
  # newlib expects CC to build for build platform, not host platform
  preConfigure = ''
    export CC=cc
  '' +
  # newlib tries to disable itself when building for Linux *except*
  # when native-compiling.  Unfortunately the check for "is cross
  # compiling" was written when newlib was part of GCC and newlib
  # was built along with GCC (therefore newlib was built to execute
  # on the targetPlatform, not the hostPlatform).  Unfortunately
  # when newlib was extracted from GCC, this "is cross compiling"
  # logic was not fixed.  So we must disable it.
  ''
    substituteInPlace configure --replace 'noconfigdirs target-newlib target-libgloss' 'noconfigdirs'
  '';


  configurePlatforms = [ "build" "target" ];
  # flags copied from https://community.arm.com/support-forums/f/compilers-and-libraries-forum/53310/gcc-arm-none-eabi-what-were-the-newlib-compilation-options
  # sort alphabetically
  configureFlags = [
    "--with-newlib"
    "--host=${stdenv.buildPlatform.config}"

    # The newlib configury uses `host` to refer to the platform
    # which is being used to compile newlib.  Ugh.  It does this
    # because of its history: newlib used to be distributed with and
    # built as part of gcc.
    #
    # To prevent nixpkgs from going insane, this package presents the
    # "normal" view to the outside world: the binaries in $out will
    # execute on `stdenv.hostPlatform`.  We then fool newlib's build
    # process into doing the right thing.
    "--host=${stdenv.targetPlatform.config}"

  ] ++ (if !nanoizeNewlib then [
    "--disable-newlib-supplied-syscalls"
    "--disable-nls"