LuaSnip icon indicating copy to clipboard operation
LuaSnip copied to clipboard

Unable to install jsregexp (OS: Windows)

Open hrcHarry opened this issue 1 year ago • 3 comments

Hi, I have checked #569 but I have a slightly different situation.

OS: Windows 10 Neovim Version: NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1713484068

The installation of Luasnip via Lazy gives the following message

git submodule init
process_begin: CreateProcess(NULL, uname, ...) failed.
process_begin: CreateProcess(NULL, pwd, ...) failed.
process_begin: CreateProcess(NULL, pwd, ...) failed.
git submodule update
make "CC=cc" "INCLUDE_DIR=-I'/deps/lua51_include/'" LDLIBS="" -C "deps/jsregexp"
make[1]: Entering directory `C:/Users/User/AppData/Local/nvim-data/lazy/LuaSnip/deps/jsregexp'
cc -I'/deps/lua51_include/' -O2 -fPIC -c jsregexp.c -o jsregexp.o
process_begin: CreateProcess(NULL, cc -I/deps/lua51_include/ -O2 -fPIC -c jsregexp.c -o jsregexp.o, ...) failed.

make[1]: *** [jsregexp.o] Error 2
make[1]: Leaving directory `C:/Users/User/AppData/Local/nvim-data/lazy/LuaSnip/deps/jsregexp'
make: *** [jsregexp] Error 2

Additional info: I have installed gcc, g++, zig, and clang (Visual Studio) is installed on my machine before installing Luasnip.

Could anyone help? Thanks.

hrcHarry avatar Aug 06 '24 06:08 hrcHarry

I have the very same issue with a clean install of Neovim and clean pull of the plugin.

JohnWilliston avatar Oct 24 '24 23:10 JohnWilliston

Wow. And at the end of the day, it doesn't make one whit of difference. I finally fought through all the nonsense necessary to get the make files and everything building without errors in the right directory and everything. The following screenshot is of me using the MSYS2 UCRT64 command window to do an uninstall and a reinstall in the very LuaSnip folder:

2024-10-24 19_40_35-_c_Users_John_AppData_Local_nvim-data_lazy_LuaSnip

The jsregexp.so file builds just fine and copies to deps/luasnip-jsregexp.so just fine. I can copy both of those *.so files to my nvim/lua folder or anywhere else, but checking health still complains that the jsregexp library is not installed. I seriously don't know how to make this thing happy.

JohnWilliston avatar Oct 25 '24 02:10 JohnWilliston

For anyone following this thread, or other other threads about the difficulties of getting jsregexp working with Luasnip on Windows, I posted a reply today on one of the jsregexp issues that explains how I eventually got it working. I hope it might prove useful to others as a guide what not to do and what to do as well.

JohnWilliston avatar Oct 26 '24 19:10 JohnWilliston

Please have a try for the fix #1252

xudyang1 avatar Nov 11 '24 21:11 xudyang1

Having a lot of troubles with the makefile

https://github.com/L3MON4D3/LuaSnip/blob/0f7bbce41ea152a94d12aea286f2ce98e63c0f58/Makefile#L87 I replaced that with $(CURDIR) otherwise PROJECT_ROOT just evaluated to "".

https://github.com/L3MON4D3/LuaSnip/blob/0f7bbce41ea152a94d12aea286f2ce98e63c0f58/Makefile#L84 and I replaced this with LUA_LDLIBS?=$(if $(strip $(NEOVIM_BIN_PATH)),-L$("NEOVIM_BIN_PATH") -llua51,), note the quotation marks otherwise it struggled with the space in "Program Files"

error: unable to find dynamic system library 'lua51' using strategy 'paths_first'. searched paths:
  C:\Program\lua51.dll
  C:\Program\lua51.lib
  C:\Program\liblua51.a

that got it to run the makefile in powershell and msys.

also it doesnt seem to work with llvm but only gcc? otherwise i still get linking errors.

and yeah then it still doesnt do anything just like @JohnWilliston said

zeratax avatar Dec 23 '24 05:12 zeratax

Having a lot of troubles with the makefile

https://github.com/L3MON4D3/LuaSnip/blob/0f7bbce41ea152a94d12aea286f2ce98e63c0f58/Makefile#L87

I replaced that with $(CURDIR) otherwise PROJECT_ROOT just evaluated to "". https://github.com/L3MON4D3/LuaSnip/blob/0f7bbce41ea152a94d12aea286f2ce98e63c0f58/Makefile#L84

and I replaced this with LUA_LDLIBS?=$(if $(strip $(NEOVIM_BIN_PATH)),-L$("NEOVIM_BIN_PATH") -llua51,), note the quotation marks otherwise it struggled with the space in "Program Files"

error: unable to find dynamic system library 'lua51' using strategy 'paths_first'. searched paths:
  C:\Program\lua51.dll
  C:\Program\lua51.lib
  C:\Program\liblua51.a

that got it to run the makefile in powershell and msys.

also it doesnt seem to work with llvm but only gcc? otherwise i still get linking errors.

and yeah then it still doesnt do anything just like @JohnWilliston said

How do you install LuaSnip and do you use any package manager? I have tested locally on powershell 7.4.6 and git bash, both worked fine.

xudyang1 avatar Jan 02 '25 03:01 xudyang1

How do you install LuaSnip and do you use any package manager? I have tested locally on powershell 7.4.6 and git bash, both worked fine.

For my part, I use the following luasnip.lua file in my nvim/lua/plugins folder if that helps:

return {
    "L3MON4D3/LuaSnip",
    -- follow latest release.
    -- version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
    -- install jsregexp (optional!).
    build = "make install_jsregexp",
    dependencies = {
        "saadparwaiz1/cmp_luasnip",
        "rafamadriz/friendly-snippets",
    },
    config = function()

        local ls = require("luasnip")

        local t = ls.text_node
        local i = ls.insert_node
        local f = ls.function_node
        local s = ls.snippet
        local l = require("luasnip.extras").lambda

        -- args is a table, where 1 is the text in Placeholder 1, 2 the text in
        -- placeholder 2,...
        local function copy(args)
            return args[1]
        end

        ls.add_snippets("all", {
            -- trigger is `fn`, second argument to snippet-constructor are the nodes to insert into the buffer on expansion.
            s("fn", {
                -- Simple static text.
                t("//Parameters: "),
                -- function, first parameter is the function, second the Placeholders
                -- whose text it gets as input.
                f(copy, 2),
                t({ "", "function " }),
                -- Placeholder/Insert.
                i(1),
                t("("),
                -- Placeholder with initial text.
                i(2, "int foo"),
                -- Linebreak
                t({ ") {", "\t" }),
                -- Last Placeholder, exit Point of the snippet.
                i(0),
                t({ "", "}" }),
            }),

            s("transform", {
                i(1, "initial text"),
                t({ "", "" }),
                -- lambda nodes accept an l._1,2,3,4,5, which in turn accept any string transformations.
                -- This list will be applied in order to the first node given in the second argument.
                l(l._1:match("[^i]*$"):gsub("i", "o"):gsub(" ", "_"):upper(), 1),
            }),
        }, {
            key = "all",
        })

        require("luasnip.loaders.from_vscode").lazy_load()

    end,
}

JohnWilliston avatar Jan 02 '25 20:01 JohnWilliston

@JohnWilliston If you are using make with gcc, the following may work


local IN_WINDOWS = vim.fn.has("win32") == 1 or vim.fn.has("win64") == 1
return {
  "L3MON4D3/LuaSnip",
  build = IN_WINDOWS and "make install_jsregexp CC=gcc" or "make install_jsregexp",
  -- more ...
}
  • If it does not work, please check:
  1. which sh.exe points to Git/MinGW/MSYS2 sh.exe
  • if empty, append SHELL=C:/path/to/Git/usr/bin/sh.exe after make install_jsregexp
  1. which cc points to a compiler
  • if empty, append CC=gcc after make install_jsregexp

xudyang1 avatar Jan 07 '25 21:01 xudyang1

@zeratax llvm should also work. You can try make install_jsregexp CC=clang

xudyang1 avatar Jan 07 '25 22:01 xudyang1

I appreciate the attempts to help, thank you. I've moved on after finding the workaround I linked above.

JohnWilliston avatar Jan 10 '25 18:01 JohnWilliston

@JohnWilliston The lastest commit 7351d673f430e89f11962dc45b7360d6a0a26d2d should work with make install_jsregexp.

xudyang1 avatar May 03 '25 17:05 xudyang1

@JohnWilliston The lastest commit 7351d67 should work with make install_jsregexp.

Thanks for letting me know. I do a clean install from time to time and will see if that fixes my prior issue.

JohnWilliston avatar May 03 '25 21:05 JohnWilliston

This makefile is a bit of a mess on windows. Both CC and LUA_LDLIBS evaluate to blank. I'm using mingw64 on the standard cmd prompt version of nvim.

So I've tried to fix CC and LUA_LDLIBS and you still wind up with file not found errors and it trying to run commands like rm and cp resulting in other errors.

Oh, and if you do copy the files where the makefile says to :checkhealth still says it's missing jsregexp. And this is on the master version: 75bf25e according to lazy.

ouch67 avatar May 07 '25 14:05 ouch67

@ouch67 CC is blank when Makefile does not detect any C compiler (gcc, clang, zig, or custom CC). LUA_LDLIBS depends on uname command, can you post the value returned by uname command in your mingw64 environment? Alternatively, you could try a clean install of LuaSnip to prevent cache from interfering with the installation process.

xudyang1 avatar May 07 '25 23:05 xudyang1

Uname is not a a windows command nor is it a mingw one. So it just says it's not recognized as an internal or external command.

"which" has a similar problem which is why it can't detect the compiler.

ouch67 avatar May 08 '25 14:05 ouch67

Uname is not a a windows command nor is it a mingw one. So it just says it's not recognized as an internal or external command.

"which" has a similar problem which is why it can't detect the compiler.

I just realized that MinGW is not like MSYS2, it is a port of gcc to Windows and it does not come with a shell environment (https://superuser.com/questions/1258498/how-to-start-the-shell-in-mingw-64).

If you want to build jsregexp, you may need MSYS2 environment or use mingw32-make properly. (https://stackoverflow.com/questions/36770716/mingw64-make-build-error-bash-make-command-not-found)

I assume you are running nvim in cmd with Git for Windows installed under C:/Program Files/Git. Then, the easiest way to get the work done is to let make use C:/Program Files/Git/bin/sh.exe: make install_jsregexp SHELL=path_to_git_root/bin/sh.exe or, you can add %GIT%/bin to $PATH and keep make install_jsregexp unmodified, then make.exe can find git's sh.exe.

xudyang1 avatar May 09 '25 04:05 xudyang1

I can build the file by setting the variables manually.

The issue is that once luasnip-jsregexp.lua and luasnip-jsregexp.so are copied to the lua directory and luasnip-jsregexp.so to the deps directory, checkhealth still says luasnip cannot find the jsregexp library. I'm not sure where it's trying to look or even what file type it's actually looking for. (Should it be a dll file or something?)

ouch67 avatar May 09 '25 20:05 ouch67

I have created a discussion for this. We can continue the topic at #1341 .

xudyang1 avatar May 09 '25 22:05 xudyang1

I was able to resolve the issue by using the following configuration:

build = 'make install_jsregexp CC=gcc SHELL="C:/Program Files/Git/bin/sh.exe"' -- update the path to sh.exe accordingly

After applying this change, running :checkhealth luasnip no longer reports any errors. (Oddly, build = 'make install_jsregexp CC=gcc' remains ineffective, despite my expectation that #1343 would have addressed this.)

georgejean avatar Jun 23 '25 09:06 georgejean

I was able to resolve the issue by using the following configuration:

build = 'make install_jsregexp CC=gcc SHELL="C:/Program Files/Git/bin/sh.exe"' -- update the path to sh.exe accordingly

After applying this change, running :checkhealth luasnip no longer reports any errors. (Oddly, build = 'make install_jsregexp CC=gcc' remains ineffective, despite my expectation that #1343 would have addressed this.)

Can you try #1346, with a minimal configuration like this

The full steps are:

  1. mkdir minimal_nvim; cd minimal_nvim
  2. touch init.lua, and put the following config into init.lua:
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

local luasnip_config = {
	"xudyang1/LuaSnip", -- "L3MON4D3/LuaSnip",
	branch = "fix/makefile-SHELL", -- wait to be merged to upstream
	lazy = false,
	dependencies = { "rafamadriz/friendly-snippets" },
	build = "make install_jsregexp", -- optional
	config = function()
		local luasnip = require("luasnip")

		luasnip.config.setup()

		require("luasnip.loaders.from_vscode").lazy_load({
			paths = { vim.fn.stdpath("data") .. "/lazy/friendly-snippets" },
		})
	end,
}

local plugins = { luasnip_config }

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})
  1. nvim -u init.lua
  2. wait until lazy.nvim finishes download
  3. Run :checkhealth luasnip in neovim

For testing after initial download, run rm -rf .repro to cleanup old caches before step 3.

xudyang1 avatar Jun 30 '25 00:06 xudyang1

Ok, here is what I've done:

cd $env:LOCALAPPDATA
mkdir repro
cd repro

then I edit a init.lua file with this content:

-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
	local lazyrepo = "https://github.com/folke/lazy.nvim.git"
	local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
	if vim.v.shell_error ~= 0 then
		vim.api.nvim_echo({
			{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
			{ out, "WarningMsg" },
			{ "\nPress any key to exit..." },
		}, true, {})
		vim.fn.getchar()
		os.exit(1)
	end
end
vim.opt.rtp:prepend(lazypath)
-- Make sure to setup `mapleader` and `maplocalleader` before
-- loading lazy.nvim so that mappings are correct.
-- This is also a good place to setup other settings (vim.opt)
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"

local luasnip_config = {
	"xudyang1/LuaSnip", -- "L3MON4D3/LuaSnip",
	branch = "fix/makefile-SHELL", -- wait to be merged to upstream
	lazy = false,
	build = "make install_jsregexp", -- optional
	config = function()
		local luasnip = require("luasnip")
		luasnip.config.setup()
		require("luasnip.loaders.from_lua").lazy_load({ paths = { vim.fn.stdpath("config") .. "/lua/custom/LuaSnip/" } })
	end,
}

require("lazy").setup({
	spec = {
		luasnip_config,
	},
})

then using

$env:NVIM_APPNAME = "repro"
nvim

during the loading, jsregexp has been correctly installed, and :checkhealth luasnip says so. Cool !

I will clean now repro and repro-data because I'm on Windows.

Thanks for your consideration.

georgejean avatar Jul 01 '25 17:07 georgejean