Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to install jsregexp #569

Closed
sidlatau opened this issue Sep 1, 2022 · 26 comments
Closed

Unable to install jsregexp #569

sidlatau opened this issue Sep 1, 2022 · 26 comments

Comments

@sidlatau
Copy link

sidlatau commented Sep 1, 2022

I get an error when trying to install jsregexp.
OS: macOS Monterey (M1 chip)
Neovim version:
NVIM v0.8.0-dev-2299-gc96020b2b
Build type: Release
LuaJIT 2.1.0-beta3

❯ make install_jsregexp
git submodule init
git submodule update
# conditional: find lua nvim is linked against, and link against it too.
make INCLUDE_DIR=-I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51
_include/ LDLIBS="-lluajit-5.1" -C deps/jsregexp
gcc -shared jsregexp.o cutils.o libregexp.o libunicode.o -lluajit-5.1 -o jsregexp.so
ld: library not found for -lluajit-5.1
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [jsregexp.so] Error 1
make: *** [jsregexp] Error 2
@L3MON4D3
Copy link
Owner

L3MON4D3 commented Sep 1, 2022

Mhmm that sucks :/
Could you find out the name of the luajit-dynamic library on your system?

@sidlatau
Copy link
Author

sidlatau commented Sep 1, 2022

❯ where luajit
/opt/homebrew/bin/luajit

image

Is this is the info you are asking, or should I add something more?

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Sep 1, 2022

No, that's not it, the dynamic library is (on my system at least) located at /usr/lib/libluajit-5.1.so, but I don't know what the macros-equivalents of that is.
Maybe try using find to locate it on your system, but it's also possible it just doesn't exist :/

@leiserfg
Copy link
Contributor

leiserfg commented Sep 1, 2022

Maybe try using find to locate it on your system, but it's also possible it just doesn't exist :/

ldd $(which nvim) |grep luajit

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Sep 1, 2022

Maybe try using find to locate it on your system, but it's also possible it just doesn't exist :/

ldd (which nvim) |grep luajit

Aha, yes ofc, very nice 👍

@sidlatau
Copy link
Author

sidlatau commented Sep 1, 2022

ldd is not available in macOS, looks like otool is equivalent.
Output:

❯ otool -L /opt/homebrew/bin/nvim | grep luajit
	/opt/homebrew/opt/luajit/lib/libluajit-5.1.2.dylib (compatibility version 2.1.0, current version 2.1.0)

Is this info enough to identify the problem?

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Sep 1, 2022

Yess, thank you!
Could you try the branch jsregexp_homebrew?

@sidlatau
Copy link
Author

sidlatau commented Sep 1, 2022

I am getting the same error:

❯ make install_jsregexp
git submodule init
git submodule update
# conditional: find lua nvim is linked against, and link against it too.
make INCLUDE_DIR=-I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51
_include/ LDLIBS=-llua5.1 -C deps/jsregexp
gcc -shared jsregexp.o cutils.o libregexp.o libunicode.o -llua5.1 -o jsregexp.so
ld: library not found for -llua5.1
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [jsregexp.so] Error 1
make: *** [jsregexp] Error 2

I even tried to hardcode:

LUA_LIBNAME=luajit5.1.2
JSREGEXP_PATH=deps/jsregexp
jsregexp:
	git submodule init
	git submodule update
	# conditional: find lua nvim is linked against, and link against it too.
	make INCLUDE_DIR=-I$(shell pwd)/deps/lua51_include/ LDLIBS=-l${LUA_LIBNAME} -C ${JSREGEXP_PATH}

but library still not found:

❯ make install_jsregexp
git submodule init
git submodule update
# conditional: find lua nvim is linked against, and link against it too.
make INCLUDE_DIR=-I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51
_include/ LDLIBS=-lluajit5.1.2 -C deps/jsregexp
gcc -shared jsregexp.o cutils.o libregexp.o libunicode.o -lluajit5.1.2 -o jsregexp.so
ld: library not found for -lluajit5.1.2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [jsregexp.so] Error 1
make: *** [jsregexp] Error 2

@kmarius
Copy link
Contributor

kmarius commented Sep 1, 2022

Can you try with an empty LDLIBS=?

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Sep 1, 2022

Ah, my bad, the name should be luajit-5.1.2 🤦
pull again, should work now.

@sidlatau
Copy link
Author

sidlatau commented Sep 2, 2022

I pulled the code, now the output is:

❯ make install_jsregexp
git submodule init
git submodule update
# conditional: find lua nvim is linked against, and link against it too.
make INCLUDE_DIR=-I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51
_include/ LDLIBS=-lluajit-5.1.2 -C deps/jsregexp
gcc -shared jsregexp.o cutils.o libregexp.o libunicode.o -lluajit-5.1.2 -o jsregexp.so
ld: library not found for -lluajit-5.1.2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [jsregexp.so] Error 1
make: *** [jsregexp] Error 2

@kmarius if I make LDLIBS empty output is:

 make install_jsregexp
git submodule init
git submodule update
# conditional: find lua nvim is linked against, and link against it too.
make INCLUDE_DIR=-I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51
_include/ LDLIBS=
git clone --depth 1 https://github.com/neovim/neovim deps/nvim || (cd deps/nvim; git fet
ch --depth 1; git checkout origin/master)
fatal: destination path 'deps/nvim' already exists and is not an empty directory.
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
HEAD is now at 12fe197 Merge pull request #20040 from zeertzjq/vim-9.0.0342
# access via require("luasnip-jsregexp")
# The hyphen must be used here, otherwise the luaopen_*-call will fail.
# See the package.loaders-section [here](https://www.lua.org/manual/5.1/manual.html#pdf-
require)
cp /Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/jsregexp/jsregexp.so 
/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/lua/luasnip-jsregexp.so
cp: /Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/jsregexp/jsregexp.so
: No such file or directory
make: *** [install_jsregexp] Error 1

@sidlatau
Copy link
Author

sidlatau commented Sep 2, 2022

I tested on other mac, which has Intel processor (2,2 GHz Quad-Core Intel Core i7), it works!

make install_jsregexp
git submodule init
git submodule update
# conditional: find lua nvim is linked against, and link against it too.
make INCLUDE_DIR=-I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51_include/ LDLIBS=-lluajit-5.1.2 -C deps/jsregexp
gcc -I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51_include/ -O2 -fPIC -c jsregexp.c -o jsregexp.o
gcc -I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51_include/ -O2 -fPIC -c cutils.c -o cutils.o
gcc -I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51_include/ -O2 -fPIC -c libregexp.c -o libregexp.o
gcc -I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51_include/ -O2 -fPIC -c libunicode.c -o libunicode.o
gcc -shared jsregexp.o cutils.o libregexp.o libunicode.o -lluajit-5.1.2 -o jsregexp.so
# access via require("luasnip-jsregexp")
# The hyphen must be used here, otherwise the luaopen_*-call will fail.
# See the package.loaders-section [here](https://www.lua.org/manual/5.1/manual.html#pdf-require)
cp /Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/jsregexp/jsregexp.so /Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/lua/luasnip-jsregexp.so

Maybe previous error somehow related that mac has arm64 architecture?

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Sep 2, 2022

I pulled the code, now the output is: ...

Mhm, I pushed once more, maybe that does it 😅

@kmarius if I make LDLIBS empty output is: ...

Could you try that again? The current output is very unexpected, it somehow ends up at the target nvim, which definitely shoudn't happen.

I tested on other mac, which has Intel processor (2,2 GHz Quad-Core Intel Core i7), it works!

Oho, could you find out (via otool again) where the dynamic library is located on that machine?

@kmarius
Copy link
Contributor

kmarius commented Sep 2, 2022

@sidlatau You deleted too much causing it to use the root Makefile (with the nvim target). It should be

make INCLUDE_DIR=-I$(shell pwd)/deps/lua51_include/ LDLIBS= -C ${JSREGEXP_PATH}

@sidlatau
Copy link
Author

sidlatau commented Sep 2, 2022

@sidlatau You deleted too much causing it to use the root Makefile (with the nvim target). It should be

make INCLUDE_DIR=-I$(shell pwd)/deps/lua51_include/ LDLIBS= -C ${JSREGEXP_PATH}

The output now:

make install_jsregexp
git submodule init
git submodule update
make INCLUDE_DIR=-I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51
_include/ LDLIBS= -C deps/jsregexp
gcc -I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51_include/ -O2
 -fPIC -c jsregexp.c -o jsregexp.o
gcc -shared jsregexp.o cutils.o libregexp.o libunicode.o  -o jsregexp.so
Undefined symbols for architecture arm64:
  "_luaL_checklstring", referenced from:
      _jsregexp_compile in jsregexp.o
      _regexp_call in jsregexp.o
  "_luaL_checkudata", referenced from:
      _regexp_call in jsregexp.o
      _regexp_tostring in jsregexp.o
  "_luaL_newmetatable", referenced from:
      _luaopen_jsregexp in jsregexp.o
  "_luaL_register", referenced from:
      _luaopen_jsregexp in jsregexp.o
  "_lua_createtable", referenced from:
      _luaopen_jsregexp in jsregexp.o
      _regexp_call in jsregexp.o
  "_lua_getfield", referenced from:
      _jsregexp_compile in jsregexp.o
  "_lua_newuserdata", referenced from:
      _jsregexp_compile in jsregexp.o
  "_lua_pushfstring", referenced from:
      _regexp_tostring in jsregexp.o
  "_lua_pushlstring", referenced from:
      _regexp_call in jsregexp.o
  "_lua_pushnil", referenced from:
      _jsregexp_compile in jsregexp.o
      _regexp_call in jsregexp.o
  "_lua_pushnumber", referenced from:
      _regexp_call in jsregexp.o
  "_lua_pushstring", referenced from:
      _jsregexp_compile in jsregexp.o
      _regexp_call in jsregexp.o
  "_lua_rawseti", referenced from:
      _regexp_call in jsregexp.o
  "_lua_setfield", referenced from:
      _regexp_call in jsregexp.o
  "_lua_setmetatable", referenced from:
      _jsregexp_compile in jsregexp.o
  "_lua_settop", referenced from:
      _luaopen_jsregexp in jsregexp.o
  "_lua_touserdata", referenced from:
      _regexp_gc in jsregexp.o
  "_lua_type", referenced from:
      _jsregexp_compile in jsregexp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [jsregexp.so] Error 1
make: *** [jsregexp] Error 2

@sidlatau
Copy link
Author

sidlatau commented Sep 2, 2022

I pulled the code, now the output is: ...

Mhm, I pushed once more, maybe that does it 😅

Output is:

make install_jsregexp
git submodule init
git submodule update
make INCLUDE_DIR=-I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51
_include/ LDLIBS="-lluajit-5.1.2 -L/opt/homebrew/opt/luajit/lib/" -C deps/jsregexp
gcc -shared jsregexp.o cutils.o libregexp.o libunicode.o -lluajit-5.1.2 -L/opt/homebrew/
opt/luajit/lib/ -o jsregexp.so
# access via require("luasnip-jsregexp")
# The hyphen must be used here, otherwise the luaopen_*-call will fail.
# See the package.loaders-section [here](https://www.lua.org/manual/5.1/manual.html#pdf-
require)
cp /Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/jsregexp/jsregexp.so 
/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/lua/luasnip-jsregexp.so

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Sep 2, 2022

Okay, that looks good, do transformations work now?
I guess adding a potentially unused dl-path won't hurt too, so that's nice.
Does the new version also still work on you other machine?

@sidlatau
Copy link
Author

sidlatau commented Sep 2, 2022

Does the new version also still work on you other machine?

On Intel macos brew directory is different: https://docs.brew.sh/Installation

This script installs Homebrew to its preferred prefix (/usr/local for macOS Intel, /opt/homebrew for Apple Silicon and /home/linuxbrew/.linuxbrew for Linux) so that you don’t need sudo when you brew install. It is a careful script; it can be run even if you have stuff installed in the preferred prefix already.

Output:

make install_jsregexp
git submodule init
git submodule update
make INCLUDE_DIR=-I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51_include/ LDLIBS="-lluajit-5.1.2 -L/opt/homebrew/opt/luajit/lib/" -C deps/jsregex
p
gcc -I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51_include/ -O2 -fPIC -c jsregexp.c -o jsregexp.o
gcc -shared jsregexp.o cutils.o libregexp.o libunicode.o -lluajit-5.1.2 -L/opt/homebrew/opt/luajit/lib/ -o jsregexp.so
ld: warning: directory not found for option '-L/opt/homebrew/opt/luajit/lib/'
# access via require("luasnip-jsregexp")
# The hyphen must be used here, otherwise the luaopen_*-call will fail.
# See the package.loaders-section [here](https://www.lua.org/manual/5.1/manual.html#pdf-require)
cp /Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/jsregexp/jsregexp.so /Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/lua/luasnip-jsregexp.s
o

But build generates jsregexp.o file successfully.

@sidlatau
Copy link
Author

sidlatau commented Sep 2, 2022

Okay, that looks good, do transformations work now?

I am not seeing transformations to work, but maybe I am doing something wrong.
Snippet:

  "Built Value Type File": {
    "prefix": "bvtf",
    "body": [
      "import 'package:built_collection/built_collection.dart';",
      "import 'package:built_value/built_value.dart';",
      "",
      "part '$TM_FILENAME_BASE.g.dart';",
      "",
      "abstract class ${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/} implements Built<${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/}, ${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/}Builder> {",
      "  ${2}",
      "",
      "  ${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/}._();",
      "  factory ${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/}([void Function(${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/}Builder) updates]) = _$${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/};",
      "}"
    ],
    "description": "Built Value Type File whose name corresponds to the file name"
  },

Output:

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';

part 'order_notes_state.g.dart';

abstract class order_notes_state implements Built<order_notes_state, order_notes_stateBuilder> {
  

  order_notes_state._();
  factory order_notes_state([void Function(order_notes_stateBuilder) updates]) = _$order_notes_state;
}

pascalcase transformation seem to be still ignored.

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Sep 2, 2022

Does the new version also still work on you other machine?

On Intel macos brew directory is different: https://docs.brew.sh/Installation

This script installs Homebrew to its preferred prefix (/usr/local for macOS Intel, /opt/homebrew for Apple Silicon and /home/linuxbrew/.linuxbrew for Linux) so that you don’t need sudo when you brew install. It is a careful script; it can be run even if you have stuff installed in the preferred prefix already.

Ahh, nice work, yeah that's exactly what was going wrong 👍
Now I have a nice reference for that change :D

Output:

make install_jsregexp
git submodule init
git submodule update
make INCLUDE_DIR=-I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51_include/ LDLIBS="-lluajit-5.1.2 -L/opt/homebrew/opt/luajit/lib/" -C deps/jsregex
p
gcc -I/Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/lua51_include/ -O2 -fPIC -c jsregexp.c -o jsregexp.o
gcc -shared jsregexp.o cutils.o libregexp.o libunicode.o -lluajit-5.1.2 -L/opt/homebrew/opt/luajit/lib/ -o jsregexp.so
ld: warning: directory not found for option '-L/opt/homebrew/opt/luajit/lib/'
# access via require("luasnip-jsregexp")
# The hyphen must be used here, otherwise the luaopen_*-call will fail.
# See the package.loaders-section [here](https://www.lua.org/manual/5.1/manual.html#pdf-require)
cp /Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/deps/jsregexp/jsregexp.so /Users/ts/.local/share/nvim/site/pack/packer/start/LuaSnip/lua/luasnip-jsregexp.s
o

But build generates jsregexp.o file successfully.

Great, that sounds good

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Sep 2, 2022

Okay, that looks good, do transformations work now?

I am not seeing transformations to work, but maybe I am doing something wrong. Snippet:

  "Built Value Type File": {
    "prefix": "bvtf",
    "body": [
      "import 'package:built_collection/built_collection.dart';",
      "import 'package:built_value/built_value.dart';",
      "",
      "part '$TM_FILENAME_BASE.g.dart';",
      "",
      "abstract class ${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/} implements Built<${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/}, ${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/}Builder> {",
      "  ${2}",
      "",
      "  ${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/}._();",
      "  factory ${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/}([void Function(${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/}Builder) updates]) = _$${TM_FILENAME_BASE/(.*)$/${1:/pascalcase}/};",
      "}"
    ],
    "description": "Built Value Type File whose name corresponds to the file name"
  },

Output:

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';

part 'order_notes_state.g.dart';

abstract class order_notes_state implements Built<order_notes_state, order_notes_stateBuilder> {
  

  order_notes_state._();
  factory order_notes_state([void Function(order_notes_stateBuilder) updates]) = _$order_notes_state;
}

pascalcase transformation seem to be still ignored.

Ahhh, yeah we don't support all of those yet (only those in the lsp-spec, '/upcase' | '/downcase' | '/capitalize'), could you open a new issue for that?
But jsregexp works! That's the important takeaway :D
I'll push the fix shortly

@sidlatau
Copy link
Author

sidlatau commented Sep 2, 2022

@L3MON4D3 thanks! Should I close this issue now or any work is still pending for it?

@L3MON4D3
Copy link
Owner

L3MON4D3 commented Sep 2, 2022

Oh, go ahead, I'm about to push the fix

L3MON4D3 added a commit that referenced this issue Sep 2, 2022
See [here](https://docs.brew.sh/Installation), the prefix `/opt/hombrew`
is not searched by apples ld, so we just pass it.
@kmarius
Copy link
Contributor

kmarius commented Sep 2, 2022

Undefined symbols for architecture arm64:

Ok, that's odd. We shouldn't need to link against lua since we are building a shared object. In fact, I can build it just fine on my machines (including an arm64) without any lua installed.

@sidlatau
Copy link
Author

sidlatau commented Sep 2, 2022

My original problem was solved, so closing an issue. Thanks!

@rawatkushagra
Copy link

I was also facing the same issue but after i installed lua51-jsregexp 0.0.7-1 package using pacman the issue was resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants