summary refs log tree commit diff
diff options
context:
space:
mode:
authorAdam Joseph <adam@westernsemico.com>2023-11-08 16:42:00 -0800
committerAdam Joseph <54836058+amjoseph-nixpkgs@users.noreply.github.com>2023-11-12 02:12:42 +0000
commit1e47c87fd239258c2e5e8259765053c24b5f50d9 (patch)
tree881f882f7fb5a25b292b1d51e79096e1ec8f9eea
parent4c5a455ca5c09a15edca42e83e8b65773da4394a (diff)
downloadnixpkgs-1e47c87fd239258c2e5e8259765053c24b5f50d9.tar
nixpkgs-1e47c87fd239258c2e5e8259765053c24b5f50d9.tar.gz
nixpkgs-1e47c87fd239258c2e5e8259765053c24b5f50d9.tar.bz2
nixpkgs-1e47c87fd239258c2e5e8259765053c24b5f50d9.tar.lz
nixpkgs-1e47c87fd239258c2e5e8259765053c24b5f50d9.tar.xz
nixpkgs-1e47c87fd239258c2e5e8259765053c24b5f50d9.tar.zst
nixpkgs-1e47c87fd239258c2e5e8259765053c24b5f50d9.zip
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.
-rw-r--r--pkgs/development/misc/newlib/default.nix24
1 files changed, 23 insertions, 1 deletions
diff --git a/pkgs/development/misc/newlib/default.nix b/pkgs/development/misc/newlib/default.nix
index 49626ab8466..8aed144ff65 100644
--- a/pkgs/development/misc/newlib/default.nix
+++ b/pkgs/development/misc/newlib/default.nix
@@ -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"