Merge pull request #135525 from veprbl/pr/open_memstream_fmemopen_darwin_fix

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