jalvesaq / Nvim-R

Vim plugin to work with R
GNU General Public License v2.0
959 stars 124 forks source link

Error when building with Nix home-manager on MacOS #745

Closed vegabook closed 1 year ago

vegabook commented 1 year ago

Here is the neovim part of my home.nix which as you can see contains a build instruction for Nvim-R

programs.neovim = {
    enable = true;
    defaultEditor = true;
    viAlias = true;
    vimAlias = true;
    vimdiffAlias = true;
    plugins = with pkgs.vimPlugins; [
      nvim-lspconfig
      nvim-treesitter.withAllGrammars
      gruvbox-material
      gruvbox
      nerdtree
      copilot-vim
      lush-nvim
      zenbones-nvim
      (fromGitHub "3145169593555bef72dca5b164779983f6e64974" "jalvesaq/Nvim-R")
    ];

For completeness, function fromGitHub is this:

{ config, pkgs, lib, ... }:

let
  fromGitHub = rev: repo: pkgs.vimUtils.buildVimPluginFrom2Nix {
    pname = "${lib.strings.sanitizeDerivationName repo}";
    version = rev;
    src = builtins.fetchGit {
      url = "https://github.com/${repo}.git";
      rev = rev;
    };
  };
in
{....

However when loading an r file Nvim-R tries to install nvimcom, which fails, and :RDebugInfo gives this:

RInitOut
* checking for file ‘/nix/store/mc2pqbzf69jdkcn3q5xyn6kmfs5s3hqx-vimplugin-jalvesaq-Nvim-R-3145169593555bef72dca5b16477
9983f6e64974/R/nvimcom/DESCRIPTION’ ...

OK
* preparing ‘nvimcom’:
* checking DESCRIPTION meta-information ...
 OK
* cleaning src
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘nvimcom_0.9-146.tar.gz’
/nix/store/y432q34aj5h9qn5qzm4w066j5l5dhmd2-clang-wrapper-11.1.0/bin/cc -I"/nix/store/jic6smsgyb90gilixjkj0xm42vwca2l1-
R-4.3.1/lib/R/include" -DNDEBUG   -isystem /nix/store/fhi1x6ysq2fs88ajb8w6x4z04gkaymdg-libcxx-11.1.0-dev/include/c++/v1
    -fPIC  -g -O2  -c nvimcom.c -o nvimcom.o
/nix/store/y432q34aj5h9qn5qzm4w066j5l5dhmd2-clang-wrapper-11.1.0/bin/cc -I"/nix/store/jic6smsgyb90gilixjkj0xm42vwca2l1-
R-4.3.1/lib/R/include" -DNDEBUG   -isystem /nix/store/fhi1x6ysq2fs88ajb8w6x4z04gkaymdg-libcxx-11.1.0-dev/include/c++/v1
    -fPIC  -g -O2  -c rd2md.c -o rd2md.o
/nix/store/y432q34aj5h9qn5qzm4w066j5l5dhmd2-clang-wrapper-11.1.0/bin/cc -dynamiclib -Wl,-headerpad_max_install_names -u
ndefined dynamic_lookup -single_module -multiply_defined suppress -L/nix/store/jic6smsgyb90gilixjkj0xm42vwca2l1-R-4.3.1
/lib/R/lib -L/nix/store/hbaykxf3scgcmhj92r1i57jz8nl1ngyf-libcxx-11.1.0/lib -o nvimcom.so nvimcom.o rd2md.o -L/nix/store
/jic6smsgyb90gilixjkj0xm42vwca2l1-R-4.3.1/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation
Why build nvimcom
Nvimcom not installed
RInitErr

.build_packages() exit status 0
* installing to library ‘/Users/mmai/Library/R/arm64/4.3/library’
* installing *source* package ‘nvimcom’ ...
** using staged installation
** libs
using C compiler: ‘clang version 11.1.0’
using SDK: ‘’
ld: library not found for -lintl
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/nix/store/jic6smsgyb90gilixjkj0xm42vwca2l1-R-4.3.1/lib/R/share/make/shlib.mk:10: nvimcom.so] Error 1
ERROR: compilation failed for package ‘nvimcom’
* removing ‘/Users/mmai/Library/R/arm64/4.3/library/nvimcom’
Error in do_exit(status = status) : .install_packages() exit status 1
Error in do_exit(status = status) : .install_packages() exit status 1 Execution halted

Seems like it cannot find the sdk libraries. I've tried various approaches to adding library paths including this stack overflow answer but no luck. Any idea what's going on here? Ideally I'd like to try to compile nvimcom from outside the neovim environment so that I can narrow things down a bit. What is the command for that?

jalvesaq commented 1 year ago

The nvimcom code is not internationalized, so you should not need -lintl. I don't see this and many other arguments that appear in your output when I compile nvimcom on Linux. To build nvimcom manually, do this:

R CMD build /path/to/Nvim-R/R/nvimcom
R CMD INSTALL nvimcom_0.9-147.tar.gz
vegabook commented 1 year ago

Thanks going to close it as I can't get it working. Personal view is that it would be good for there to be an option to install nvimcom outside of Nvim-R, rather than it installing it through a first-run script. This would allow for easier packaging under Nix which encourages OS package manager-level installation of language libraries, so that it can manage the dependency chain in one place (which it does extremely well). Keeping in mind that Ubuntu 23.04 is already moving that way (starting with Python).

jalvesaq commented 1 year ago

They can be packaged separately if the packaging system allows dependency on a specific version of another package. The current Vim/Neovim's Nvim-R package should depend on the R's nvimcom-0.9-147 package. If someone wants to package it and needs any changes, I can make the necessary changes in this repository. For example, adding the condition "Don't check nvimcom's version if the nvimcom directory does not exist", which would be true if the Vim and R parts of Nvim-R were packaged separately.

Nvim-R is already packaged for Archlinux: https://aur.archlinux.org/packages/nvim-r. But nobody asked for any change to build this package, and I don't use Archlinux. I'm on Debian testing now.

vegabook commented 1 year ago

I'll take a look thank you. If I can find a spare day I might look at trying to build a nix version. Nix does indeed tie dependencies together strictly by version, indeed by dependency trees linked by binary hashes so it's extremely reliable and allows for multiple versions to be managed separately on the system. Nix btw is available on most Linux distributions and indeed on MacOS (I use it on Ubuntu 22.04 and Darwin) so it's a nice way to have one cross-platform and cross-distro-version package. There are lots of R packages on it already, and the ecosystem is becoming quite popular. Anyway pitch over. Nice package thank you for writing as I said as I grow into this ecosystem I might try to see if I can get Nvim-R in there.

jalvesaq commented 1 year ago

I already did the change that I mentioned. Of course, the change was not tested in a real-case situation.