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

Lapis cjson dependency breaks on openresty-1.11.2.3 #539

Closed
nelson2005 opened this issue Apr 25, 2017 · 17 comments
Closed

Lapis cjson dependency breaks on openresty-1.11.2.3 #539

nelson2005 opened this issue Apr 25, 2017 · 17 comments

Comments

@nelson2005
Copy link

Lapis has a dependency on cjson, which seems not to be actively maintained. Openresty comes bundled with a maintained version of cjson- https://github.com/openresty/lua-cjson

The luarocks version of cjson doesn't work with the newest openresty- would it be possible to use the already-bundled cjson to fulfill the dependency, and not include the luarocks version? I think this issue will affect anyone installing the openresty 1.11.2.3 and later.

I've attached my luarocks log file below.

Thanks

luarocks.txt

@leafo
Copy link
Owner

leafo commented Apr 25, 2017

lapis can run outside of openresty, so we need some json library. I think they should either take over maintenance of the project on luarocks or publish it with a different name.

Within openresty though, I would assume their bundled version would take precedence over a system installed version when requiring the module. Are you seeing an issue with the wrong cjson library being loaded?

@nelson2005
Copy link
Author

Understood on the running outside openresty.

Not so much on the wrong library being loaded... lapis can't even be installed. The luarocks dependency manager doesn't "see" the openresty-installed cjson, so it tries to install it. I'd guess it's something about the way it looks up if a dependency is installed. In my log, it shows

Missing dependencies for lapis 1.5.1-1: ansicolors (not installed) date (not installed) etlua (not installed) loadkit (not installed) lpeg (not installed) lua-cjson (not installed)

so it seems unaware that the openresty cjson can fulfill the dependency.

@thibaultcha
Copy link

thibaultcha commented Apr 25, 2017

If I may: this discussion originated from https://groups.google.com/forum/#!topic/openresty-en/GXoaQNoUurs. imho, the path forward - as highlighted in my message on the openresty-en mailing list - would be to make Lapis depend on openresty/lua-cjson, which is a fully backwards-compatible fork of mpx/lua-cjson.

On top of a few bug fixes (including this compatibility with the latest LuaJIT 2.1), the addition of the cjson.empty_array and cjson.empty_array_mt values allow for a much needed granularity in JSON encoding, especially in a web framework such as Lapis that eventually has to deal with JSON responses.

@nelson2005
Copy link
Author

nelson2005 commented Apr 25, 2017 via email

@nelson2005
Copy link
Author

@thibaultcha - Apologies for the messy response, I was on my mobile device and didn't realize it would show up here. My comment added no value.

@zejji
Copy link

zejji commented May 9, 2017

Is there any way to get round this issue in the interim? Currently running "luarocks install lapis" on Openresty (which I imagine most people will be using) simply does not work, so it's impossible to install lapis.

I'm not familiar enough we the luarocks ecosystem to debug this myself :(

@zejji
Copy link

zejji commented May 9, 2017

By way of update, I was able to get Lapis working with Openresty 1.11.2.3 in the interim by:

  • Downloading the lapis rockspec file from https://luarocks.org/manifests/leafo/lapis-1.5.1-1.rockspec
  • Commenting out the "lua-cjson" dependency
  • Running "luarocks install lapis-1.5.1-1.rockspec"
  • Copying Openresty's cjson.so file (which for me was in /usr/local/openresty/lualib/cjson.so) into my Lapis project directory (which is one of the paths Lapis will search for dependencies)

Just a dirty hack, I know, but I thought I'd leave a comment in case it helps anyone else.

@devvit
Copy link

devvit commented May 15, 2017

Just see here #34

After compile openresty, go to openresty-1.11.2.3/build/lua-cjson-2.1.0.5, run "luarocks make",

or install latest lua-cjson from https://github.com/openresty/lua-cjson.

@leafo
Copy link
Owner

leafo commented Jul 21, 2017

Just following up with this ticket, I can't make any chnages until the updated cjson library is available in LuaRocks. In the meantime, you can install lapis with your distro's version of lua with no issues as far as I can tell.

@nelson2005
Copy link
Author

Okay, thanks. I need the openresty functionality so I'll just use a workaround for now.

@CriztianiX
Copy link
Contributor

CriztianiX commented Aug 1, 2017

https://luarocks.org/modules/criztianix/lua-cjson2

This contains the updated version for lua-cjson from openresty.
Changing "lua-cjson" dependency to "lua-cjson2" lapis install without errors.

[my@myrocks src]$ luarocks make
Missing dependencies for lapis:
lpeg 
mimetypes 
pgmoon 
luasocket 
ansicolors 
lua-cjson2 
luaossl 
luafilesystem 
date

Using https://luarocks.org/lua-cjson2-2.1devel-1.src.rock... switching to 'build' mode
gcc -O2 -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1 -c lua_cjson.c -o lua_cjson.o
gcc -O2 -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1 -c strbuf.c -o strbuf.o
gcc -O2 -fPIC -I/usr/local/openresty/luajit/include/luajit-2.1 -c fpconv.c -o fpconv.o
gcc -shared -o cjson.so -L/usr/local/openresty/luajit/lib lua_cjson.o strbuf.o fpconv.o
Updating manifest for /usr/local/openresty/luajit/lib/luarocks/rocks
lua-cjson2 2.1devel-1 is now built and installed in /usr/local/openresty/luajit (license: MIT)

Using https://luarocks.org/luaossl-20161214-0.src.rock
...

@nelson2005
Copy link
Author

@CriztianiX Thanks for patching that up in LuaRocks!

@CriztianiX
Copy link
Contributor

CriztianiX commented Aug 2, 2017

@nelson2005 you'are welcome!
@leafo maybe we need update the rockspec?

@neomantra
Copy link

I worked around this issue by installing the luarocks dependencies manually, without cjson, then installing lapis with --deps-mode=none. To support the lapis CLI command, the cjson.so is copied to a path that the command-line luajit has access to (versus where it originally lives for OpenResty).

Here's a Dockerfile that shows this:

FROM openresty/openresty:1.11.2.5-xenial
MAINTAINER "Evan Wies <evan@neomantra.net>"

# install Lapis
RUN DEBIAN_FRONTEND=noninteractive apt-get update \
    && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        libssl-dev \
    && /usr/local/openresty/luajit/bin/luarocks install ansicolors \
    && /usr/local/openresty/luajit/bin/luarocks install date \
    && /usr/local/openresty/luajit/bin/luarocks install etlua \
    && /usr/local/openresty/luajit/bin/luarocks install loadkit \
    && /usr/local/openresty/luajit/bin/luarocks install lpeg \
    && /usr/local/openresty/luajit/bin/luarocks install luaossl \
    && /usr/local/openresty/luajit/bin/luarocks install luafilesystem \
    && /usr/local/openresty/luajit/bin/luarocks install luasocket \
    && /usr/local/openresty/luajit/bin/luarocks install mimetypes \
    && /usr/local/openresty/luajit/bin/luarocks install pgmoon \
    && cp /usr/local/openresty/lualib/cjson.so /usr/local/openresty/luajit/lib/lua/5.1/ \
    && /usr/local/openresty/luajit/bin/luarocks install --deps-mode=none lapis \
    && DEBIAN_FRONTEND=noninteractive apt-get remove --purge -y \
        libssl-dev \
    && DEBIAN_FRONTEND=noninteractive apt-get autoremove -y \
    && rm -rf /var/lib/apt/lists/*

@CriztianiX
Copy link
Contributor

You can use this:
https://luarocks.org/modules/criztianix/lua-cjson2

@neomantra
Copy link

I saw that (and thank you for publishing it!), but I want to:

  1. get Lapis from LuaRocks repo (versus modifying the rockspec)
  2. use the same exact cjson with OpenResty and plain LuaJIT

@leafo
Copy link
Owner

leafo commented Apr 2, 2018

Closing this since it appears that the cjson on luarocks is now the one owned by openresty: https://luarocks.org/modules/openresty/lua-cjson

@leafo leafo closed this as completed Apr 2, 2018
tzssangglass added a commit to tzssangglass/skywalking-nginx-lua that referenced this issue Jan 13, 2022
since lua-cjson 2.1.0-1 may fail to install, ref
openresty/lua-cjson#21, so use lua-cjson2,
ref: leafo/lapis#539 (comment)

Signed-off-by: tzssangglass <tzssangglass@gmail.com>
wu-sheng pushed a commit to apache/skywalking-nginx-lua that referenced this issue Jan 13, 2022
* ci: run lua test cases with luajit

since lua-cjson 2.1.0-1 may fail to install, ref
openresty/lua-cjson#21, so use lua-cjson2,
ref: leafo/lapis#539 (comment)
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

7 participants