luvit / lit

Toolkit for developing, sharing, and running luvit/lua programs and libraries.
http://lit.luvit.io/
Apache License 2.0
245 stars 58 forks source link

Bootstrapping lit with external lua-git fails #145

Closed joerg-krause closed 5 years ago

joerg-krause commented 8 years ago

I am trying to cross-build lit by bootstrapping it with an external lua-git (instead of the bundled one).

For this I have build an host variant of luvi in host/usr/bin/ as well as an target variant of luvi in target/usr/bin/. I've downloaded lit from github (without lua-git) in dl/ and installed lua-git in host/usr/share/lua/5.1/git (by copying the lua files to that directory).

$ ls host/usr/share/lua/5.1/git/
core.lua  db.lua  init.lua  package.lua  storage.lua

Bootstrapping fails:

$ host/usr/bin/luvi dl/lit-2.2.17.zip -- make dl/lit-2.2.17.zip build/lit target/usr/bin/luvi
lit version: 2.2.17
luvi version: v2.3.4
command: make dl/lit-2.2.17.zip lit target/usr/bin/luvi
fail: [string "bundle:deps/require.lua"]:271: No such module 'git' in 'bundle:/libs/pkg.lua'
/usr/share/lua/5.1/git/core.lua:36: attempt to index global 'exports' (a nil value)
stack traceback:
    [C]: in function 'error'
    [string "bundle:deps/require.lua"]:271: in function 'require'
    [string "bundle:/libs/pkg.lua"]:30: in function 'fn'
    [string "bundle:deps/require.lua"]:293: in function 'require'
    [string "bundle:/libs/core.lua"]:34: in function 'fn'
    [string "bundle:deps/require.lua"]:293: in function 'require'
    [string "bundle:/commands/make.lua"]:1: in function 'fn'
    [string "bundle:deps/require.lua"]:293: in function 'require'
    [string "bundle:/main.lua"]:52: in function <[string "bundle:/main.lua"]:39>
    [C]: in function 'xpcall'
    [string "bundle:/main.lua"]:39: in function <[string "bundle:/main.lua"]:31>

Sorry, I am a Lua novice. Do you have an idea how to solve this issue?

creationix commented 8 years ago

Luvit doesn't use the global paths to install libraries like lua does. You need the git subfolder to be present in deps/git for bootstrapping to work.

You can copy most the logic from https://github.com/luvit/lit/blob/master/get-lit.sh, but insert your custom luvi builds for host and target.

joerg-krause commented 8 years ago

Long time...

Does luvit-loader by chance change this issue? I haven't tried, yet.

creationix commented 8 years ago

It probably does. Luvit-loader works by prepending a special loader into the chain of lua require loaders. If luvit-loader can't find the file (and it won't in this case), then the normal require loaders will run as fallback. Assuming lua-git can be used this way, it will work.

But I think there will be problems if you don't modify the require paths within lua-git. Lua does not support relative requires (which is why I made luvit's custom system in the first place).

https://github.com/creationix/lua-git/blob/00bd21b8cc3a2e233276f5a70b57ca7347fdf520/init.lua#L2 and https://github.com/creationix/lua-git/blob/00bd21b8cc3a2e233276f5a70b57ca7347fdf520/init.lua#L9

creationix commented 8 years ago

Actually after thinking more about it, I think this will work with luvit-loader. Assuming the fallback loaders will find init.lua, when the relative requires are made, luvit-loader will still be first in the list and resolve them correctly.

Try it and see.

joerg-krause commented 8 years ago

Thanks so far for explanation! I'll give it a try in the next days and post the results here.

joerg-krause commented 5 years ago

Closing this issue as it has no priority anymore.