scoder / lupa

Lua in Python
http://pypi.python.org/pypi/lupa
Other
1.02k stars 136 forks source link

setup.py does not build with luajit on windows(x64) #235

Open hidwood opened 1 year ago

hidwood commented 1 year ago

This issue occurs when building with the standard "setup.py build" command, as it completely skips checking and building LuaJit. It succeeds in building Lua51, Lua52, Lua53, and Lua54, and then skips both LuaJit20 and LuaJit21, despite being able to build them directly. After searching the setup.py, I found a comment that states:

Couldn't get the Windows build to work. See

        #https://luajit.org/install.html#windows
        I am unsure if this means that the setup file cannot build on windows, or if it means that it is expecting one to build it themselves. Just in case that was true, I built with "msvcbuild.bat", and reran, but nothing had changed. After more searching, it does not appear that this should be the case, as there are references to msvcbuild in the setup file. I am now at a loss and would greatly appreciate some insight into what is going on. Fixing this issue would allow for LuaJit to be distributed in the auto-generated wheels for windows, much like it already is in Linux.
MuffinMario commented 1 year ago

It seems that luajit is currently not working with windows as it is written. What worked for me was the following:

  1. Go to setup.py and comment out the previously mentioned line or (platform.startswith('win') and 'luajit' in os.path.basename(lua_bundle_path.rstrip(os.sep)))
  2. Modify the line below which is limiting luajit to only x64 arch so that it also supports windows (which for some reason says "AMD64" instead of "x64_86") to the following: or (get_machine() != "AMD64" and get_machine() != "x86_64" and 'luajit' in os.path.basename(lua_bundle_path.rstrip(os.sep)))
  3. Open your Visual Studio 20XX x64 native command prompt (or alternatively run vsvars64.bat which for 2022 is lying in C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build in cmd as powershell will not work)
  4. cd to your directory and run python setup.py build_ext -i

This will include the luajit20 and luajit21 third-party folders to also build, leaving you with lua52,lua53,lua54,luajit20 and luajit21 modules.

If you additionally want to create a distribution and such, you may also have to mass replace the hard coded absolute paths "/home/runner/work/lupa/lupa/..." to "./lupa/..."

scoder commented 1 year ago

If someone gets this to work, I'd be happy to receive a PR.

hidwood commented 1 year ago

Thank you, this appears to work. I suppose my question is then why Windows on x64 will not build unless the machine type is specifically not x64 or AMD64? One would think that it would, but I do not know enough about the wizardry that is going on to make a guess as to why it does not work by default. With the modified setup file, I was able to build successfully on Windows10 /11 and Ubuntu 22.04, both on x64. I was unable to test on a Mac, so that may or may not work. Are there any adverse effects of using this setup? Or could this possibly be integrated with a PR as it is?