kmarius / jsregexp

JavaScript regular expressions for Lua
MIT License
30 stars 3 forks source link

Can't get this to build on Windows 11 Pro x64, can't install via Luarocks #26

Open JohnWilliston opened 1 month ago

JohnWilliston commented 1 month ago

I've been beating my head against this for a while. No matter what I do, I can't seem to get jsregexp to install using Luarocks or to build in any way. I've tried every article I can find, using msys2 and what not. Can anyone offer advice? Maybe a simple pre-compiled binary to download? I'd just like to get it working with Neovim if possible.

kmarius commented 1 month ago

There are some suggestions in this issue: https://github.com/L3MON4D3/LuaSnip/issues/986 I don't have a windows machine and can't test any of them, unfortunately.

JohnWilliston commented 1 month ago

Thanks. I have literally tried every example on that page and a couple others. Nothing works. The closest I get is that lit looks like the linker is failing with a bunch of errors like "undefined reference to lua_pushstring" and a bunch of other such mentioned exports. Any ideas how maybe I fix that? I've been able to get the gcc compiler to build the .c files into .o, but despite having installed seemingly every variant imaginable of Lua along the way, I can't find its libraries to include in the flags.

Update: after downloading the lua-5.1.5_Win64_mingw6_lib.zip files and unpacking that liblua5.1.a and including it, I'm down to a mere three unresolved externals:

C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: liblua5.1.a(ldo.o):ldo.c:(.text+0xe6): undefined reference to `_setjmp'
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: liblua5.1.a(lauxlib.o):lauxlib.c:(.text+0xf7): undefined reference to `__imp___iob_func'
C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: liblua5.1.a(lauxlib.o):lauxlib.c:(.text+0x1257): undefined reference to `__imp___iob_func'
collect2.exe: error: ld returned 1 exit status

Any ideas what the linker might need to fix those?

JohnWilliston commented 1 month ago

A quick follow-up. Even after fighting all the way to a successful compilation with a completely new Lua install, MSYS2 install, you name it, it's still not good enough for the Neovim LuaSnip plugin for some reason. I ultimately got everything working on my machine building jsregexp.so just fine, but it still doesn't work with the LuaSnip plugin I was hoping to use. Thanks anyway.

kmarius commented 1 month ago

What exactly doesn't work? Can you load jsregexp from the lua5.1/luajit interpreter outside of neovim?

There is something really wrong here as because an installation lua shouldn't be needed to build the library, only the headers which are included in luasnip. I can look into it on a windows 10 machine in a few days. How did you install neovim?

JohnWilliston commented 1 month ago

Let me provide some more context. But first, I appreciate your willingness to help and absolutely recognize that this is largely a Windows specific problem and related to the Luasnip plugin for Neovim, neither of which are your headache to have. I should note that I use Neovim on Linux and macOS without a single problem. This problem existed only on my Windows machines, all of which failed to build the library. And in answer to your question, I installed Neovim using the chocolatey "package manager" for Windows, which gave me Neovim v0.10.2 for reference.

I spent way too much time over the last few days and ended up posting an issue here only because I thought maybe if I could just build the library on its own in isolation, I could then use those build artifacts or otherwise get it working with Luasnip. Plenty of comments in the Luasnip issues mentioned that just building the jsregexp.so library and moving it to the right directory would fix things. My original post above about link errors is still an issue on any stock Windows machine on which I try to build the library. It sure seems to me like it requires a Lua installation to have the associated header and library files in place as well as all the appropriate environment variables (viz., LUA_CPATH and LUA_PATH) to make sure they get pulled in and a compiler/linker capable of doing the job. In my particular case, that "strawberry" flavor of the mingw tool chain was also part of the problem. But let me start at the beginning.

I've been a Vim user for decades, but so many of my colleagues today use Neovim and tell me how amazing it is that I've been trying it out for a couple months and working (obsessing?) on my configuration in earnest for the last few weeks. When I learned about the LSP features and saw how the Luasnip plugin could do transformations and such, I wanted those features to work. So my very first roadblock came when I installed the Luasnip plugin and it failed to build jsregexp on startup. I found it seemed to be mostly working, insofar as I could expand normal snippets, so I wasn't too concerned at the time, but I've been working through all the issues reported by a Neovim :checkhealth command ever since, and there were two in particular relevant to my post here:

  1. The Lazy nvim plugin manager complained that Luarocks was not available.
  2. The Luasnip plugin complained that jsregexp was not available.

My first attempt to solve the problem was to fix my Luarocks installation as I figured maybe that would kill two birds with one stone. But nothing I did got rid of those errors no matter which version of Lua I installed, how I installed it, etc. When I learned there is a luarocks.nvim plugin to provide Luarocks services instead, I tried using that. The plugin installed and updated fine, but it didn't fix either of my errors. I'll come back to that eventually.

So my next attempt to solve problem (2) first was to see if I could build the library in isolation. I won't bore you with the pages of details I gathered along the way (unless you ask), but the short version is that I had a lot of tools installed on my machine that were getting in the way of the build working, most notably Visual Studio 2022, gcc make, gcc, the strawberry flavor of mingw, etc. Once I uninstalled all that stuff, and installed the complete MSYS2 tool chain, etc., I could compile the C code in the jsregexp library but was then running into the same linker errors I originally posted above.

That led me to question the flavor of Lua I had installed, which was v5.3 at the time. I've used Lua on and off for a decade or more, first learning it as a tool to write profiles for my beloved old Logitech G13 game pad, but I'm not much of a Lua programmer. I didn't know that each minor version release apparently breaks all kinds of things, but when I learned that from online searching I figured I'd better install the latest and greatest just to be safe. I tried several different approaches and articles that failed until I came across this article on How to install Lua and LuaJIT on 64-bit Windows. That procedure actually worked and gave me a verifiable Lua v5.4.7 installation complete with the LuaJIT stuff, the requisite header and lib files, and once I configured my environment variables correctly to point to those folders, I could successfully build jsregexp on its own in isolation. Yay!

A number of threads in the issues for the Luasnip repo on GitHub suggested that if I could just build that bloody jsregexp.so library file that I could then drop it in an appropriate Neovim config folder and all my problems would be solved. Only I tried putting it practically everywhere and neither of those two aforementioned Neovim :checkhealth issues went away. I even posted a screenshot to that effect on one of the issues. It seemed like I had finally built the thing guaranteed to fix at least Luasnip, only it didn't help at all.

While still searching for information, I came across several articles talking about why Neovim is essentially locked in for Lua v5.1 and doesn't use any more recent version. That got me wondering if perhaps that was why my problems still remained. As much as I hated to do it, I undid all the changes I'd made to install Lua v5.4.7 and installed Lua v5.1 instead. I had to work a little harder to get the jsregexp library to build as the contents of the releases were a little different, but I eventually got a version of jsregexp built with the Lua v5.1 headers/libraries instead. It didn't do a bloody thing to solve my problems either. Sigh.

So at that point, I remembered that I had installed the Luarocks Neovim plugin back at the start of this whole adventure, thinking it might kill two birds with one stone. I knew I now had a valid, working Lua v5.1 installation, so I tried using it to install the jsregexp library using Luarocks, and it worked! I was so excited! I thought for sure I'd solved both my issues in Neovim!

But I hadn't. The good news is that the Luasnip plugin was now completely happy with jsregexp installed via Luarocks. That works just fine: I can manage various "rocks" either from the command line or using the Luarocks.nvim plugin. So I have finally solved problem (2) from above. Luasnip expands normal snippets for me and seems to handle transformations just fine (though honestly I still have a bit of a learning curve to master in figuring out how to specify and best use them).

The remaining weird thing is that the Lazy nvim plugin manager still complains luarocks is not working, even though it obviously is! The error it gives is that spawning the process failed, which doesn't make a damn bit of sense seeing as I can run the Luarocks manager from any command line, from the internal Neovim terminal, from the bloody Windows Run box, anywhere! I'm starting to think its detection is just plain busted. But that's a problem with the Lazy nvim plugin manager, which also isn't your headache to have, and not a problem I'm going to tackle anytime soon.

Whew! Sorry for the book-length post, but I thought your willingness to help merited a detailed response. Cheers!