Skip to content

Conversation

@TSnake41
Copy link

No description provided.

@TSnake41 TSnake41 changed the title Add LuaJIT for 3DS Add 3ds-luajit Apr 28, 2019
@WinterMute
Copy link
Member

WinterMute commented Apr 29, 2019

Installed files shouldn't be renamed or moved around, nor should the pkgconfig directory be deleted. The proper way to obtain cflags and libs for libraries like this is to use pkg-config rather than specifying them manually.

$ /opt/devkitpro/portlibs/3ds/bin/arm-none-eabi-pkg-config luajit --cflags
-I/opt/devkitpro/portlibs/3ds/include/luajit-2.0
$ /opt/devkitpro/portlibs/3ds/bin/arm-none-eabi-pkg-config luajit --libs
-L/opt/devkitpro/portlibs/3ds/lib -lluajit-5.1 -Wl,-E -lm -ldl

We can either supply a dummy libdl.a in a separate package or patch ./etc/luajit.pc temporarily to avoid linker errors. -Wl,-E should be patched out anyway, we're not supplying dynamic libs.

I also had some success building from top level dir rather than descending into src.

touch src/luajit src/jit/vmdef.lua
make TARGET_SYS=OTHER TARGET_T=libluajit.a  HOST_CC="gcc -m32"  XCFLAGS="-DLUAJIT_USE_SYSMALLOC" CFLAGS="" LDFLAGS="" LIBS="" HOST_CFLAGS="" HOST_LIBS="" HOST_LDFLAGS=""  CROSS=arm-none-eabi- PREFIX=${PORTLIBS_PREFIX} DESTDIR=`pwd`/test amalg install

Is there a good way to test the result?

@TSnake41
Copy link
Author

TSnake41 commented Apr 29, 2019

(I fixed a issue, I noticed that luajit was built without platform flags, so soft-abi and some other stuff, so can't link against 3ds homebrews)

We can either supply a dummy libdl.a in a separate package or patch ./etc/luajit.pc temporarily to avoid linker errors. -Wl,-E should be patched out anyway, we're not supplying dynamic libs.

A libdl library could be interesting if it dlfcn stuff works, e.g involves "modules" as structures, with minimal patching, we could build FFI with "libdl support".
Otherwise, we will have minimal FFI for embedded platforms (still capable though).

Is there a good way to test the result?

Yes, I made a LuaJIT shell for 3DS : https://gist.github.com/TSnake41/cc723ffcfc386bbc9bf91cd1475e0836
After pressing (A), it shows a prompt where you can write Lua code.
e.g print(jit.status()) checks JIT status (give true/false and JIT optimization features).

I made another shell (in Lua with FFI) that currently can't work because it needs the "libdl support" feature (that adds support to ffi.cdef stuff very useful to interact with C functions by prototypes) of FFI which is currently not supported.

@uyjulian
Copy link
Contributor

I did it without moving files around:
https://github.com/uyjulian/LuaJIT/tree/3ds
make install CROSS="arm-none-eabi-" HOST_CC="gcc -m32" TARGET_SYS=3DS DESTDIR=wherever
If you believe my changes are better, I can make a new PR with a patch

@WinterMute
Copy link
Member

@uyjulian This PR has already been updated to not move files around. I just haven't had time to test the library.

Your changes are intrusive and inappropriate, sorry.

@uyjulian
Copy link
Contributor

May I ask how this manages to get JIT working without mmap/etc implementation?

@fincs
Copy link
Member

fincs commented May 13, 2019

It doesn't. However, hacking in a questionable implementation of mmap and pthread isn't a desirable solution either.

@WinterMute
Copy link
Member

One package and only one package per PR please. Separate out the stub libdl

@TSnake41
Copy link
Author

Making a cleanup, will reopen it later.

@WinterMute
Copy link
Member

protip: use git pull --rebase rather than just a pull when attempting to sync with master. This is one of the reasons why it's a good idea to work on a feature branch rather than directly on the master branch of a fork.

@TSnake41 TSnake41 mentioned this pull request Apr 14, 2020
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

Successfully merging this pull request may close these issues.

4 participants