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
22 changes: 11 additions & 11 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, binutils, clang ? null, binutils-unwrapped, makeWrapper # native-comp params
, systemd ? null
, withX ? !stdenv.isDarwin
, withNS ? stdenv.isDarwin
Expand Down Expand Up @@ -67,18 +67,18 @@ 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"
];
libPath = (lib.concatStringsSep " "
(builtins.map (x: ''\"-L${x}\"'') [
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we should use -B here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean for binutils's ld? Darwin's ld does not support any -B options, as far as I can tell.

Copy link
Member

Choose a reason for hiding this comment

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

I think -B is a CC flag, so it's gcc that handles it. I think gccemacs only cares about library files, so I'm not sure if the -L vs. -B is relevant though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, it may depend on whether libgccjit recognizes that option as a "driver" option (vs. a "frontend" option I guess?) - the manual warns that only options for the assembler or linker will be meaningful as "driver options". Definitely something to experiment with, though!

Copy link
Contributor

@mjlbach mjlbach Aug 30, 2020

Choose a reason for hiding this comment

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

Yes, the guix packaging for native-comp explicitly uses the -B option flatwhatson/guix-channel@f9bf0a4 else it complains about not finding crti.o, crtbeginS.o, and -lgcc. I haven't been able to compile this successfully else I'd test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fascinating! I'll try that - might also help us get rid of the need to use wrapProgram to set paths to the linker and assembler.

Copy link
Contributor

@mjlbach mjlbach Sep 1, 2020

Choose a reason for hiding this comment

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

Ok, just confirmed that on linux building with the -B option is necessary for straight.el to compile packages outside of nix else it segfaults.

"${lib.getLib libgccjit}/lib"
"${lib.getLib libgccjit}/lib/gcc/${targetPlatform.config}/${libgccjit.version}"
"${lib.getLib stdenv.cc.cc}/lib"
antifuchs marked this conversation as resolved.
Show resolved Hide resolved
"${lib.getLib stdenv.cc.libc}/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}\")) \":\")))"

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

""
];

Expand Down Expand Up @@ -158,7 +158,7 @@ in stdenv.mkDerivation {
'')

(lib.optionalString nativeComp ''
wrapProgram $out/bin/emacs-* --prefix PATH : "${lib.makeBinPath [ binutils binutils-unwrapped ]}"
wrapProgram $out/bin/emacs-* --prefix PATH : "${lib.makeBinPath [ clang.bintools binutils binutils-unwrapped ]}"
antifuchs marked this conversation as resolved.
Show resolved Hide resolved
'')

];
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'
''