From 1e4763dd90ad8712b459d1f5e53cbbc047b75dd0 Mon Sep 17 00:00:00 2001 From: Brian Leung Date: Sun, 4 Dec 2022 12:37:26 -0800 Subject: Revert "add tree sitter languages to rpath (#273)" This reverts commit 64b233cc9cfb1239f3725d0c5953581b43148956. --- overlays/emacs.nix | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'overlays') diff --git a/overlays/emacs.nix b/overlays/emacs.nix index 7731175a8bc7..ab16a7250416 100644 --- a/overlays/emacs.nix +++ b/overlays/emacs.nix @@ -83,6 +83,7 @@ let /usr/bin/codesign -s - -f $out/lib/${lib drv} '' else ''ln -s ${drv}/parser $out/lib/${lib drv}''; + linkerFlag = drv: "-l" + libName drv; plugins = with self.pkgs.tree-sitter-grammars; [ tree-sitter-bash tree-sitter-c @@ -100,14 +101,20 @@ let (super.lib.concatStringsSep "\n" (["mkdir -p $out/lib"] ++ (map linkCmd plugins))); in { buildInputs = old.buildInputs ++ [ self.pkgs.tree-sitter tree-sitter-grammars ]; - TREE_SITTER_LIBS = "-ltree-sitter"; - # Add to list of directories dlopen/dynlib_open searches for tree sitter languages *.so/*.dylib. - postFixup = old.postFixup + super.lib.optionalString self.stdenv.isDarwin '' - /usr/bin/install_name_tool -add_rpath ${super.lib.makeLibraryPath [ tree-sitter-grammars ]} $out/bin/emacs - /usr/bin/codesign -s - -f $out/bin/emacs - '' + super.lib.optionalString self.stdenv.isLinux '' - ${self.pkgs.patchelf}/bin/patchelf --add-rpath ${super.lib.makeLibraryPath [ tree-sitter-grammars ]} $out/bin/emacs - ''; + # before building the `.el` files, we need to allow the `tree-sitter` libraries + # bundled in emacs to be dynamically loaded. + TREE_SITTER_LIBS = super.lib.concatStringsSep " " ([ "-ltree-sitter" ] ++ (map linkerFlag plugins)); + # Add to directories that tree-sitter looks in for language definitions / shared object parsers + # FIXME: This was added for macOS, but it shouldn't be necessary on any platform. + # https://git.savannah.gnu.org/cgit/emacs.git/tree/src/treesit.c?h=64044f545add60e045ff16a9891b06f429ac935f#n533 + # appends a bunch of filenames that appear to be incorrectly skipped over + # in https://git.savannah.gnu.org/cgit/emacs.git/tree/src/treesit.c?h=64044f545add60e045ff16a9891b06f429ac935f#n567 + # on macOS, but are handled properly in Linux. + postPatch = old.postPatch + super.lib.optionalString super.stdenv.isDarwin '' + substituteInPlace src/treesit.c \ + --replace "Vtreesit_extra_load_path = Qnil;" \ + "Vtreesit_extra_load_path = list1 ( build_string ( \"${tree-sitter-grammars}/lib\" ) );" + ''; } ) ))); -- cgit 1.4.1