Merge pull request #135525 from veprbl/pr/open_memstream_fmemopen_darwin_fix

Add implemetations of open_memstream/fmemopen to be used on BSDs

authored by Dmitry Kalinkin and committed by GitHub d8ed39b3 f8cea6b5

+121 -46
+3 -3
pkgs/applications/science/physics/xfitter/default.nix
··· 1 { lib, stdenv, fetchurl, apfel, apfelgrid, applgrid, blas, gfortran, lhapdf, lapack, libyaml, lynx 2 , mela, root5, qcdnum, which, libtirpc 3 }: 4 5 stdenv.mkDerivation rec { ··· 36 37 nativeBuildInputs = [ gfortran which ]; 38 buildInputs = 39 - [ apfel apfelgrid applgrid blas lhapdf lapack mela root5 qcdnum ] 40 - # pdf2yaml requires fmemopen and open_memstream which are not readily available on Darwin 41 - ++ lib.optional (!stdenv.isDarwin) libyaml 42 ++ lib.optional (stdenv.hostPlatform.libc == "glibc") libtirpc 43 ; 44 propagatedBuildInputs = [ lynx ];
··· 1 { lib, stdenv, fetchurl, apfel, apfelgrid, applgrid, blas, gfortran, lhapdf, lapack, libyaml, lynx 2 , mela, root5, qcdnum, which, libtirpc 3 + , memorymappingHook, memstreamHook 4 }: 5 6 stdenv.mkDerivation rec { ··· 37 38 nativeBuildInputs = [ gfortran which ]; 39 buildInputs = 40 + [ apfel apfelgrid applgrid blas lhapdf libyaml lapack mela root5 qcdnum ] 41 + ++ lib.optionals (stdenv.system == "x86_64-darwin") [ memorymappingHook memstreamHook ] 42 ++ lib.optional (stdenv.hostPlatform.libc == "glibc") libtirpc 43 ; 44 propagatedBuildInputs = [ lynx ];
+43
pkgs/development/libraries/memorymapping/default.nix
···
··· 1 + { lib, stdenv, fetchFromGitHub }: 2 + 3 + stdenv.mkDerivation { 4 + pname = "memorymapping"; 5 + version = "unstable-2014-02-20"; 6 + 7 + src = fetchFromGitHub { 8 + owner = "NimbusKit"; 9 + repo = "memorymapping"; 10 + rev = "fc285afe13cb9d56a40c647b8ed6d6bd40636af7"; 11 + sha256 = "sha256-9u/QvK9TDsKxcubINH2OAbx5fXXkKF0+YT7LoLDaF0M="; 12 + }; 13 + 14 + dontConfigure = true; 15 + 16 + buildPhase = '' 17 + runHook preBuild 18 + 19 + $CC -c src/fmemopen.c 20 + $AR rcs libmemorymapping.a fmemopen.o 21 + sed -e '1i#include <stdio.h>' -i src/fmemopen.h 22 + 23 + runHook postBuild 24 + ''; 25 + 26 + installPhase = '' 27 + runHook preInstall 28 + 29 + install -D libmemorymapping.a "$out"/lib/libmemorymapping.a 30 + install -D src/fmemopen.h "$out"/include/fmemopen.h 31 + 32 + runHook postInstall 33 + ''; 34 + 35 + meta = with lib; { 36 + homepage = "https://nimbuskit.github.io/memorymapping/"; 37 + description = "fmemopen for Mac OS and iOS"; 38 + license = licenses.asl20; 39 + maintainers = with maintainers; [ veprbl ]; 40 + platforms = platforms.unix; 41 + broken = stdenv.isAarch64; 42 + }; 43 + }
+6
pkgs/development/libraries/memorymapping/setup-hook.sh
···
··· 1 + useMemorymapping () { 2 + export NIX_CFLAGS_COMPILE="${NIX_CFLAGS_COMPILE-}${NIX_CFLAGS_COMPILE:+ }-include fmemopen.h"; 3 + export NIX_LDFLAGS="${NIX_LDFLAGS-}${NIX_LDFLAGS:+ }-lmemorymapping"; 4 + } 5 + 6 + postHooks+=(useMemorymapping)
+43
pkgs/development/libraries/memstream/default.nix
···
··· 1 + { lib, stdenv, fetchurl }: 2 + 3 + stdenv.mkDerivation rec { 4 + pname = "memstream"; 5 + version = "0.1"; 6 + 7 + src = fetchurl { 8 + url = "https://piumarta.com/software/memstream/memstream-${version}.tar.gz"; 9 + sha256 = "0kvdb897g7nyviaz72arbqijk2g2wa61cmi3l5yh48rzr49r3a3a"; 10 + }; 11 + 12 + dontConfigure = true; 13 + 14 + postBuild = '' 15 + $AR rcs libmemstream.a memstream.o 16 + ''; 17 + 18 + doCheck = true; 19 + checkPhase = '' 20 + runHook preCheck 21 + 22 + ./test | grep "This is a test of memstream" 23 + 24 + runHook postCheck 25 + ''; 26 + 27 + installPhase = '' 28 + runHook preInstall 29 + 30 + install -D libmemstream.a "$out"/lib/libmemstream.a 31 + install -D memstream.h "$out"/include/memstream.h 32 + 33 + runHook postInstall 34 + ''; 35 + 36 + meta = with lib; { 37 + homepage = "https://www.piumarta.com/software/memstream/"; 38 + description = "memstream.c is an implementation of the POSIX function open_memstream() for BSD and BSD-like operating systems"; 39 + license = licenses.mit; 40 + maintainers = with maintainers; [ veprbl ]; 41 + platforms = platforms.unix; 42 + }; 43 + }
+6
pkgs/development/libraries/memstream/setup-hook.sh
···
··· 1 + useMemstream () { 2 + export NIX_CFLAGS_COMPILE="${NIX_CFLAGS_COMPILE-}${NIX_CFLAGS_COMPILE:+ }-include memstream.h"; 3 + export NIX_LDFLAGS="${NIX_LDFLAGS-}${NIX_LDFLAGS:+ }-lmemstream"; 4 + } 5 + 6 + postHooks+=(useMemstream)
+4 -1
pkgs/games/tintin/default.nix
··· 1 { stdenv, fetchurl, lib, zlib, pcre 2 , tlsSupport ? true, gnutls ? null 3 # ^ set { tlsSupport = false; } to reduce closure size by ~= 18.6 MB 4 }: ··· 15 }; 16 17 nativeBuildInputs = lib.optional tlsSupport gnutls.dev; 18 - buildInputs = [ zlib pcre ] ++ lib.optional tlsSupport gnutls; 19 20 preConfigure = '' 21 cd src
··· 1 { stdenv, fetchurl, lib, zlib, pcre 2 + , memorymappingHook, memstreamHook 3 , tlsSupport ? true, gnutls ? null 4 # ^ set { tlsSupport = false; } to reduce closure size by ~= 18.6 MB 5 }: ··· 16 }; 17 18 nativeBuildInputs = lib.optional tlsSupport gnutls.dev; 19 + buildInputs = [ zlib pcre ] 20 + ++ lib.optionals (stdenv.system == "x86_64-darwin") [ memorymappingHook memstreamHook ] 21 + ++ lib.optional tlsSupport gnutls; 22 23 preConfigure = '' 24 cd src
+6 -11
pkgs/tools/text/hyx/default.nix
··· 1 - { lib, stdenv, fetchurl }: 2 - let 3 - # memstream — POSIX memory streams for BSD 4 - memstream = fetchurl { 5 - url = "https://piumarta.com/software/memstream/memstream-0.1.tar.gz"; 6 - sha256 = "0kvdb897g7nyviaz72arbqijk2g2wa61cmi3l5yh48rzr49r3a3a"; 7 - }; 8 - in 9 stdenv.mkDerivation rec { 10 pname = "hyx"; 11 version = "2020-06-09"; ··· 15 sha256 = "1x8dmll93hrnj24kn5knpwj36y6r1v2ygwynpjwrg2hwd4c1a8hi"; 16 }; 17 18 - postUnpack = lib.optionalString stdenv.isDarwin '' 19 - tar --strip=1 -C $sourceRoot -xf ${memstream} --wildcards "memstream-0.1/memstream.[hc]" 20 ''; 21 22 - patches = lib.optional stdenv.isDarwin ./memstream.patch; 23 24 installPhase = '' 25 install -vD hyx $out/bin/hyx
··· 1 + { lib, stdenv, fetchurl, memstreamHook }: 2 + 3 stdenv.mkDerivation rec { 4 pname = "hyx"; 5 version = "2020-06-09"; ··· 9 sha256 = "1x8dmll93hrnj24kn5knpwj36y6r1v2ygwynpjwrg2hwd4c1a8hi"; 10 }; 11 12 + postPatch = lib.optionalString stdenv.isDarwin '' 13 + substituteInPlace Makefile \ 14 + --replace "-Wl,-z,relro,-z,now -fpic -pie" "" 15 ''; 16 17 + buildInputs = lib.optional (stdenv.system == "x86_64-darwin") memstreamHook; 18 19 installPhase = '' 20 install -vD hyx $out/bin/hyx
-31
pkgs/tools/text/hyx/memstream.patch
··· 1 - diff -Naur hyx-2020.06.09.org/Makefile hyx-2020.06.09/Makefile 2 - --- hyx-2020.06.09.org/Makefile 2020-06-09 15:19:50.000000000 +0300 3 - +++ hyx-2020.06.09/Makefile 2020-07-22 11:46:40.000000000 +0300 4 - @@ -1,6 +1,6 @@ 5 - 6 - all: CFLAGS ?= -O2 -Wl,-s \ 7 - - -Wl,-z,relro,-z,now -fpic -pie -D_FORTIFY_SOURCE=2 -fstack-protector-all 8 - + -D_FORTIFY_SOURCE=2 -fstack-protector-all 9 - all: CFLAGS += -std=c99 -pedantic -Wall -Wextra -DNDEBUG 10 - all: hyx 11 - 12 - @@ -13,7 +13,7 @@ 13 - hyx: *.h *.c 14 - $(CC) \ 15 - $(CFLAGS) \ 16 - - hyx.c common.c blob.c history.c view.c input.c \ 17 - + hyx.c common.c blob.c history.c view.c input.c memstream.c \ 18 - -o hyx 19 - 20 - clean: 21 - diff -Naur hyx-2020.06.09.org/view.c hyx-2020.06.09/view.c 22 - --- hyx-2020.06.09.org/view.c 2020-06-09 15:19:50.000000000 +0300 23 - +++ hyx-2020.06.09/view.c 2020-07-22 11:49:09.000000000 +0300 24 - @@ -4,6 +4,7 @@ 25 - #include "view.h" 26 - #include "input.h" 27 - #include "ansi.h" 28 - +#include "memstream.h" 29 - 30 - #include <stdlib.h> 31 - #include <stdio.h>
···
+10
pkgs/top-level/all-packages.nix
··· 17896 17897 mediastreamer-openh264 = callPackage ../development/libraries/mediastreamer/msopenh264.nix { }; 17898 17899 menu-cache = callPackage ../development/libraries/menu-cache { }; 17900 17901 mergerfs = callPackage ../tools/filesystems/mergerfs { };
··· 17896 17897 mediastreamer-openh264 = callPackage ../development/libraries/mediastreamer/msopenh264.nix { }; 17898 17899 + memorymapping = callPackage ../development/libraries/memorymapping { }; 17900 + memorymappingHook = makeSetupHook { 17901 + deps = [ memorymapping ]; 17902 + } ../development/libraries/memorymapping/setup-hook.sh; 17903 + 17904 + memstream = callPackage ../development/libraries/memstream { }; 17905 + memstreamHook = makeSetupHook { 17906 + deps = [ memstream ]; 17907 + } ../development/libraries/memstream/setup-hook.sh; 17908 + 17909 menu-cache = callPackage ../development/libraries/menu-cache { }; 17910 17911 mergerfs = callPackage ../tools/filesystems/mergerfs { };