Fix neovim on Darwin (#46905)

* lua: update luarocks resource to 3.11.1

We have kept an older 3.8 for some time, but that now uses an incorrect
value for the deployment target for macos, causing builds for bundles to
succeed but in such a way that they can't be linked to applications by
`ld` but only loaded by dlopen.  This fixes that, and also generally
updates the tool.

* lua-luajit-openresty: add new version fix LUA_PATH

Adds a newer version of openresty's luajor, and adds the slightly odd
extra share path they use that contains the `jit.*` modules.  Without
that, things that use bytecode-saving and other jit routines (like
neovim) fail.

* lua-lpeg: fix lpeg build to work for neovim on OSX

Normally luarocks builds all lua libraries as bundles on macos, this
makes sense, but means they can't then be linked by LD into executables
the way neovim expects to do.  I'm not sure how this ever worked, if it
did.  This patch adds the appropriate variables to have luarocks build
the library as a shared librar, and subsequently fix the id with
install_name_tool (the built-in functionality for this does not
trigger).

This also adds a symlink from `liblpeg.dylib` to `lpeg.so` because
neovim will not build on macos without it.  See corresponding upstream
pull request at https://github.com/neovim/neovim/pull/30749
This commit is contained in:
Tom Scogland 2024-10-15 19:04:33 -07:00 committed by GitHub
parent 57586df91a
commit d2f1e29927
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 5 deletions

View File

@ -4,6 +4,9 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
import spack.build_systems.lua
from spack.package import * from spack.package import *
@ -32,3 +35,36 @@ class LuaLpeg(LuaPackage):
) )
depends_on("lua-lang@:5.1.9", when="@:0.12.1 ^[virtuals=lua-lang] lua") depends_on("lua-lang@:5.1.9", when="@:0.12.1 ^[virtuals=lua-lang] lua")
class LuaBuilder(spack.build_systems.lua.LuaBuilder):
# without this, the resulting library cannot be linked by a normal link phase, the
# way neovim expects to link it, works fine with lua loads though,
# * replaces `-bundle` from the default flags with `-shared`
@when("platform=darwin")
def generate_luarocks_config(self, pkg, spec, prefix):
path = super().generate_luarocks_config(pkg, spec, prefix)
with open(path, "a") as cfg:
cfg.write(
"""
variables = {
LIBFLAG = "-shared -fPIC -undefined dynamic_lookup -all_load"
}
"""
)
return path
# Builds searching for lpeg with darwin conventions can't find it without a dylib
# symlink, neovim is an example
@run_after("install", when="platform=darwin")
def create_dylib_link_and_fix_id(self):
lpeg_so = find(self.prefix, "lpeg.so")
assert len(lpeg_so) >= 1
dylib_path = os.path.join(self.prefix.lib, "liblpeg.dylib")
symlink(lpeg_so[0], dylib_path)
# can't use spack.filesystem.fix_darwin_install_name for this, doesn't work
install_name_tool = which("install_name_tool", required=True)
install_name_tool("-id", dylib_path, dylib_path)

View File

@ -17,15 +17,15 @@ class LuaLuajitOpenresty(LuaImplPackage):
license("MIT") license("MIT")
version(
"2.1-20240626", sha256="1e53822a1105df216b9657ccb0293a152ac5afd875abc848453bfa353ca8181b"
)
version( version(
"2.1-20230410", sha256="77bbcbb24c3c78f51560017288f3118d995fe71240aa379f5818ff6b166712ff" "2.1-20230410", sha256="77bbcbb24c3c78f51560017288f3118d995fe71240aa379f5818ff6b166712ff"
) )
version( version(
"2.1-20220111", sha256="1ad2e34b111c802f9d0cdf019e986909123237a28c746b21295b63c9e785d9c3" "2.1-20220111", sha256="1ad2e34b111c802f9d0cdf019e986909123237a28c746b21295b63c9e785d9c3"
) )
version(
"2.1-20230410", sha256="77bbcbb24c3c78f51560017288f3118d995fe71240aa379f5818ff6b166712ff"
)
depends_on("c", type="build") # generated depends_on("c", type="build") # generated
depends_on("cxx", type="build") # generated depends_on("cxx", type="build") # generated
@ -64,3 +64,11 @@ def edit(self, spec, prefix):
# that unwinding symbols are not included by libc, this is necessary # that unwinding symbols are not included by libc, this is necessary
# on some platforms for the final link stage to work # on some platforms for the final link stage to work
src_makefile.filter("^TARGET_LD = .*", f"TARGET_LD = {spack_cxx}") src_makefile.filter("^TARGET_LD = .*", f"TARGET_LD = {spack_cxx}")
def setup_run_environment(self, env):
env.prepend_path(
"LUA_PATH",
os.path.join(self.spec.prefix, "share", f"luajit-{self.version[0:2]}", "?.lua"),
separator=";",
)
super().setup_run_environment(env)

View File

@ -64,8 +64,8 @@ def lua_share_dir(self):
resource( resource(
name="luarocks", name="luarocks",
url="https://luarocks.github.io/luarocks/releases/" "luarocks-3.8.0.tar.gz", url="https://luarocks.github.io/luarocks/releases/luarocks-3.11.1.tar.gz",
sha256="56ab9b90f5acbc42eb7a94cf482e6c058a63e8a1effdf572b8b2a6323a06d923", sha256="c3fb3d960dffb2b2fe9de7e3cb004dc4d0b34bb3d342578af84f84325c669102",
destination="luarocks", destination="luarocks",
placement="luarocks", placement="luarocks",
) )