@@ -1,81 +1,68 @@
{
lib ,
stdenv ,
fetchFromGitHub ,
atf ,
gperf ,
libiconvReal ,
meson ,
ninja ,
mkAppleDerivation ,
pkg-config ,
gitUpdater ,
stdenv ,
} :
let
inherit ( stdenv ) hostPlatform ;
in
stdenv . mkDerivation ( finalAttrs : {
pname = " l i b i c o n v " ;
version = " 9 9 " ;
mkAppleDerivation ( finalAttrs : {
releaseName = " l i b i c o n v " ;
outputs = [
" o u t "
" d e v "
] ;
xcodeHash = " s h a 2 5 6 - w T K a R M q K C 6 T / n x J I E r 6 I l R G g s P w O b g i / s p w 5 g k 2 l A C g = " ;
patches =
lib . optionals hostPlatform . isStatic [
# Use gperf to implement module loading statically by looking up the module functions in the static binary.
./patches/0001-Support-static-module-loading.patch
]
++ [
# Avoid out of bounds write with ISO-2022
./patches/0002-Fix-ISO-2022-out-of-bounds-write-with-encoded-charac.patch
] ;
# Propagate `out` only when there are dylibs to link (i.e., don’ t propagate when doing a static build).
propagatedBuildOutputs = lib . optionalString ( ! hostPlatform . isStatic ) " o u t " ;
src = fetchFromGitHub {
owner = " a p p l e - o s s - d i s t r i b u t i o n s " ;
repo = " l i b i c o n v " ;
rev = " l i b i c o n v - ${ finalAttrs . version } " ;
hash = " s h a 2 5 6 - T G t 6 r s U 5 2 z t f W 2 r C q w n h M A E x L b e x I / 5 9 I o D O G Y + X G u 0 = " ;
} ;
setupHooks =
libiconvReal . setupHooks
++ lib . optionals hostPlatform . isStatic [ ./static-setup-hook.sh ] ;
patches = lib . optionals hostPlatform . isStatic [ ./0001-Support-static-module-loading.patch ] ++ [
./0002-Fix-ISO-2022-out-of-bounds-write-with-encoded-charac.patch
] ;
postPatch =
''
substitute $ { ./meson.build } meson . build - - subst-var version
cp $ { ./meson.options } meson . options
# Work around unnecessary private API usage in libcharset
# Work around unnecessary private API usage in libcharset.
mkdir - p libcharset/os && cat < < - header > libcharset/os/variant_private.h
#pragma once
#include <stdbool.h>
static inline bool os_variant_has_internal_content ( const char * ) { return false ; }
header
# Add additional test cases found while working on packaging libiconv in nixpkgs.
cp $ { ./nixpkgs_test.c } tests/libiconv/nixpkgs_test.c
''
+ lib . optionalString hostPlatform . isStatic ''
cp $ { ./static-modules.gperf } static-modules . gperf
'' ;
strictDeps = true ;
nativeBuildInputs =
[
meson
ninja
]
# Dynamic builds use `dlopen` to load modules, but static builds have to link them all.
# `gperf` is used to generate a lookup table from module to ops functions.
++ lib . optionals hostPlatform . isStatic [ gperf ] ;
mesonBuildType = " r e l e a s e " ;
# Dynamic builds use `dlopen` to load modules, but static builds have to link them all.
# `gperf` is used to generate a lookup table from module to ops functions.
nativeBuildInputs = lib . optionals hostPlatform . isStatic [ gperf ] ;
mesonFlags = [ ( lib . mesonBool " t e s t s " finalAttrs . doInstallCheck ) ] ;
postBuild =
# Add `libcharset.a` contents to `libiconv.a` to duplicate the reexport from `libiconv.dylib`.
lib . optionalString hostPlatform . isStatic ''
$ { stdenv . cc . targetPrefix } ar qL libiconv . a libcharset . a
'' ;
postInstall =
lib . optionalString ( stdenv . hostPlatform . isDarwin && ! hostPlatform . isStatic ) ''
lib . optionalString ( hostPlatform . isDarwin && ! hostPlatform . isStatic ) ''
$ { stdenv . cc . targetPrefix } install_name_tool " $ o u t / l i b / l i b i c o n v . 2 . d y l i b " \
- change ' @ rpath/libcharset.1.dylib ' " $ o u t / l i b / l i b c h a r s e t . 1 . d y l i b "
''
@@ -98,22 +85,12 @@ stdenv.mkDerivation (finalAttrs: {
runHook postInstallCheck
'' ;
passthru . updateScript = gitUpdater { rev-prefix = " l i b i c o n v - " ; } ;
__structuredAttrs = true ;
meta = {
description = " I c o n v ( 3 ) i m p l e m e n t a t i o n " ;
homepage = " h t t p s : / / o p e n s o u r c e . a p p l e . c o m / r e l e a s e s / " ;
license =
with lib . licenses ;
[
bsd2
bsd3
]
++ lib . optional finalAttrs . doInstallCheck apsl10 ;
license = [
lib . licenses . bsd2
lib . licenses . bsd3
] ++ lib . optional finalAttrs . doInstallCheck lib . licenses . apple-psl10 ;
mainProgram = " i c o n v " ;
maintainers = with lib . maintainers ; [ reckenrode ] ;
platforms = lib . platforms . darwin ;
} ;
} )