2024-05-15 15:35:15 +00:00
|
|
|
|
{
|
|
|
|
|
lib,
|
|
|
|
|
stdenv,
|
|
|
|
|
fetchFromGitHub,
|
|
|
|
|
atf,
|
2024-06-20 14:57:18 +00:00
|
|
|
|
gperf,
|
2024-05-15 15:35:15 +00:00
|
|
|
|
libiconvReal,
|
|
|
|
|
meson,
|
|
|
|
|
ninja,
|
|
|
|
|
pkg-config,
|
|
|
|
|
gitUpdater,
|
|
|
|
|
}:
|
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
|
let
|
|
|
|
|
inherit (stdenv) hostPlatform;
|
|
|
|
|
in
|
2024-05-15 15:35:15 +00:00
|
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
|
|
|
|
pname = "libiconv";
|
|
|
|
|
version = "99";
|
|
|
|
|
|
|
|
|
|
outputs = [
|
|
|
|
|
"out"
|
|
|
|
|
"dev"
|
|
|
|
|
];
|
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
|
# Propagate `out` only when there are dylibs to link (i.e., don’t propagate when doing a static build).
|
|
|
|
|
propagatedBuildOutputs = lib.optionalString (!hostPlatform.isStatic) "out";
|
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
|
owner = "apple-oss-distributions";
|
|
|
|
|
repo = "libiconv";
|
|
|
|
|
rev = "libiconv-${finalAttrs.version}";
|
|
|
|
|
hash = "sha256-TGt6rsU52ztfW2rCqwnhMAExLbexI/59IoDOGY+XGu0=";
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
|
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
|
|
|
|
|
];
|
2024-05-15 15:35:15 +00:00
|
|
|
|
|
|
|
|
|
postPatch =
|
|
|
|
|
''
|
|
|
|
|
substitute ${./meson.build} meson.build --subst-var version
|
|
|
|
|
cp ${./meson.options} meson.options
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
cp ${./nixpkgs_test.c} tests/libiconv/nixpkgs_test.c
|
2024-06-20 14:57:18 +00:00
|
|
|
|
''
|
|
|
|
|
+ lib.optionalString hostPlatform.isStatic ''
|
|
|
|
|
cp ${./static-modules.gperf} static-modules.gperf
|
2024-05-15 15:35:15 +00:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
strictDeps = true;
|
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
|
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 ];
|
2024-05-15 15:35:15 +00:00
|
|
|
|
|
|
|
|
|
mesonBuildType = "release";
|
|
|
|
|
|
|
|
|
|
mesonFlags = [ (lib.mesonBool "tests" finalAttrs.doInstallCheck) ];
|
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
|
postInstall =
|
|
|
|
|
lib.optionalString (stdenv.isDarwin && !hostPlatform.isStatic) ''
|
|
|
|
|
${stdenv.cc.targetPrefix}install_name_tool "$out/lib/libiconv.2.dylib" \
|
|
|
|
|
-change '@rpath/libcharset.1.dylib' "$out/lib/libcharset.1.dylib"
|
|
|
|
|
''
|
|
|
|
|
# Move the static library to the `dev` output
|
|
|
|
|
+ lib.optionalString hostPlatform.isStatic ''
|
|
|
|
|
moveToOutput lib "$dev"
|
|
|
|
|
'';
|
2024-05-15 15:35:15 +00:00
|
|
|
|
|
|
|
|
|
# Tests have to be run in `installCheckPhase` because libiconv expects to `dlopen`
|
|
|
|
|
# modules from `$out/lib/i18n`.
|
|
|
|
|
nativeInstallCheckInputs = [ pkg-config ];
|
|
|
|
|
installCheckInputs = [ atf ];
|
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
|
doInstallCheck = stdenv.buildPlatform.canExecute hostPlatform;
|
2024-05-15 15:35:15 +00:00
|
|
|
|
|
|
|
|
|
# Can’t use `mesonCheckPhase` because it runs the wrong hooks for `installCheckPhase`.
|
|
|
|
|
installCheckPhase = ''
|
|
|
|
|
runHook preInstallCheck
|
|
|
|
|
meson test --no-rebuild
|
|
|
|
|
runHook postInstallCheck
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
passthru.updateScript = gitUpdater { rev-prefix = "libiconv-"; };
|
|
|
|
|
|
|
|
|
|
__structuredAttrs = true;
|
|
|
|
|
|
|
|
|
|
meta = {
|
2024-06-20 14:57:18 +00:00
|
|
|
|
description = "Iconv(3) implementation";
|
2024-05-15 15:35:15 +00:00
|
|
|
|
homepage = "https://opensource.apple.com/releases/";
|
|
|
|
|
license =
|
|
|
|
|
with lib.licenses;
|
|
|
|
|
[
|
|
|
|
|
bsd2
|
|
|
|
|
bsd3
|
|
|
|
|
]
|
|
|
|
|
++ lib.optional finalAttrs.doInstallCheck apsl10;
|
|
|
|
|
mainProgram = "iconv";
|
|
|
|
|
maintainers = with lib.maintainers; [ reckenrode ];
|
|
|
|
|
platforms = lib.platforms.darwin;
|
|
|
|
|
};
|
|
|
|
|
})
|