git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #135525 from veprbl/pr/open_memstream_fmemopen_darwin_fix

Add implemetations of open_memstream/fmemopen to be used on BSDs

commitd8ed39b309bf6fc4261a46d1ca6d218e791dc0e2 authorDmitry Kalinkin <dmitry.kalinkin@gmail.com> dateWed 15 Sep 2021, 11:49 (5 years ago) parentf8cea6b9c8f6ef
9 files changed+121−46
pkgs/applications/science/physics/xfitter/default.nix+3−3 pkgs/development/libraries/memorymapping/default.nix+43 pkgs/development/libraries/memorymapping/setup-hook.sh+6 pkgs/development/libraries/memstream/default.nix+43 pkgs/development/libraries/memstream/setup-hook.sh+6 pkgs/games/tintin/default.nix+4−1 pkgs/tools/text/hyx/default.nix+6−11 pkgs/tools/text/hyx/memstream.patch−31 pkgs/top-level/all-packages.nix+10
pkgs/applications/science/physics/xfitter/default.nix+3−3
@@ -1,5 +1,6 @@
11{ lib, stdenv, fetchurl, apfel, apfelgrid, applgrid, blas, gfortran, lhapdf, lapack, libyaml, lynx
22, mela, root5, qcdnum, which, libtirpc
3+, memorymappingHook, memstreamHook
34}:
45
56stdenv.mkDerivation rec {
@@ -36,9 +37,8 @@ stdenv.mkDerivation rec {
3637
3738 nativeBuildInputs = [ gfortran which ];
3839 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
40+ [ apfel apfelgrid applgrid blas lhapdf libyaml lapack mela root5 qcdnum ]
41+ ++ lib.optionals (stdenv.system == "x86_64-darwin") [ memorymappingHook memstreamHook ]
4242 ++ lib.optional (stdenv.hostPlatform.libc == "glibc") libtirpc
4343 ;
4444 propagatedBuildInputs = [ lynx ];
pkgs/development/libraries/memorymapping/default.nixnew file+43
@@ -0,0 +1,43 @@
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+}
pkgs/development/libraries/memorymapping/setup-hook.shnew file+6
@@ -0,0 +1,6 @@
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)
pkgs/development/libraries/memstream/default.nixnew file+43
@@ -0,0 +1,43 @@
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+}
pkgs/development/libraries/memstream/setup-hook.shnew file+6
@@ -0,0 +1,6 @@
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)
pkgs/games/tintin/default.nix+4−1
@@ -1,4 +1,5 @@
11{ stdenv, fetchurl, lib, zlib, pcre
2+, memorymappingHook, memstreamHook
23, tlsSupport ? true, gnutls ? null
34# ^ set { tlsSupport = false; } to reduce closure size by ~= 18.6 MB
45}:
@@ -15,7 +16,9 @@ stdenv.mkDerivation rec {
1516 };
1617
1718 nativeBuildInputs = lib.optional tlsSupport gnutls.dev;
18− buildInputs = [ zlib pcre ] ++ lib.optional tlsSupport gnutls;
19+ buildInputs = [ zlib pcre ]
20+ ++ lib.optionals (stdenv.system == "x86_64-darwin") [ memorymappingHook memstreamHook ]
21+ ++ lib.optional tlsSupport gnutls;
1922
2023 preConfigure = ''
2124 cd src
pkgs/tools/text/hyx/default.nix+6−11
@@ -1,11 +1,5 @@
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
1+{ lib, stdenv, fetchurl, memstreamHook }:
2+
93stdenv.mkDerivation rec {
104 pname = "hyx";
115 version = "2020-06-09";
@@ -15,11 +9,12 @@ stdenv.mkDerivation rec {
159 sha256 = "1x8dmll93hrnj24kn5knpwj36y6r1v2ygwynpjwrg2hwd4c1a8hi";
1610 };
1711
18− postUnpack = lib.optionalString stdenv.isDarwin ''
19− tar --strip=1 -C $sourceRoot -xf ${memstream} --wildcards "memstream-0.1/memstream.[hc]"
12+ postPatch = lib.optionalString stdenv.isDarwin ''
13+ substituteInPlace Makefile \
14+ --replace "-Wl,-z,relro,-z,now -fpic -pie" ""
2015 '';
2116
22− patches = lib.optional stdenv.isDarwin ./memstream.patch;
17+ buildInputs = lib.optional (stdenv.system == "x86_64-darwin") memstreamHook;
2318
2419 installPhase = ''
2520 install -vD hyx $out/bin/hyx
pkgs/tools/text/hyx/memstream.patchdeleted−31
@@ -1,31 +0,0 @@
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>
pkgs/top-level/all-packages.nix+10
@@ -17896,6 +17896,16 @@ with pkgs;
1789617896
1789717897 mediastreamer-openh264 = callPackage ../development/libraries/mediastreamer/msopenh264.nix { };
1789817898
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+
1789917909 menu-cache = callPackage ../development/libraries/menu-cache { };
1790017910
1790117911 mergerfs = callPackage ../tools/filesystems/mergerfs { };