Repository: spack/spack

Issue:
Installation issue: neovim 'E970: Failed to initialize lua interpreter'
### Steps to reproduce the issue

```console
$ spack spec -I neovim%gcc ^curl tls=openssl ^lua-luajit ^tar zip=gzip
Input spec
--------------------------------
 -   neovim%gcc
 -       ^curl tls=openssl
 -       ^lua-luajit
 -       ^tar zip=gzip

Concretized
--------------------------------
 -   neovim@0.7.0%gcc@11.3.0~ipo~no_luajit build_type=RelWithDebInfo arch=darwin-catalina-skylake
[+]      ^cmake@3.23.1%gcc@11.3.0~doc+ncurses+ownlibs~qt build_type=Release arch=darwin-catalina-skylake
[+]      ^gettext@0.21%gcc@11.3.0+bzip2+curses+git~libunistring+libxml2+tar+xz arch=darwin-catalina-skylake
[+]          ^bzip2@1.0.8%gcc@11.3.0~debug~pic+shared arch=darwin-catalina-skylake
[+]          ^libiconv@1.16%gcc@11.3.0 libs=shared,static arch=darwin-catalina-skylake
[+]          ^libxml2@2.9.13%gcc@11.3.0~python arch=darwin-catalina-skylake
[+]              ^pkgconf@1.8.0%gcc@11.3.0 arch=darwin-catalina-skylake
[+]              ^xz@5.2.5%gcc@11.3.0~pic libs=shared,static arch=darwin-catalina-skylake
[+]              ^zlib@1.2.12%gcc@11.3.0+optimize+pic+shared patches=0d38234 arch=darwin-catalina-skylake
[+]          ^ncurses@6.2%gcc@11.3.0~symlinks+termlib abi=none arch=darwin-catalina-skylake
[+]              ^pkgconf@1.8.0%gcc@11.3.0 arch=darwin-catalina-skylake
[+]          ^tar@1.34%gcc@11.3.0 zip=gzip arch=darwin-catalina-skylake
[+]              ^gzip@1.12%gcc@11.3.0 arch=darwin-catalina-skylake
[+]              ^zstd@1.5.2%gcc@11.3.0+programs compression=none libs=shared,static arch=darwin-catalina-skylake
[+]      ^gperf@3.1%gcc@11.3.0 arch=darwin-catalina-skylake
[+]      ^libluv@1.43.0-0%gcc@11.3.0~ipo build_type=RelWithDebInfo arch=darwin-catalina-skylake
[+]          ^libuv@1.44.1%gcc@11.3.0 arch=darwin-catalina-skylake
[+]          ^lua-luajit@2.0.5%gcc@11.3.0+lualinks fetcher=curl arch=darwin-catalina-skylake
[+]              ^curl@7.83.0%gcc@11.3.0~gssapi~ldap~libidn2~librtmp~libssh~libssh2~nghttp2 libs=shared,static tls=openssl arch=darwin-catalina-skylake
[+]                  ^openssl@1.1.1o%gcc@11.3.0~docs~shared certs=system arch=darwin-catalina-skylake
[+]                      ^perl@5.18.4%gcc@11.3.0+cpanm+shared+threads patches=0eac10e,3bbd7d6 arch=darwin-catalina-skylake
[+]              ^unzip@6.0%gcc@11.3.0 arch=darwin-catalina-skylake
[+]      ^libtermkey@0.22%gcc@11.3.0 arch=darwin-catalina-skylake
[+]          ^libtool@2.4.7%gcc@11.3.0 arch=darwin-catalina-skylake
[+]              ^m4@1.4.6%gcc@11.3.0+sigsegv patches=c0a408f arch=darwin-catalina-skylake
[+]          ^unibilium@2.0.0%gcc@11.3.0 arch=darwin-catalina-skylake
[+]      ^libvterm@0.1.4%gcc@11.3.0 arch=darwin-catalina-skylake
[+]      ^lua-lpeg@1.0.2-1%gcc@11.3.0 arch=darwin-catalina-skylake
[+]      ^lua-mpack@1.0.9%gcc@11.3.0 arch=darwin-catalina-skylake
[+]          ^msgpack-c@3.1.1%gcc@11.3.0~ipo build_type=RelWithDebInfo arch=darwin-catalina-skylake
[+]      ^tree-sitter@0.20.6%gcc@11.3.0 arch=darwin-catalina-skylake
```


### Error message

<details><summary>Error message</summary>
<pre>
cd /private/var/folders/vz/s2jc6vq50l9_sjh85hnlgvydgz4_5h/T/manc568/spack-stage/spack-stage-neovim-0.7.0-bkoxxmh5nhoj5lgqjlfbyrprp5wwcsy3/spack-build-bkoxxmh/runtime/pack/dist/opt/vimball && /private/var/folders/vz/s2jc6vq50l9_sjh85hnlgvydgz4_5h/T/manc568/spack-stage/spack-stage-neovim-0.7.0-bkoxxmh5nhoj5lgqjlfbyrprp5wwcsy3/spack-build-bkoxxmh/bin/nvim -u NONE -i NONE -e --headless -c helptags\ doc -c quit
E970: Failed to initialize lua interpreter                                      
E970: Failed to initialize lua interpreter                                      
make[3]: *** [runtime/pack/dist/opt/vimball/doc/tags] Error 1                   
make[3]: *** Waiting for unfinished jobs....                                    
make[3]: *** [runtime/pack/dist/opt/matchit/doc/tags] Error 1                   
cd /private/var/folders/vz/s2jc6vq50l9_sjh85hnlgvydgz4_5h/T/manc568/spack-stage/spack-stage-neovim-0.7.0-bkoxxmh5nhoj5lgqjlfbyrprp5wwcsy3/spack-build-bkoxxmh/runtime && /private/var/folders/vz/s2jc6vq50l9_sjh85hnlgvydgz4_5h/T/manc568/spack-stage/spack-stage-neovim-0.7.0-bkoxxmh5nhoj5lgqjlfbyrprp5wwcsy3/spack-build-bkoxxmh/bin/nvim -u NONE -i NONE -e --headless -c helptags\ ++t\ doc -c quit
E970: Failed to initialize lua interpreter                                      
make[3]: *** [runtime/doc/tags] Error 1                                         
make[2]: *** [runtime/CMakeFiles/runtime.dir/all] Error 2                       
make[1]: *** [all] Error 2                                                      

</pre>

</details>


### Information on your system

* **Spack:** 0.19.0.dev0 (174258c09a3147b48c332ea8c552c94cec2af9ca)
* **Python:** 3.12.0a0
* **Platform:** darwin-catalina-skylake
* **Concretizer:** clingo

### Additional information

CC @albestro @trws

I can't find `E970: Failed to initialize lua interpreter` mentioned much elsewhere, but it seems to be an issue with building `lua-luajit`.

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:
The exact same error occurs with `lua-luajit-openresty` as well.
I thought I had this solved, but this is specifically a Darwin issue AFAIK.  For now, it seems to work reliably with the lua interpreter, but that's not a very satisfying solution.  I'll try to look into it, but am not 100% sure what the root cause is.
Right, can't use most plugins with just the interpreter. Thanks Tom, happy to test stuff if you have ideas.
If that's true I would consider it a bug (though I'm not sure I can fix all instances).  I try to include all the lua packages necessary to mimic luajit functionality in regular lua to make things like telescope work.  Have you seen anything specific missing?

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/lua-luajit-openresty/package.py b/var/spack/repos/builtin/packages/lua-luajit-openresty/package.py
--- a/var/spack/repos/builtin/packages/lua-luajit-openresty/package.py
+++ b/var/spack/repos/builtin/packages/lua-luajit-openresty/package.py
@@ -43,6 +43,12 @@ def edit(self, spec, prefix):
         src_makefile.filter(
             '^DYNAMIC_CC = .*',
             'DYNAMIC_CC = $(CC) {0}'.format(self.compiler.cc_pic_flag))
+        # Catalina and higher produce a non-functional luajit unless this is set
+        if spec.satisfies("platform=darwin"):
+            src_makefile.filter(
+                '^.XCFLAGS.= -DLUAJIT_ENABLE_GC64',
+                'XCFLAGS+= -DLUAJIT_ENABLE_GC64',
+            )
         # Linking with the C++ compiler is a dirty hack to deal with the fact
         # that unwinding symbols are not included by libc, this is necessary
         # on some platforms for the final link stage to work
diff --git a/var/spack/repos/builtin/packages/lua-luajit/package.py b/var/spack/repos/builtin/packages/lua-luajit/package.py
--- a/var/spack/repos/builtin/packages/lua-luajit/package.py
+++ b/var/spack/repos/builtin/packages/lua-luajit/package.py
@@ -26,6 +26,7 @@ class LuaLuajit(LuaImplPackage):
     conflicts("lua", when="+lualinks")
     provides("luajit")
     lua_version_override = "5.1"
+    conflicts('platform=darwin', msg='luajit not supported on MacOS, see lua-luajit-openresty')
 
     @run_after("install")
     def install_links(self):
@@ -47,6 +48,7 @@ def edit(self, spec, prefix):
         src_makefile.filter(
             '^DYNAMIC_CC = .*',
             'DYNAMIC_CC = $(CC) {0}'.format(self.compiler.cc_pic_flag))
+
         # Linking with the C++ compiler is a dirty hack to deal with the fact
         # that unwinding symbols are not included by libc, this is necessary
         # on some platforms for the final link stage to work


Test patch: