Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gettext: adopt and update #299647

Closed
wants to merge 13 commits into from
54 changes: 54 additions & 0 deletions pkgs/by-name/ge/gettext/003-revert-avoid-crash-on-macos-14.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
From 2f702ed832b2aa0feaa1948104eb0388943177e6 Mon Sep 17 00:00:00 2001
From: Weijia Wang <contact@weijia.wang>
Date: Sun, 7 Jan 2024 01:27:16 +0100
Subject: [PATCH] Revert "Avoid crash on macOS 14."

This reverts commit 1bcf74a9fa6dcf33645f54a854dc49387e76a40b.
---
gettext-runtime/configure | 2 +-
gettext-runtime/intl/configure | 2 +-
gettext-tools/configure | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gettext-runtime/configure b/gettext-runtime/configure
index 2a376c6..88c9312 100755
--- a/gettext-runtime/configure
+++ b/gettext-runtime/configure
@@ -22421,7 +22421,7 @@ printf "%s\n" "#define HAVE_CFLOCALECOPYPREFERREDLANGUAGES 1" >>confdefs.h
INTL_MACOSX_LIBS=
if test $gt_cv_func_CFPreferencesCopyAppValue = yes \
|| test $gt_cv_func_CFLocaleCopyPreferredLanguages = yes; then
- INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation -Wl,-framework -Wl,CoreServices"
+ INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation"
fi


diff --git a/gettext-runtime/intl/configure b/gettext-runtime/intl/configure
index 8bea363..78f70d7 100755
--- a/gettext-runtime/intl/configure
+++ b/gettext-runtime/intl/configure
@@ -17428,7 +17428,7 @@ printf "%s\n" "#define HAVE_CFLOCALECOPYPREFERREDLANGUAGES 1" >>confdefs.h
INTL_MACOSX_LIBS=
if test $gt_cv_func_CFPreferencesCopyAppValue = yes \
|| test $gt_cv_func_CFLocaleCopyPreferredLanguages = yes; then
- INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation -Wl,-framework -Wl,CoreServices"
+ INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation"
fi


diff --git a/gettext-tools/configure b/gettext-tools/configure
index 5ce6cf1..08f1062 100755
--- a/gettext-tools/configure
+++ b/gettext-tools/configure
@@ -25810,7 +25810,7 @@ printf "%s\n" "#define HAVE_CFLOCALECOPYPREFERREDLANGUAGES 1" >>confdefs.h
INTL_MACOSX_LIBS=
if test $gt_cv_func_CFPreferencesCopyAppValue = yes \
|| test $gt_cv_func_CFLocaleCopyPreferredLanguages = yes; then
- INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation -Wl,-framework -Wl,CoreServices"
+ INTL_MACOSX_LIBS="-Wl,-framework -Wl,CoreFoundation"
fi


--
2.39.3 (Apple Git-145)

125 changes: 125 additions & 0 deletions pkgs/by-name/ge/gettext/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{ lib
, bash
, darwin
, fetchurl
, libiconv
, stdenv
, xz

, enableCoreServices ? stdenv.isDarwin
# HACK, see #10874 (and 14664)
, enableLibiconv ? (!stdenv.isLinux && !stdenv.hostPlatform.isCygwin)
}:

# Note: this package is used for bootstrapping fetchurl, and thus cannot use
# fetchpatch! All mutable patches (retrieved via by GitHub, cgit or similar
# means) that perhaps are needed here should be included directly in Nixpkgs as
# regular files inside this same directory.

stdenv.mkDerivation (finalAttrs: ({
pname = "gettext";
version = "0.22.5";

src = fetchurl {
url = "mirror://gnu/gettext/gettext-${finalAttrs.version}.tar.gz";
hash = "sha256-7BcFselpuDqfBzFE7IBhUduIEn9eQP5alMtsj6SJlqA=";
};

patches = [
# Parameterize some tools to their absolute paths in gettext.sh.in
./001-absolute-paths.diff
# fix reproducibile output, in particular in the grub2 build
# https://savannah.gnu.org/bugs/index.php?59658
./002-msginit-do-not-use-pot-creation-date.patch
]
++ lib.optionals enableCoreServices [
# prevent infinite recursion for the darwin stdenv
./003-revert-avoid-crash-on-macos-14.patch
];
Comment on lines +34 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
]
++ lib.optionals enableCoreServices [
# prevent infinite recursion for the darwin stdenv
./003-revert-avoid-crash-on-macos-14.patch
];
];
propagatedBuildInputs = lib.optionals enableCoreServices [
# prevent infinite recursion for the darwin stdenv
./003-revert-avoid-crash-on-macos-14.patch
];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When autoreconfPhase is run with the new gettext, m4/intlmacosx.m4 is updated, adding CoreServices as a dependency of the original package.

Copy link
Contributor

@reckenrode reckenrode May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After rebuilding the stdenv with this change, there is one downside. It requires adding CoreServices and its propagated inputs the Darwin stdenv’s allowedRequisites, which differ depending on the SDK.

Is it possible to add a dev output to gettext, so CoreServices is propagated from it instead of out?

I used the following (with CoreServices as a regular build input) to successfully rebuild the Darwin stdenv. libpsl is an example of a package that needs CoreServices propagated to it. It also built successfully.

I also split the hook into two hooks. The one copied into $out sets up GETTEXTDATADIRS while the other ensures that libintl is linked.

  # Two setup hooks are needed. One is for making sure gettext can find its data files at runtime, and the other
  # is to make sure `libintl` is linked even on non-glibc targets. This is the latter hook. The other is below.
  setupHooks = [
    ../../../build-support/setup-hooks/role.bash
    ./gettext-setup-hook-dev.sh
  ];

  postInstall = ''
    mkdir -p "$out/nix-support"
    cat ${../../../build-support/setup-hooks/role.bash} ${./gettext-setup-hook.sh} > "$out/nix-support/setup-hook"
  '';

Edit: CoreServices needs to be in propagatedBuildInputs for it to be picked up by overrideSDK. Otherwise, anything that needs a non-default SDK and uses gettext won’t build (e.g., Wine).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will wait your modifications before migrating this, since I don't and I won't have a Darwin machine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifications to the existing gettext package? I can open a PR (or PRs, depending) for those.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migration to by-name will be a little bit harder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the hooks? I cheated with libiconv-darwin (by reexporting them from libiconvReal and using those), but I don’t think that will be possible here.


outputs = [ "out" "man" "doc" "info" ];

hardeningDisable = [ "format" ];

configureFlags = [
(lib.enableFeature false "csharp")
(lib.withFeature true "xz")
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
# On cross building, gettext supposes that the wchar.h from libc does not
# fulfill gettext needs, so it tries to work with its own wchar.h file,
# which does not cope well with the system's wchar.h and stddef.h (gcc-4.3 -
# glibc-2.9)
"gl_cv_func_wcwidth_works=yes"
];

postPatch = ''
substituteAllInPlace gettext-runtime/src/gettext.sh.in
substituteInPlace gettext-tools/projects/KDE/trigger --replace "/bin/pwd" pwd
substituteInPlace gettext-tools/projects/GNOME/trigger --replace "/bin/pwd" pwd
substituteInPlace gettext-tools/src/project-id --replace "/bin/pwd" pwd
'' + lib.optionalString stdenv.hostPlatform.isCygwin ''
sed -i -e "s/\(cldr_plurals_LDADD = \)/\\1..\/gnulib-lib\/libxml_rpl.la /" gettext-tools/src/Makefile.in
sed -i -e "s/\(libgettextsrc_la_LDFLAGS = \)/\\1..\/gnulib-lib\/libxml_rpl.la /" gettext-tools/src/Makefile.in
'' + lib.optionalString stdenv.hostPlatform.isMinGW ''
sed -i "s/@GNULIB_CLOSE@/1/" */*/unistd.in.h
'';

nativeBuildInputs = [
xz
(lib.getBin xz)
];

buildInputs = lib.optionals (!stdenv.hostPlatform.isMinGW) [
bash
]
++ lib.optionals enableLibiconv [
libiconv
]
++ lib.optionals enableCoreServices [
darwin.apple_sdk.frameworks.CoreServices
];

strictDeps = true;

env = {
LDFLAGS = lib.optionalString stdenv.isSunOS "-lm -lmd -lmp -luutil -lnvpair -lnsl -lidmap -lavl -lsec";
gettextNeedsLdflags = stdenv.hostPlatform.libc != "glibc" && !stdenv.hostPlatform.isMusl;
};

enableParallelBuilding = true;
enableParallelChecking = false; # fails sometimes

setupHooks = [
../../../build-support/setup-hooks/role.bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it won't pass the by-name check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am cogitating to write a dummy package that installs those scripts at Nix Store.

./gettext-setup-hook.sh
];

meta = {
homepage = "https://www.gnu.org/software/gettext/";
description = "Well integrated set of translation tools and documentation";
longDescription = ''
Usually, programs are written and documented in English, and use English
at execution time for interacting with users. Using a common language is
quite handy for communication between developers, maintainers and users
from all countries. On the other hand, most people are less comfortable
with English than with their own native language, and would rather be
using their mother tongue for day to day's work, as far as possible. Many
would simply love seeing their computer screen showing a lot less of
English, and far more of their own language.

GNU gettext is an important step for the GNU Translation Project, as it is
an asset on which we may build many other steps. This package offers to
programmers, translators, and even users, a well integrated set of tools
and documentation. Specifically, the GNU gettext utilities are a set of
tools that provides a framework to help other GNU packages produce
multi-lingual messages.
'';
mainProgram = "gettext";
maintainers = with lib.maintainers; [ zimbatm AndersonTorres ];
license = with lib.licenses; [ gpl2Plus ];
platforms = lib.platforms.all;
};
}
// lib.optionalAttrs stdenv.isDarwin {
makeFlags = [ "CFLAGS=-D_FORTIFY_SOURCE=0" ];
}))
108 changes: 0 additions & 108 deletions pkgs/development/libraries/gettext/default.nix

This file was deleted.

10 changes: 10 additions & 0 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ in
buildInputs = old.buildInputs ++ [ self.darwin.CF ];
});

# Don’t link CoreServices during the bootstrap to prevent an infinite recursion.
gettext = super.gettext.override { enableCoreServices = false; };

# Disable tests because they use dejagnu, which fails to run.
libffi = super.libffi.override { doCheck = false; };

Expand Down Expand Up @@ -1034,6 +1037,13 @@ in
# LLVM dependencies - don’t rebuild them.
libffi libiconv libxml2 ncurses zlib;

# Use CoreServices from the previous stage to avoid an infinite recursion.
gettext = super.gettext.override {
darwin.apple_sdk.frameworks = {
inherit (prevStage.darwin.apple_sdk.frameworks) CoreServices;
};
};

darwin = super.darwin.overrideScope (selfDarwin: superDarwin: {
inherit (prevStage.darwin) dyld CF Libsystem darwin-stubs
# CF dependencies - don’t rebuild them.
Expand Down
5 changes: 4 additions & 1 deletion pkgs/stdenv/linux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ in
configureFlags = (a.configureFlags or []) ++ [
"--with-native-system-header-dir=/include"
"--with-build-sysroot=${lib.getDev final.stdenv.cc.libc}"
# Don't assume that `gettext` was built with iconv support, since
# we don't have our own `glibc` yet.
"--disable-nls"
];

# This is a separate phase because gcc assembles its phase scripts
Expand Down Expand Up @@ -499,7 +502,7 @@ in
overrides = self: super: rec {
inherit (prevStage)
ccWrapperStdenv
binutils coreutils gnugrep gettext
binutils coreutils gnugrep
perl patchelf linuxHeaders gnum4 bison libidn2 libunistring libxcrypt;
# We build a special copy of libgmp which doesn't use libstdc++, because
# xgcc++'s libstdc++ references the bootstrap-files (which is what
Expand Down
2 changes: 0 additions & 2 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21117,8 +21117,6 @@ with pkgs;
inherit (callPackages ../development/libraries/getdns { })
getdns stubby;

gettext = callPackage ../development/libraries/gettext { };

gf2x = callPackage ../development/libraries/gf2x { };

gfxstream = callPackage ../development/libraries/gfxstream { };
Expand Down
Loading