1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-06 12:33:51 +00:00

Merge pull request #93716 from adisbladis/emacs-native-comp

emacs: Add infrastructure for native-comp
This commit is contained in:
adisbladis 2020-07-24 13:15:22 +02:00 committed by GitHub
commit ea63a04660
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 20 deletions

View file

@ -2,6 +2,8 @@
, Xaw3d, libXcursor, pkgconfig, gettext, libXft, dbus, libpng, libjpeg, libungif
, libtiff, librsvg, gconf, libxml2, imagemagick, gnutls, libselinux
, alsaLib, cairo, acl, gpm, AppKit, GSS, ImageIO, m17n_lib, libotf
, jansson, harfbuzz
, libgccjit, targetPlatform, binutils, binutils-unwrapped, makeWrapper # native-comp params
, systemd ? null
, withX ? !stdenv.isDarwin
, withNS ? stdenv.isDarwin
@ -11,6 +13,7 @@
, withCsrc ? true
, srcRepo ? false, autoconf ? null, automake ? null, texinfo ? null
, siteStart ? ./site-start.el
, nativeComp ? false
, toolkit ? (
if withGTK2 then "gtk2"
else if withGTK3 then "gtk3"
@ -28,10 +31,13 @@ assert withGTK3 -> !withGTK2 && gtk3-x11 != null;
assert withXwidgets -> withGTK3 && webkitgtk != null;
stdenv.mkDerivation rec {
name = "emacs-${version}${versionModifier}";
let
version = "26.3";
versionModifier = "";
name = "emacs-${version}${versionModifier}";
in stdenv.mkDerivation {
inherit name version;
src = fetchurl {
url = "mirror://gnu/emacs/${name}.tar.xz";
@ -50,29 +56,50 @@ stdenv.mkDerivation rec {
})
];
postPatch = lib.optionalString srcRepo ''
rm -fr .git
'';
postPatch = lib.concatStringsSep "\n" [
(lib.optionalString srcRepo ''
rm -fr .git
'')
# Make native compilation work both inside and outside of nix build
(lib.optionalString nativeComp (let
libPath = lib.concatStringsSep ":" [
"${lib.getLib libgccjit}/lib/gcc/${targetPlatform.config}/${libgccjit.version}"
"${lib.getLib stdenv.cc.cc}/lib"
"${lib.getLib stdenv.glibc}/lib"
];
in ''
substituteInPlace lisp/emacs-lisp/comp.el --replace \
"(defcustom comp-async-env-modifier-form nil" \
"(defcustom comp-async-env-modifier-form '((setenv \"LIBRARY_PATH\" (string-join (seq-filter (lambda (v) (null (eq v nil))) (list (getenv \"LIBRARY_PATH\") \"${libPath}\")) \":\")))"
''))
""
];
CFLAGS = "-DMAC_OS_X_VERSION_MAX_ALLOWED=101200";
nativeBuildInputs = [ pkgconfig ]
LIBRARY_PATH = if nativeComp then "${lib.getLib stdenv.cc.libc}/lib" else "";
nativeBuildInputs = [ pkgconfig makeWrapper ]
++ lib.optionals srcRepo [ autoconf automake texinfo ]
++ lib.optional (withX && (withGTK3 || withXwidgets)) wrapGAppsHook;
buildInputs =
[ ncurses gconf libxml2 gnutls alsaLib acl gpm gettext ]
[ ncurses gconf libxml2 gnutls alsaLib acl gpm gettext jansson harfbuzz.dev ]
++ lib.optionals stdenv.isLinux [ dbus libselinux systemd ]
++ lib.optionals withX
[ xlibsWrapper libXaw Xaw3d libXpm libpng libjpeg libungif libtiff libXft
gconf ]
gconf cairo ]
++ lib.optionals (withX || withNS) [ imagemagick librsvg ]
++ lib.optionals (stdenv.isLinux && withX) [ m17n_lib libotf ]
++ lib.optional (withX && withGTK2) gtk2-x11
++ lib.optionals (withX && withGTK3) [ gtk3-x11 gsettings-desktop-schemas ]
++ lib.optional (stdenv.isDarwin && withX) cairo
++ lib.optionals (withX && withXwidgets) [ webkitgtk glib-networking ]
++ lib.optionals withNS [ AppKit GSS ImageIO ];
++ lib.optionals withNS [ AppKit GSS ImageIO ]
++ lib.optionals nativeComp [ libgccjit ]
;
hardeningDisable = [ "format" ];
@ -88,7 +115,9 @@ stdenv.mkDerivation rec {
then [ "--with-x-toolkit=${toolkit}" "--with-xft" ]
else [ "--with-x=no" "--with-xpm=no" "--with-jpeg=no" "--with-png=no"
"--with-gif=no" "--with-tiff=no" ])
++ lib.optional withXwidgets "--with-xwidgets";
++ lib.optional withXwidgets "--with-xwidgets"
++ lib.optional nativeComp "--with-nativecomp"
;
preConfigure = lib.optionalString srcRepo ''
./autogen.sh
@ -106,13 +135,16 @@ stdenv.mkDerivation rec {
postInstall = ''
mkdir -p $out/share/emacs/site-lisp
cp ${siteStart} $out/share/emacs/site-lisp/site-start.el
$out/bin/emacs --batch -f batch-byte-compile $out/share/emacs/site-lisp/site-start.el
siteVersionDir=`ls $out/share/emacs | grep -v site-lisp | head -n 1`
rm -rf $out/var
rm -rf $out/share/emacs/${version}/site-lisp
rm -rf $siteVersionDir
'' + lib.optionalString withCsrc ''
for srcdir in src lisp lwlib ; do
dstdir=$out/share/emacs/${version}/$srcdir
dstdir=$siteVersionDir/$srcdir
mkdir -p $dstdir
find $srcdir -name "*.[chm]" -exec cp {} $dstdir \;
cp $srcdir/TAGS $dstdir
@ -123,16 +155,24 @@ stdenv.mkDerivation rec {
mv nextstep/Emacs.app $out/Applications
'';
postFixup =
let libPath = lib.makeLibraryPath [
libXcursor
];
in lib.optionalString (stdenv.isLinux && withX && toolkit == "lucid") ''
postFixup = lib.concatStringsSep "\n" [
(lib.optionalString (stdenv.isLinux && withX && toolkit == "lucid") ''
patchelf --set-rpath \
"$(patchelf --print-rpath "$out/bin/emacs"):${libPath}" \
"$(patchelf --print-rpath "$out/bin/emacs"):${lib.makeLibraryPath [ libXcursor ]}" \
"$out/bin/emacs"
patchelf --add-needed "libXcursor.so.1" "$out/bin/emacs"
'';
'')
(lib.optionalString nativeComp ''
wrapProgram $out/bin/emacs-* --prefix PATH : "${lib.makeBinPath [ binutils binutils-unwrapped ]}"
'')
];
passthru = {
inherit nativeComp;
};
meta = with stdenv.lib; {
description = "The extensible, customizable GNU text editor";

View file

@ -56,6 +56,16 @@ stdenv.mkDerivation ({
meta = defaultMeta // meta;
}
// lib.optionalAttrs (emacs.nativeComp or false) {
LIBRARY_PATH = "${lib.getLib stdenv.cc.libc}/lib";
postInstall = ''
find $out/share/emacs -type f -name '*.el' -print0 | xargs -0 -n 1 -I {} -P $NIX_BUILD_CORES sh -c "emacs --batch -f batch-native-compile {} || true"
'';
}
// removeAttrs args [ "buildInputs" "packageRequires"
"meta"
])