sile-typesetter / sile

The SILE Typesetter — Simon’s Improved Layout Engine
https://sile-typesetter.org
MIT License
1.67k stars 98 forks source link

Rust build on macOS can't use os.getenv, hence uses can't setup custom LuaRocks installs #2121

Closed alerque closed 1 week ago

alerque commented 1 month ago

I gave this script to Homebrew user @no-vici:

#!/bin/bash

echo 'system default:'
env | grep LUA_PATH

eval "$(luarocks --lua-version 5.1 --local path)"

echo 'after adding local path:'
env | grep LUA_PATH

lp='print((("LUA_PATH=%s"):format(os.getenv("LUA_PATH"))))'

echo 'per lua5.1:'
lua5.1 -e "$lp"

echo 'per luajit:'
luajit -e "$lp"

echo 'per sile rust:'
sile -q -e "$lp;os.exit()"

echo 'per sile lua:'
sile-lua -q -e "$lp;os.exit()"

and got back this:

This is the output of your script in my untampered shell, LUA_PATH should be nothing, but my ~/.luarock still in there.

``` system default: after adding local path: LUA_PATH=/usr/local/Cellar/luarocks/3.11.1/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua;./?.lua;./?/init.lua;/Users/no-vici/.luarocks/share/lua/5.1/?.lua;/Users/no-vici/.luarocks/share/lua/5.1/?/init.lua per lua5.1: lua_api_check.sh: line 14: lua5.1: command not found per luajit: LUA_PATH=/usr/local/Cellar/luarocks/3.11.1/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua;./?.lua;./?/init.lua;/Users/no-vici/.luarocks/share/lua/5.1/?.lua;/Users/no-vici/.luarocks/share/lua/5.1/?/init.lua per sile rust: LUA_PATH=/usr/local/Cellar/sile/0.15.5/libexec/vendor/share/lua/5.1/?.lua;/usr/local/Cellar/sile/0.15.5/libexec/vendor/share/lua/5.1/?/init.lua;/usr/local/Cellar/sile/0.15.5/libexec/vendor/share/lua/5.1/lxp/?.lua;; per sile lua: /usr/local/opt/luajit/bin/luajit: /usr/local/Cellar/sile/0.15.5/share/sile/core/globals.lua:10: module 'pl.import_into' not found: no field package.preload['pl.import_into'] no file './sile/pl/import_into.lua' no file './sile/pl/import_into/init.lua' no file './pl/import_into.lua' no file './pl/import_into/init.lua' no file './lua_modules/share/lua/5.1/sile/pl/import_into.lua' no file './lua_modules/share/lua/5.1/sile/pl/import_into/init.lua' no file './lua_modules/share/lua/5.1/pl/import_into.lua' no file './lua_modules/share/lua/5.1/pl/import_into/init.lua' no file '=[C]/sile/pl/import_into.lua' no file '=[C]/sile/pl/import_into/init.lua' no file '=[C]/pl/import_into.lua' no file '=[C]/pl/import_into/init.lua' no file '=[C]/lua_modules/share/lua/5.1/sile/pl/import_into.lua' no file '=[C]/lua_modules/share/lua/5.1/sile/pl/import_into/init.lua' no file '=[C]/lua_modules/share/lua/5.1/pl/import_into.lua' no file '=[C]/lua_modules/share/lua/5.1/pl/import_into/init.lua' no file '/usr/local/Cellar/luarocks/3.11.1/share/lua/5.1/sile/pl/import_into.lua' no file '/usr/local/share/lua/5.1/sile/pl/import_into.lua' no file '/usr/local/share/lua/5.1/sile/pl/import_into/init.lua' no file '/usr/local/lib/lua/5.1/sile/pl/import_into.lua' no file '/usr/local/lib/lua/5.1/sile/pl/import_into/init.lua' no file '/Users/no-vici/.luarocks/share/lua/5.1/sile/pl/import_into.lua' no file '/Users/no-vici/.luarocks/share/lua/5.1/sile/pl/import_into/init.lua' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/lua-libraries/pl/import_into.lua' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/lua-libraries/pl/import_into/init.lua' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/pl/import_into.lua' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/pl/import_into/init.lua' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/lua_modules/share/lua/5.1/sile/pl/import_into.lua' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/lua_modules/share/lua/5.1/sile/pl/import_into/init.lua' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/lua_modules/share/lua/5.1/pl/import_into.lua' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/lua_modules/share/lua/5.1/pl/import_into/init.lua' no file '/usr/local/Cellar/sile/0.15.5/share/sile/lua-libraries/pl/import_into.lua' no file '/usr/local/Cellar/sile/0.15.5/share/sile/lua-libraries/pl/import_into/init.lua' no file '/usr/local/Cellar/sile/0.15.5/share/sile/pl/import_into.lua' no file '/usr/local/Cellar/sile/0.15.5/share/sile/pl/import_into/init.lua' no file '/usr/local/Cellar/sile/0.15.5/share/sile/lua_modules/share/lua/5.1/sile/pl/import_into.lua' no file '/usr/local/Cellar/sile/0.15.5/share/sile/lua_modules/share/lua/5.1/sile/pl/import_into/init.lua' no file '/usr/local/Cellar/sile/0.15.5/share/sile/lua_modules/share/lua/5.1/pl/import_into.lua' no file '/usr/local/Cellar/sile/0.15.5/share/sile/lua_modules/share/lua/5.1/pl/import_into/init.lua' no file '/usr/local/Cellar/luarocks/3.11.1/share/lua/5.1/pl/import_into.lua' no file '/usr/local/share/lua/5.1/pl/import_into.lua' no file '/usr/local/share/lua/5.1/pl/import_into/init.lua' no file '/usr/local/lib/lua/5.1/pl/import_into.lua' no file '/usr/local/lib/lua/5.1/pl/import_into/init.lua' no file '/Users/no-vici/.luarocks/share/lua/5.1/pl/import_into.lua' no file '/Users/no-vici/.luarocks/share/lua/5.1/pl/import_into/init.lua' no file './justenough/.libs/pl/import_into.so' no file './libtexpdf/.libs/pl/import_into.so' no file './sile/pl/import_into.so' no file './pl/import_into.so' no file './lua_modules/lib/lua/5.1/sile/pl/import_into.so' no file './lua_modules/lib/lua/5.1/pl/import_into.so' no file '=[C]/justenough/.libs/pl/import_into.so' no file '=[C]/libtexpdf/.libs/pl/import_into.so' no file '=[C]/sile/pl/import_into.so' no file '=[C]/pl/import_into.so' no file '=[C]/lua_modules/lib/lua/5.1/sile/pl/import_into.so' no file '=[C]/lua_modules/lib/lua/5.1/pl/import_into.so' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/justenough/.libs/pl/import_into.so' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/libtexpdf/.libs/pl/import_into.so' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/pl/import_into.so' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/lua_modules/lib/lua/5.1/sile/pl/import_into.so' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/lua_modules/lib/lua/5.1/pl/import_into.so' no file '/usr/local/Cellar/sile/0.15.5/share/sile/justenough/.libs/pl/import_into.so' no file '/usr/local/Cellar/sile/0.15.5/share/sile/libtexpdf/.libs/pl/import_into.so' no file '/usr/local/Cellar/sile/0.15.5/share/sile/pl/import_into.so' no file '/usr/local/Cellar/sile/0.15.5/share/sile/lua_modules/lib/lua/5.1/sile/pl/import_into.so' no file '/usr/local/Cellar/sile/0.15.5/share/sile/lua_modules/lib/lua/5.1/pl/import_into.so' no file '/usr/local/lib/lua/5.1/pl/import_into.so' no file '/usr/local/lib/lua/5.1/loadall.so' no file '/Users/no-vici/.luarocks/lib/lua/5.1/pl/import_into.so' no file './justenough/.libs/pl.so' no file './libtexpdf/.libs/pl.so' no file './sile/pl.so' no file './pl.so' no file './lua_modules/lib/lua/5.1/sile/pl.so' no file './lua_modules/lib/lua/5.1/pl.so' no file '=[C]/justenough/.libs/pl.so' no file '=[C]/libtexpdf/.libs/pl.so' no file '=[C]/sile/pl.so' no file '=[C]/pl.so' no file '=[C]/lua_modules/lib/lua/5.1/sile/pl.so' no file '=[C]/lua_modules/lib/lua/5.1/pl.so' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/justenough/.libs/pl.so' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/libtexpdf/.libs/pl.so' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/pl.so' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/lua_modules/lib/lua/5.1/sile/pl.so' no file '/usr/local/Cellar/sile/0.15.5/lib/sile/lua_modules/lib/lua/5.1/pl.so' no file '/usr/local/Cellar/sile/0.15.5/share/sile/justenough/.libs/pl.so' no file '/usr/local/Cellar/sile/0.15.5/share/sile/libtexpdf/.libs/pl.so' no file '/usr/local/Cellar/sile/0.15.5/share/sile/pl.so' no file '/usr/local/Cellar/sile/0.15.5/share/sile/lua_modules/lib/lua/5.1/sile/pl.so' no file '/usr/local/Cellar/sile/0.15.5/share/sile/lua_modules/lib/lua/5.1/pl.so' no file '/usr/local/lib/lua/5.1/pl.so' no file '/usr/local/lib/lua/5.1/loadall.so' no file '/Users/no-vici/.luarocks/lib/lua/5.1/pl.so' stack traceback: [C]: in function 'require' /usr/local/Cellar/sile/0.15.5/share/sile/core/globals.lua:10: in main chunk [C]: in function 'require' /usr/local/Cellar/sile/0.15.5/share/sile/core/sile.lua:8: in main chunk [C]: in function 'require' /usr/local/bin/sile-lua:24: in main chunk [C]: at 0x0108fa018b ```

This suggests to me that os.getenv() isn't even working for us in the Rust build on macOS.

The fact that it did work but also rendered the Lua build of SILE un-runnable because it no longer had access to the bulid time pseudo-system dependencies is another bug. That should either be fixed as part of this issue or opened for separate tracking here or in Homebrew.

Originally posted by @alerque in https://github.com/sile-typesetter/sile/discussions/2117#discussioncomment-10798054

alerque commented 1 week ago

After many attempts and much puzzling pulling my hair out I finally tracked this down. It turns out the issues is much simpler than what I was trying to look into and the upshot is that this is not a SILE bug, it is a Homebrew packaging issue. The Homebrew package is not giving you the original sile executable, it is giving you a wrapper script that mucks with the environment variable and then calls the sile binary.

$ which sile
/opt/homebrew/bin/sile
$ file /opt/homebrew/bin/sile
/opt/homebrew/bin/sile: Bourne-Again shell script text executable, ASCII text, with very long lines (377)
$ cat /opt/homebrew/bin/sile
#!/bin/bash
LUA_PATH="/opt/homebrew/Cellar/sile/0.15.5_1/libexec/vendor/share/lua/5.1/?.lua;/opt/homebrew/Cellar/sile/0.15.5_1/libeare/lua/5.1/?/init.lua;/opt/homebrew/Cellar/sile/0.15.5_1/libexec/vendor/share/lua/5.1/lxp/?.lua;;" LUA_CPATH="/opt/homsile/0.15.5_1/libexec/vendor/lib/lua/5.1/?.so;;" exec "/opt/homebrew/Cellar/sile/0.15.5_1/libexec/bin/sile"  "$@"
alerque commented 1 week ago

The Homebrew wrapper script is pretty easy to ditch and (unlike as of when it was first introduced) SILE works fine and doesn't need the workaround it was providing.

On the other hand just removing the wrapper doesn't fix this problem, because as soon as you try to set LUA_PATH to anything you suddenly run afoul of the original problem the wrapper script was designed to fix. Working around that from the Homebrew side would involve some real shenanigans in the wrapper script. What I'm going to propose instead is that we handle the tricky bits here upstream where it will be a bit easier and then get Homebrew to just drop the wrapper script entirely.