mogenson/lua-macos-app

LuaJIT could actually be multi-arch somewhat easily

awilfox opened this issue · 5 comments

As far as I know there's no way to build luajit as a universal binary since it includes hand crafted assembly.

But, maybe we could include an x86 and am64 version of luajit and detect which interpreter to call in the shebang startup script…

Apple have some documentation on this very subject. Just build the different versions you want, and then combine them using the lipo command.

Hope this info helps you!

Just to test, I did a quick build, and it seems to work fine (though I have no way to test the darwin-x86 version in the universal build, I did run the binary via rosetta).
To make things a little easier...

To cross-compile the x86 variant:
MACOSX_DEPLOYMENT_TARGET=14 make HOST_CC='clang -target arm64-apple-macos14' STATIC_CC='clang -target x86_64-apple-macos14' DYNAMIC_CC='clang -target x86_64-apple-macos14 -fPIC' TARGET_LD='clang -target x86_64-apple-macos14' TARGET_AR='ar -r'

Then simply lipo -create -output luajit-universal luajit-x86_64 luajit-arm64 as per the abovementioned docs (presuming you have luajit-x86_64 and luajit-arm64).

Here's an example build:
luajit.zip

Thanks, I'll give it a try!

Tested out your build instructions and tried the app on an M1 and Intel macbook. They both work! I updated the committed app with a universal luajit binary and added your build instructions to the readme. Thanks!

Just to note, the conclusion still needs updating.

D'oh! Thanks. I added a note about both of you in an acknowledgements section. I hope you don't mind.