Merge pull request #222401 from Artturin/newlibincr

authored by Artturi and committed by GitHub 4d383f2c d3f37613

+60 -14
+60 -14
pkgs/development/misc/newlib/default.nix
··· 1 - { stdenv, fetchurl, buildPackages 1 + { stdenv, fetchurl, buildPackages, lib, fetchpatch, texinfo 2 2 , # "newlib-nano" is what the official ARM embedded toolchain calls this build 3 3 # configuration that prioritizes low space usage. We include it as a preset 4 4 # for embedded projects striving for a similar configuration. 5 5 nanoizeNewlib ? false 6 6 }: 7 7 8 - stdenv.mkDerivation rec { 8 + stdenv.mkDerivation (finalAttrs: { 9 9 pname = "newlib"; 10 - version = "4.1.0"; 10 + version = "4.3.0.20230120"; 11 11 12 12 src = fetchurl { 13 - url = "ftp://sourceware.org/pub/newlib/newlib-${version}.tar.gz"; 14 - sha256 = "0m01sjjyj0ib7bwlcrvmk1qkkgd66zf1dhbw716j490kymrf75pj"; 13 + url = "ftp://sourceware.org/pub/newlib/newlib-${finalAttrs.version}.tar.gz"; 14 + sha256 = "sha256-g6Yqma9Z4465sMWO0JLuJNcA//Q6IsA+QzlVET7zUVA="; 15 15 }; 16 16 17 - depsBuildBuild = [ buildPackages.stdenv.cc ]; 17 + patches = lib.optionals nanoizeNewlib [ 18 + # https://bugs.gentoo.org/723756 19 + (fetchpatch { 20 + name = "newlib-3.3.0-no-nano-cxx.patch"; 21 + url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-libs/newlib/files/newlib-3.3.0-no-nano-cxx.patch?id=9ee5a1cd6f8da6d084b93b3dbd2e8022a147cfbf"; 22 + sha256 = "sha256-S3mf7vwrzSMWZIGE+d61UDH+/SK/ao1hTPee1sElgco="; 23 + }) 24 + ]; 25 + 26 + depsBuildBuild = [ 27 + buildPackages.stdenv.cc 28 + texinfo # for makeinfo 29 + ]; 18 30 19 31 # newlib expects CC to build for build platform, not host platform 20 32 preConfigure = '' ··· 22 34 ''; 23 35 24 36 configurePlatforms = [ "build" "target" ]; 37 + # 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 38 + # sort alphabetically 25 39 configureFlags = [ 26 40 "--host=${stdenv.buildPlatform.config}" 27 - 41 + ] ++ (if !nanoizeNewlib then [ 28 42 "--disable-newlib-supplied-syscalls" 29 43 "--disable-nls" 30 - "--enable-newlib-retargetable-locking" 31 - ] ++ (if !nanoizeNewlib then [ 44 + "--enable-newlib-io-c99-formats" 32 45 "--enable-newlib-io-long-long" 46 + "--enable-newlib-reent-check-verify" 33 47 "--enable-newlib-register-fini" 48 + "--enable-newlib-retargetable-locking" 34 49 ] else [ 35 - "--enable-newlib-reent-small" 36 - "--disable-newlib-fvwrite-in-streamio" 37 50 "--disable-newlib-fseek-optimization" 38 - "--disable-newlib-wide-orient" 39 - "--enable-newlib-nano-malloc" 51 + "--disable-newlib-fvwrite-in-streamio" 52 + "--disable-newlib-supplied-syscalls" 40 53 "--disable-newlib-unbuf-stream-opt" 54 + "--disable-newlib-wide-orient" 55 + "--disable-nls" 41 56 "--enable-lite-exit" 42 57 "--enable-newlib-global-atexit" 43 58 "--enable-newlib-nano-formatted-io" 59 + "--enable-newlib-nano-malloc" 60 + "--enable-newlib-reent-check-verify" 61 + "--enable-newlib-reent-small" 62 + "--enable-newlib-retargetable-locking" 44 63 ]); 45 64 46 65 dontDisableStatic = true; 47 66 67 + # apply necessary nano changes from https://developer.arm.com/-/media/Files/downloads/gnu/12.2.rel1/manifest/copy_nano_libraries.sh?rev=4c50be6ccb9c4205a5262a3925317073&hash=1375A7B0A1CD0DB9B9EB0D2B574ADF66 68 + postInstall = lib.optionalString nanoizeNewlib '' 69 + mkdir -p $out${finalAttrs.passthru.incdir}/newlib-nano 70 + cp $out${finalAttrs.passthru.incdir}/newlib.h $out${finalAttrs.passthru.incdir}/newlib-nano/ 71 + 72 + ( 73 + cd $out${finalAttrs.passthru.libdir} 74 + 75 + for f in librdimon.a libc.a libg.a; do 76 + cp "$f" "''${f%%\.a}_nano.a" 77 + done 78 + ) 79 + ''; 80 + 48 81 passthru = { 49 82 incdir = "/${stdenv.targetPlatform.config}/include"; 50 83 libdir = "/${stdenv.targetPlatform.config}/lib"; 51 84 }; 52 - } 85 + 86 + meta = with lib; { 87 + description = "a C library intended for use on embedded systems"; 88 + homepage = "https://sourceware.org/newlib/"; 89 + # arch has "bsd" while gentoo has "NEWLIB LIBGLOSS GPL-2" while COPYING has "gpl2" 90 + # there are 5 copying files in total 91 + # COPYING 92 + # COPYING.LIB 93 + # COPYING.LIBGLOSS 94 + # COPYING.NEWLIB 95 + # COPYING3 96 + license = licenses.gpl2Plus; 97 + }; 98 + })