L3MON4D3 / LuaSnip

Snippet Engine for Neovim written in Lua.
Apache License 2.0
3.18k stars 233 forks source link

Fail to install jsregexp on Windows11 #1190

Open ThreeStonesL opened 1 month ago

ThreeStonesL commented 1 month ago

image

L3MON4D3 commented 1 month ago

Could you check whether these help?

ThreeStonesL commented 1 month ago

Could you check whether these help?

yeah,I have tried almost every methods,including luarocks、MSYS2 and so on, however, every method has its own problem that I can not solove

L3MON4D3 commented 1 month ago

Could you go into the directory luasnip is in and run make install_jsregexp manually, and post the whole output? Unfortunately I don't have a windows setup currently, so I can't test this stuff myself :/

ThreeStonesL commented 1 month ago

Could you go into the directory luasnip is in and run make install_jsregexp manually, and post the whole output? Unfortunately I don't have a windows setup currently, so I can't test this stuff myself :/

image The meaning of Chinese in the output is that system cannot find the files

dekaravanhoc commented 3 weeks ago

Hey, as this is probably the issue someone finds when googling it. I also had the same problems and solved it with the help of https://github.com/L3MON4D3/LuaSnip/issues/986#issuecomment-2060360732

Also to to make it more convinient I build a powershell script I can run. What is needed:

Than I added in my nvim dir ( c:/users/MYUSERNAME/appdata/local/nvim/luasnip_jsregexp_build.ps1) this powerhell script:

$find = '$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@'
$replace = '$(CC) $^ $(LDLIBS) -o $@ $(LDFLAGS)'

$file = '.\deps\jsregexp\Makefile'
If (!(Test-Path $file)) {
    throw '\deps\jsregexp not found'
}
(Get-Content $file).replace($find, $replace) | Set-Content $file
$file = '.\deps\jsregexp005\Makefile'
If (!(Test-Path $file)) {
    throw '\deps\jsregexp005 not found'
}
(Get-Content $file).replace($find, $replace) | Set-Content $file

$env:CHERE_INVOKING = 'yes' # Keep current Directory
$env:MSYSTEM = 'UCRT64' # https://www.msys2.org/docs/environments/
C:\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syu'
C:\msys64\usr\bin\bash -lc 'pacman --noconfirm -S git'
C:\msys64\usr\bin\bash -lc 'pacman --noconfirm -S mingw-w64-ucrt-x86_64-luajit mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-gcc'
C:\msys64\usr\bin\bash -lc 'mingw32-make CC=gcc CFLAGS="-I/ucrt64/include/luajit-2.1 -O2 -Wall -fPIC" LDFLAGS="-shared -lluajit-5.1" install_jsregexp'

For the build option in lazy or wherever:

build = "pwsh " .. vim.fn.stdpath('config') .. "/luasnip_jsregexp_build.ps1",

Or run it manually in nvim-data/lazy/LuaSnip :

& "$env:USERPROFILE/appdata/local/nvim/luasnip_jsregexp_build.ps1"

Hope that helps. :) (edit: Added git install, Base Install add the start and the good recommandation to use stdpath('config') as script location for portability)

Kortantic commented 2 weeks ago

Hey, as this is probably the issue someone finds when googling it. I also had the same problems and solved it with the help of #986 (comment)

Also to to make it more convinient I build a powershell script I can run. What is needed:

Than I added somewhere in my user home dir ( c:/users/MYUSERNAME/ps1scripts/luasnip_jsregexp_build.ps1) this powerhell script:

$find = '$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@'
$replace = '$(CC) $^ $(LDLIBS) -o $@ $(LDFLAGS)'

$file = '.\deps\jsregexp\Makefile'
If (!(Test-Path $file)) {
  throw '\deps\jsregexp not found'
}
(Get-Content $file).replace($find, $replace) | Set-Content $file
$file = '.\deps\jsregexp005\Makefile'
If (!(Test-Path $file)) {
  throw '\deps\jsregexp005 not found'
}
(Get-Content $file).replace($find, $replace) | Set-Content $file

$env:CHERE_INVOKING = 'yes' # Keep current Directory
$env:MSYSTEM = 'UCRT64' # https://www.msys2.org/docs/environments/
C:\msys64\usr\bin\bash -lc 'pacman --noconfirm -Syu'
C:\msys64\usr\bin\bash -lc 'pacman --noconfirm -S mingw-w64-ucrt-x86_64-luajit mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-gcc'
C:\msys64\usr\bin\bash -lc 'mingw32-make CC=gcc CFLAGS="-I/ucrt64/include/luajit-2.1 -O2 -Wall -fPIC" LDFLAGS="-shared -lluajit-5.1" install_jsregexp'

For the build option in lazy or wherever:

build = "pwsh " .. vim.fn.expand('$HOME/ps1scripts/luasnip_jsregexp_build.ps1'),

Run it manually in nvim-data/lazy/LuaSnip :

& "$env:USERPROFILE/ps1scripts/luasnip_jsregexp_build.ps1"

Hope that helps. :)

I'm on Windows 10. This solved it for me. Thank you so much! I was futzing around with mingw-w64-x86_64-lua and linker commands (of which I know little about). Should have come here first. My msys2 make output looked like this:

$ make install_jsregexp
git submodule init
git submodule update
make "CC=cc" "INCLUDE_DIR=-I'/c/users/kortantic/AppData/Local/nvim-data/lazy/luasnip/deps/lua51_include/'" LDLIBS="" -C "deps/jsregexp"
make[1]: Entering directory '/c/users/kortantic/AppData/Local/nvim-data/lazy/luasnip/deps/jsregexp'

...

cc -shared jsregexp.o cutils.o libregexp.o libunicode.o  -o jsregexp.so
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: jsregexp.o:jsregexp.c:(.text+0x11):
undefined reference to luaL_checklstring'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: jsregexp.o:jsregexp.c:(.text+0x24):
undefined reference to luaL_optlstring'

...

collect2.exe: error: ld returned 1 exit status
make[1]: *** [Makefile:17: jsregexp.so] Error 1
make[1]: Leaving directory

I removed a couple hundred lines of missing lua references. Should be enough to help anyone seeing similar output. I'd recommend throwing the luasnip_jsregexp_build.ps1 in vim.fn.stdpath('config') or a child directory to help install neovim on another windows system if needed.

mrbeardad commented 1 day ago

Is there any precompiled jsregexp for Windows?