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

emacs: Make gccemacs build on darwin #94637

Merged
merged 10 commits into from
Sep 2, 2020
30 changes: 15 additions & 15 deletions pkgs/applications/editors/emacs/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
, 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
, libgccjit, targetPlatform, makeWrapper # native-comp params
, systemd ? null
, withX ? !stdenv.isDarwin
, withNS ? stdenv.isDarwin
Expand Down Expand Up @@ -67,18 +67,23 @@ in stdenv.mkDerivation {

# 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"
];
backendPath = (lib.concatStringsSep " "
(builtins.map (x: ''\"-B${x}\"'') [
# Paths necessary so the JIT compiler finds its libraries:
"${lib.getLib libgccjit}/lib"
"${lib.getLib libgccjit}/lib/gcc"
"${lib.getLib stdenv.cc.libc}/lib"

# Executable paths necessary for compilation (ld, as):
"${lib.getBin stdenv.cc.cc}"
"${lib.getBin stdenv.cc.bintools}"
"${lib.getBin stdenv.cc.bintools.bintools}"
]));
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}\")) \":\")))"

"(defcustom comp-native-driver-options nil" \
"(defcustom comp-native-driver-options '(${backendPath})"
''))

""
];

Expand Down Expand Up @@ -156,11 +161,6 @@ in stdenv.mkDerivation {
"$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 = {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/9/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ stdenv.mkDerivation ({

preConfigure = import ../common/pre-configure.nix {
inherit (stdenv) lib;
inherit version hostPlatform gnatboot langAda langGo;
inherit version hostPlatform gnatboot langAda langGo langJit;
};

dontDisableStatic = true;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/gcc/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ postInstall() {
fi

if type "install_name_tool"; then
for i in "${!outputLib}"/lib/*.*.dylib; do
for i in "${!outputLib}"/lib/*.*.dylib "${!outputLib}"/lib/*.so.[0-9]; do
Copy link
Member

Choose a reason for hiding this comment

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

Is it a bug in gcc buildsystem that they install libgccjit as .so file?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, looks like it. They still make weird linux-soname based assumptions around how the structure works, but I think we could just set this as a make variable (or patch it) to fix. Probably the better way to fix it!

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@Mic92 Mic92 Aug 5, 2020

Choose a reason for hiding this comment

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

Anyway if you don't patch the build system would it not be better to rename it from .so to .dylib?

install_name_tool -id "$i" "$i" || true
for old_path in $(otool -L "$i" | grep "$out" | awk '{print $1}'); do
new_path=`echo "$old_path" | sed "s,$out,${!outputLib},"`
Expand Down
9 changes: 9 additions & 0 deletions pkgs/development/compilers/gcc/common/pre-configure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
, gnatboot ? null
, langAda ? false
, langJava ? false
, langJit ? false
, langGo }:

assert langJava -> lib.versionOlder version "7";
Expand Down Expand Up @@ -49,3 +50,11 @@ lib.optionalString (hostPlatform.isSunOS && hostPlatform.is64bit) ''
+ lib.optionalString (hostPlatform.isDarwin) ''
export ac_cv_func_aligned_alloc=no
''

# In order to properly install libgccjit on macOS Catalina, strip(1)
# upon installation must not remove external symbols, otherwise the
# install step errors with "symbols referenced by indirect symbol
# table entries that can't be stripped".
+ lib.optionalString (hostPlatform.isDarwin && langJit) ''
export STRIP='strip -x'
''