Repository: spack/spack

Issue:
Installation issue: neovim on darwin
### Steps to reproduce the issue

```console
$ spack spec -l neovim
Input spec
--------------------------------
neovim

Concretized
--------------------------------
yc6vaah  neovim@0.8.0%apple-clang@14.0.0~ipo~no_luajit build_system=cmake build_type=RelWithDebInfo arch=darwin-monterey-m1
g5oetkt      ^cmake@3.24.2%apple-clang@14.0.0~doc+ncurses+ownlibs~qt build_type=Release arch=darwin-monterey-m1
duhzt5q          ^ncurses@6.3%apple-clang@14.0.0~symlinks+termlib abi=none arch=darwin-monterey-m1
waq44kg              ^gnuconfig@2021-08-14%apple-clang@14.0.0 arch=darwin-monterey-m1
wrbynmy              ^pkgconf@1.8.0%apple-clang@14.0.0 arch=darwin-monterey-m1
gv4bhhv          ^openssl@1.1.1q%apple-clang@14.0.0~docs~shared certs=mozilla patches=3fdcf2d arch=darwin-monterey-m1
qgk3cls              ^ca-certificates-mozilla@2022-07-19%apple-clang@14.0.0 arch=darwin-monterey-m1
q3asorm              ^perl@5.34.1%apple-clang@14.0.0+cpanm+shared+threads arch=darwin-monterey-m1
24geus7                  ^berkeley-db@18.1.40%apple-clang@14.0.0+cxx~docs+stl patches=26090f4,b231fcc arch=darwin-monterey-m1
b2pyoaz                  ^bzip2@1.0.8%apple-clang@14.0.0~debug~pic+shared arch=darwin-monterey-m1
cykevnq                      ^diffutils@3.8%apple-clang@14.0.0 arch=darwin-monterey-m1
jsxdcns                          ^libiconv@1.16%apple-clang@14.0.0 libs=shared,static arch=darwin-monterey-m1
lgdwy3d                  ^gdbm@1.19%apple-clang@14.0.0 arch=darwin-monterey-m1
lck4i33                      ^readline@8.1.2%apple-clang@14.0.0 arch=darwin-monterey-m1
ay6ey4s              ^zlib@1.2.12%apple-clang@14.0.0+optimize+pic+shared patches=0d38234 arch=darwin-monterey-m1
hwu4o6k      ^gettext@0.21.1%apple-clang@14.0.0+bzip2+curses+git~libunistring+libxml2+tar+xz build_system=autotools arch=darwin-monterey-m1
ghyuso3          ^bzip2@1.0.8%apple-clang@14.0.0~debug~pic+shared build_system=generic arch=darwin-monterey-m1
feyhbhm              ^diffutils@3.8%apple-clang@14.0.0 build_system=autotools arch=darwin-monterey-m1
pdomtcr          ^gnuconfig@2022-09-17%apple-clang@14.0.0 build_system=generic arch=darwin-monterey-m1
qy6f5iu          ^libxml2@2.10.3%apple-clang@14.0.0~python build_system=autotools arch=darwin-monterey-m1
da7twnj          ^tar@1.34%apple-clang@14.0.0 build_system=autotools zip=pigz arch=darwin-monterey-m1
elhjppf              ^pigz@2.7%apple-clang@14.0.0 build_system=makefile arch=darwin-monterey-m1
tnjjnod              ^zstd@1.5.2%apple-clang@14.0.0+programs build_system=makefile compression=none libs=shared,static arch=darwin-monterey-m1
op3ztkh          ^xz@5.2.7%apple-clang@14.0.0~pic build_system=autotools libs=shared,static arch=darwin-monterey-m1
vawtenk      ^gperf@3.1%apple-clang@14.0.0 build_system=autotools arch=darwin-monterey-m1
zktuyj4      ^libiconv@1.16%apple-clang@14.0.0 build_system=autotools libs=shared,static arch=darwin-monterey-m1
d65d7r7      ^libluv@1.43.0-0%apple-clang@14.0.0~ipo build_system=cmake build_type=RelWithDebInfo arch=darwin-monterey-m1
2lc2mi2      ^libtermkey@0.22%apple-clang@14.0.0 build_system=generic arch=darwin-monterey-m1
5mmactq          ^libtool@2.4.7%apple-clang@14.0.0 build_system=autotools arch=darwin-monterey-m1
v3ldrmb              ^m4@1.4.19%apple-clang@14.0.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=darwin-monterey-m1
q2ditz3                  ^libsigsegv@2.13%apple-clang@14.0.0 build_system=autotools arch=darwin-monterey-m1
kr2mmdc      ^libuv@1.44.1%apple-clang@14.0.0 build_system=autotools arch=darwin-monterey-m1
njvcyu3      ^libvterm@0.3%apple-clang@14.0.0 build_system=generic arch=darwin-monterey-m1
p7sjlz4      ^lua-lpeg@1.0.2-1%apple-clang@14.0.0 build_system=lua arch=darwin-monterey-m1
gc5lyj4      ^lua-luajit-openresty@2.1-20220111%apple-clang@14.0.0+lualinks build_system=makefile fetcher=curl arch=darwin-monterey-m1
n4fllkr          ^curl@7.78.0%apple-clang@14.0.0~gssapi~ldap~libidn2~librtmp~libssh+libssh2+nghttp2 build_system=autotools libs=shared,static tls=mbedtls,secure_transport arch=darwin-monterey-m1
2dovil7              ^libssh2@1.10.0%apple-clang@14.0.0~ipo+shared build_system=cmake build_type=RelWithDebInfo crypto=mbedtls arch=darwin-monterey-m1
f7ztnus              ^mbedtls@2.28.0%apple-clang@14.0.0+pic build_system=makefile build_type=Release libs=shared,static arch=darwin-monterey-m1
hxnzbpi              ^nghttp2@1.47.0%apple-clang@14.0.0 build_system=autotools arch=darwin-monterey-m1
rot7r26          ^unzip@6.0%apple-clang@14.0.0 build_system=makefile arch=darwin-monterey-m1
wh3g43e      ^lua-mpack@1.0.9%apple-clang@14.0.0 build_system=lua arch=darwin-monterey-m1
s5jcb2x      ^msgpack-c@3.1.1%apple-clang@14.0.0~ipo build_system=cmake build_type=RelWithDebInfo arch=darwin-monterey-m1
jmotgze      ^pkgconf@1.8.0%apple-clang@14.0.0 build_system=autotools arch=darwin-monterey-m1
bhlrfzz      ^tree-sitter@0.20.6%apple-clang@14.0.0 build_system=makefile arch=darwin-monterey-m1
xhwqk3l      ^unibilium@2.0.0%apple-clang@14.0.0 build_system=generic arch=darwin-monterey-m1
```


### Error message

<details><summary>Error message</summary><pre>
==> Installing neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx
==> neovim exists in binary cache but with different hash
==> No binary for neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx found: installing from source
==> Using cached archive: /Users/dpzmick/spack/var/spack/cache/_source-cache/archive/50/505e3dfb71e2f73495c737c034a416911c260c0ba9fd2092c6be296655be4d18.tar.gz
==> No patches needed for neovim
==> neovim: Executing phase: 'cmake'
==> neovim: Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j8'

5 errors found in build log:
     1207    dyld[92998]: Library not loaded: '/usr/local/lib/libvterm.0.dylib'
     1208      Referenced from: '/private/var/folders/dh/58w5tcn10m3g5fndhvpbn3mm0000gn/T/dpzmick/spack-stage/spack-stage-neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx/spack-build-yc6vaah/bin/nvim'
     1209      Reason: tried: '/usr/local/lib/libvterm.0.dylib' (no such file), '/usr/lib/libvterm.0.dylib' (no such file)
     1210    /bin/sh: line 1: 92998 Abort trap: 6           /private/var/folders/dh/58w5tcn10m3g5fndhvpbn3mm0000gn/T/dpzmick/spack-stage/spack-stage-neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx/spack-build-yc6vaa
             h/bin/nvim -u NONE -i NONE -e --headless -c helptags\ ++t\ doc -c quit
     1211    /bin/sh: line 1: 92995 Abort trap: 6           /private/var/folders/dh/58w5tcn10m3g5fndhvpbn3mm0000gn/T/dpzmick/spack-stage/spack-stage-neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx/spack-build-yc6vaa
             h/bin/nvim -u NONE -i NONE -e --headless -c helptags\ doc -c quit
     1212    /bin/sh: line 1: 92996 Abort trap: 6           /private/var/folders/dh/58w5tcn10m3g5fndhvpbn3mm0000gn/T/dpzmick/spack-stage/spack-stage-neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx/spack-build-yc6vaa
             h/bin/nvim -u NONE -i NONE -e --headless -c helptags\ doc -c quit
  >> 1213    make[2]: *** [runtime/doc/tags] Error 134
     1214    make[2]: *** Waiting for unfinished jobs....
  >> 1215    make[2]: *** [runtime/pack/dist/opt/matchit/doc/tags] Error 134
  >> 1216    make[2]: *** [runtime/pack/dist/opt/vimball/doc/tags] Error 134
  >> 1217    make[1]: *** [runtime/CMakeFiles/runtime.dir/all] Error 2
  >> 1218    make: *** [all] Error 2

See build log for details:
  /var/folders/dh/58w5tcn10m3g5fndhvpbn3mm0000gn/T/dpzmick/spack-stage/spack-stage-neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx/spack-build-out.txt
</pre></details>


### Information on your system

```
$ spack debug report
* **Spack:** 0.20.0.dev0 (e3a575fb08686bd7d137332fdad046d491c09487)
* **Python:** 3.9.6
* **Platform:** darwin-monterey-m1
* **Concretizer:** clingo
```


```
$ spack compiler info apple-clang
apple-clang@14.0.0:
        paths:
                cc = /usr/bin/clang
                cxx = /usr/bin/clang++
                f77 = /opt/homebrew/bin/gfortran-12
                fc = /opt/homebrew/bin/gfortran-12
        modules  = []
        operating system  = monterey
```

### Additional information

logs are at: https://gist.github.com/dpzmick/591a64664d94d113e9896558f89d093d

Building with
```
$ spack cd neovim
$ spack build-env neovim cmake ../
$ spack build-env neovim make -j8
```

I can repro the error by trying to run the generate `nvim` binary:

```
$ bin/nvim
dyld[96987]: Library not loaded: '/usr/local/lib/libvterm.0.dylib'
  Referenced from: '/private/var/folders/dh/58w5tcn10m3g5fndhvpbn3mm0000gn/T/dpzmick/spack-stage/spack-stage-neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx/spack-src/build/bin/nvim'
  Reason: tried: '/usr/local/lib/libvterm.0.dylib' (no such file), '/usr/lib/libvterm.0.dylib' (no such file)
zsh: abort      bin/nvim
```

and `otool -L` shows that we ended up linking against a non-existent libvterm

```
$ otool -L bin/nvim
bin/nvim:
        /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 1228.0.0)
        /opt/homebrew/opt/gettext/lib/libintl.8.dylib (compatibility version 12.0.0, current version 12.0.0)
        /Users/dpzmick/spack/opt/spack/darwin-monterey-m1/apple-clang-14.0.0/libiconv-1.16-zktuyj4vmjzr55muluatv7jdoua7jr3y/lib/libiconv.2.dylib (compatibility version 9.0.0, current version 9.1.0)
        /Users/dpzmick/spack/opt/spack/darwin-monterey-m1/apple-clang-14.0.0/libuv-1.44.1-kr2mmdcriv4jw5l2ef5mfycgtwq4ts6k/lib/libuv.1.dylib (compatibility version 2.0.0, current version 2.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
        @rpath/libmsgpackc.2.dylib (compatibility version 2.0.0, current version 2.0.0)
        /usr/local/lib/libvterm.0.dylib (compatibility version 1.0.0, current version 1.0.0)
        /usr/local/lib/libtermkey.1.dylib (compatibility version 16.0.0, current version 16.2.0)
        /Users/dpzmick/spack/opt/spack/darwin-monterey-m1/apple-clang-14.0.0/unibilium-2.0.0-xhwqk3lrfgin6tzh3y664wpih5u5kj57/lib/libunibilium.4.dylib (compatibility version 5.0.0, current version 5.0.0)
        /Users/dpzmick/spack/opt/spack/darwin-monterey-m1/apple-clang-14.0.0/tree-sitter-0.20.6-bhlrfzzptmaojqbyjtywcb5y4jqz6aod/lib/libtree-sitter.0.dylib (compatibility version 0.0.0, current version 0.0.0)
        /usr/lib/libutil.dylib (compatibility version 1.0.0, current version 1.0.0)
        /Users/dpzmick/spack/opt/spack/darwin-monterey-m1/apple-clang-14.0.0/lua-luajit-openresty-2.1-20220111-gc5lyj4etlgejoeyegjf522oqjyu6fsp/lib/libluajit-5.1.2.dylib (compatibility version 2.1.0, current version 2.1.0)
```

finally, grabbing the cmake link command, it can be see that the build did attempt to link properly: https://gist.github.com/dpzmick/f9821dfe1de1cb3e62851ce5dfbc67ab but for some reason the resulting binary is not picking it up.

I've been messing with this for quite a while but I don't see anything wrong in the build other than the otool output.

Any ideas?

cc maintainers @albestro @trws

### 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:
Hi @dpzmick, thanks for reporting it.

I tried on my MacBook Pro (not M1) and it installed correctly.

```bash
$ spack install neovim
...
[+] /Users/ialberto/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/neovim-0.8.0-wc4sjwqviis6dozbuxraypkbrffyxqwv
```

About the build error you reported in "Error Message" section of this issue, I was not able to find it in the build log gist you posted (I don't see errors in that build log). What looks strange is that in the end, you got a binary built...so I'm a bit confused.

Can you please give me some more insight about this build error?


However, talking about the one you actually built, the one that `otool` shows it as linked to a missing `libvterm`, what I'd like to investigate is the "typical" HomeBrew path `/usr/local`. It turns out that I have libvterm installed with HomeBrew...so I'm going to try to explore it a bit more in deep, and check if it might be that neovim/vterm build system do something weird with that path (maybe hard-coded?!). I'll let you know if I figure out anything new.
Hi @albestro !

There's a few files in my gist, the error shows up in this one: https://gist.githubusercontent.com/dpzmick/591a64664d94d113e9896558f89d093d/raw/2699657524734876592b5cbcda5a7103f964335e/spack-build-out.txt 

The build successfully produces the nvim binary, but when it tries to launch the binary to generate some additional build artifacts, the launch fails due to the vterm thing:

Excerpt from the log:
```
cd /private/var/folders/dh/58w5tcn10m3g5fndhvpbn3mm0000gn/T/dpzmick/spack-stage/spack-stage-neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx/spack-build-yc6vaah/runtime && /private/var/folders/dh/58w5tcn10m3g5fndhvpbn3mm0000gn/T/dpzmick/spack-stage/spack-stage-neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx/spack-build-yc6vaah/bin/nvim -u NONE -i NONE -e --headless -c helptags\ ++t\ doc -c quit
dyld[92996]: Library not loaded: '/usr/local/lib/libvterm.0.dylib'
  Referenced from: '/private/var/folders/ddyld[92995]: h/58w5tcn10m3g5fndhvpbn3mm0000gnLibrary not loaded: '/usr/local//T/dpzmick/spack-stage/spack-stalib/libvterm.0.dylib'
  Referencge-neovim-0.8.0-yc6vaahe7prquga7ed from: '/private/var/folders/dhy4hainort4hrzzx/spack-build-yc6h/58w5tcn10m3g5fndhvpbn3mm0000gnvaah/bin/nvim'
  Reason: tried: /T/dpzmick/spack-stage/spack-sta'/usr/local/lib/libvterm.0.dylibge-neovim-0.8.0-yc6vaahe7prquga7' (no such file), '/usr/lib/libvhy4hainort4hrzzx/spack-build-yc6term.0.dylib' (no such file)
vaah/bin/nvim'
  Reason: tried: '/usr/local/lib/libvterm.0.dylib' (no such file), '/usr/lib/libvterm.0.dylib' (no such file)
dyld[92998]: Library not loaded: '/usr/local/lib/libvterm.0.dylib'
  Referenced from: '/private/var/folders/dh/58w5tcn10m3g5fndhvpbn3mm0000gn/T/dpzmick/spack-stage/spack-stage-neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx/spack-build-yc6vaah/bin/nvim'
  Reason: tried: '/usr/local/lib/libvterm.0.dylib' (no such file), '/usr/lib/libvterm.0.dylib' (no such file)
/bin/sh: line 1: 92998 Abort trap: 6           /private/var/folders/dh/58w5tcn10m3g5fndhvpbn3mm0000gn/T/dpzmick/spack-stage/spack-stage-neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx/spack-build-yc6vaah/bin/nvim -u NONE -i NONE -e --headless -c helptags\ ++t\ doc -c quit
/bin/sh: line 1: 92995 Abort trap: 6           /private/var/folders/dh/58w5tcn10m3g5fndhvpbn3mm0000gn/T/dpzmick/spack-stage/spack-stage-neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx/spack-build-yc6vaah/bin/nvim -u NONE -i NONE -e --headless -c helptags\ doc -c quit
/bin/sh: line 1: 92996 Abort trap: 6           /private/var/folders/dh/58w5tcn10m3g5fndhvpbn3mm0000gn/T/dpzmick/spack-stage/spack-stage-neovim-0.8.0-yc6vaahe7prquga7hy4hainort4hrzzx/spack-build-yc6vaah/bin/nvim -u NONE -i NONE -e --headless -c helptags\ doc -c quit
make[2]: *** [runtime/doc/tags] Error 134
```

A homebrewed libvterm would probably hide this, good catch! I did scan the neovim build system for any hardcoding of the dynamic lib path for libvterm, but I didn't see any such hardcoding. I'll give it another deeper scan later on; it feels likely that they'd have made a homebrew-specific assumption somewhere in here
In the meanwhile I did some test and I was able to reproduce the problem also in my configuration (it was enough removing the HomeBrew installed ones).

I did too a quick check about hard-coded things, and I tried to compare how CMake configures different libraries, without any luck. Because it looks strange that part of them are configured correctly and others are not. The problem exists for both `libvterm` and `libtermkey`.

Actually, in my setup I see with `otool` that RPATHs are set correctly for both `libvterm` and `libtermkey`, i.e. RPATH pointing inside the ones inside spack install tree, what is wrong is that load commands for them aren't set with `@rpath` (like `msgpackc`) or with the correct absolute path "from spack" (like `tree sitter`), and instead they have the full absolute (wrong) path (i.e. `/usr/local/lib/*`).

```bash
$ otool -l bin/nvim
...
Load command 18
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name @rpath/libmsgpackc.2.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 2.0.0
compatibility version 2.0.0
Load command 19
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/local/lib/libvterm.0.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 1.0.0
compatibility version 1.0.0
Load command 20
          cmd LC_LOAD_DYLIB
      cmdsize 64
         name /usr/local/lib/libtermkey.1.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 16.2.0
compatibility version 16.0.0
Load command 21
          cmd LC_LOAD_DYLIB
      cmdsize 176
         name /Users/ialberto/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/unibilium-2.0.0-4sj7o7pzvaez5dqgr42krpdkl3qe3af5/lib/libunibilium.4.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 5.0.0
compatibility version 5.0.0
Load command 22
          cmd LC_LOAD_DYLIB
      cmdsize 176
         name /Users/ialberto/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/tree-sitter-0.20.6-edoerxfwkeyuumesy5vjexbzqc56igvr/lib/libtree-sitter.0.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 0.0.0
compatibility version 0.0.0
...
Load command 32
          cmd LC_RPATH
      cmdsize 136
         path /Users/ialberto/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/libvterm-0.3-ino3hz4qtcsycr5cqm4w3h7eiw4ucbbt/lib (offset 12)
Load command 33
          cmd LC_RPATH
      cmdsize 144
         path /Users/ialberto/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/libtermkey-0.22-2xt7k4t24qpumshsh3gibxxvp2e2b33w/lib (offset 12)
...
```

Indeed, I was able to manually fix the executable by just changing that (and not altering rpaths)

```bash
install_name_tool -change /usr/local/lib/libvterm.0.dylib @rpath/libvterm.0.dylib bin/nvim
install_name_tool -change /usr/local/lib/libtermkey.1.dylib @rpath/libtermkey.1.dylib bin/nvim
```

I speculate that it is something wrong in CMake, but unfortunately, the CMake side of neovim looks very ugly... at least to my eyes 😅

Tomorrow I will dig more into the cmake side, looking for some misconfiguration of targets/rpaths.
It looks like cmake _almost_ gets this right, so the library resolution in cmake seems to be working at least:

From my `CMakeCache.txt`:
```
//Path to a file.
LIBVTERM_INCLUDE_DIR:PATH=/Users/dpzmick/spack/opt/spack/darwin-monterey-m1/apple-clang-14.0.0/libvterm-0.3-njvcyu3pas3ucvotz4mijyykcnek2k7t/include

//Path to a library.
LIBVTERM_LIBRARY:FILEPATH=/Users/dpzmick/spack/opt/spack/darwin-monterey-m1/apple-clang-14.0.0/libvterm-0.3-njvcyu3pas3ucvotz4mijyykcnek2k7t/lib/libvterm.dylib
```

likewise, libtermkey:
```
//Path to a file.
LIBTERMKEY_INCLUDE_DIR:PATH=/Users/dpzmick/spack/opt/spack/darwin-monterey-m1/apple-clang-14.0.0/libtermkey-0.22-2lc2mi2yvon3klwnlm7vmssfdv3bks42/include

//Path to a library.
LIBTERMKEY_LIBRARY:FILEPATH=/Users/dpzmick/spack/opt/spack/darwin-monterey-m1/apple-clang-14.0.0/libtermkey-0.22-2lc2mi2yvon3klwnlm7vmssfdv3bks42/lib/libtermkey.dylib

```
Yes, I agree with you. I didn't meant it was a detection problem, I was thinking more about a behind the scene RPATH management.

I started right now and I have already a quick update that looks promising:

```bash
➜  ~ otool -D `spack location -i libvterm`/lib/libvterm.dylib:
/usr/local/lib/libvterm.0.dylib
➜  ~ otool -D `spack location -i libtermkey`/lib/libtermkey.dylib
/Users/ialberto/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/libtermkey-0.22-2xt7k4t24qpumshsh3gibxxvp2e2b33w/lib/libtermkey.dylib:
/usr/local/lib/libtermkey.1.dylib
➜  ~ otool -D `spack location -i tree-sitter`/lib/libtree-sitter.dylib
/Users/ialberto/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/tree-sitter-0.20.6-edoerxfwkeyuumesy5vjexbzqc56igvr/lib/libtree-sitter.dylib:
/Users/ialberto/spack/opt/spack/darwin-bigsur-skylake/apple-clang-13.0.0/tree-sitter-0.20.6-edoerxfwkeyuumesy5vjexbzqc56igvr/lib/libtree-sitter.0.dylib
```

It seems that the problem is the install name of `libvterm` and `libtermkey` (see compared to `tree-sitter`). I have a couple of options to look for, let's see if I can fix them 😉 
the linker copies the install name when you link, so you will have to look into the libvterm/libtermkey packages' build systems

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/libtermkey/package.py b/var/spack/repos/builtin/packages/libtermkey/package.py
--- a/var/spack/repos/builtin/packages/libtermkey/package.py
+++ b/var/spack/repos/builtin/packages/libtermkey/package.py
@@ -6,7 +6,7 @@
 from spack.package import *
 
 
-class Libtermkey(Package):
+class Libtermkey(MakefilePackage):
     """Easy keyboard entry processing for terminal programs"""
 
     homepage = "http://www.leonerd.org.uk/code/libtermkey/"
@@ -20,9 +20,15 @@ class Libtermkey(Package):
     version("0.14", sha256="3d114d4509499b80a583ea39cd35f18268aacf4a7bbf56c142cd032632005c79")
 
     depends_on("libtool", type="build")
+
     depends_on("unibilium")
     depends_on("pkgconfig")
 
+    def setup_build_environment(self, env):
+        env.set("LIBTOOL", self.spec["libtool"].prefix.bin.join("libtool"))
+
+    def build(self, spec, prefix):
+        make("PREFIX=" + prefix)
+
     def install(self, spec, prefix):
-        make()
         make("install", "PREFIX=" + prefix)
diff --git a/var/spack/repos/builtin/packages/libvterm/package.py b/var/spack/repos/builtin/packages/libvterm/package.py
--- a/var/spack/repos/builtin/packages/libvterm/package.py
+++ b/var/spack/repos/builtin/packages/libvterm/package.py
@@ -7,7 +7,7 @@
 from spack.package import *
 
 
-class Libvterm(Package):
+class Libvterm(MakefilePackage):
     """An abstract library implementation of a terminal emulator"""
 
     homepage = "http://www.leonerd.org.uk/code/libvterm/"
@@ -25,6 +25,11 @@ class Libvterm(Package):
 
     depends_on("libtool", type="build")
 
+    def setup_build_environment(self, env):
+        env.set("LIBTOOL", self.spec["libtool"].prefix.bin.join("libtool"))
+
+    def build(self, spec, prefix):
+        make("PREFIX=" + prefix)
+
     def install(self, spec, prefix):
-        make()
         make("install", "PREFIX=" + prefix)


Test patch: