termux / proot-distro

An utility for managing installations of the Linux distributions in Termux.
GNU General Public License v3.0
1.84k stars 214 forks source link

[Feature]: Support Box64 for x86_64 architecture emulation (and potentially box86 for 32bit) #450

Closed ikcikoR closed 2 months ago

ikcikoR commented 2 months ago

Feature description

Box64 allows running x86_64 binaries on aarch64 systems and it's way faster than qemu. I'm not sure how difficult it would be to add support for it into proot-distro nor if it can be done on proot-distro level at all to be honest, but it'd be a great feature if it worked out. With the little knowledge I have, seeing that you can already choose between blink and qemu gives me a bit of hope that this is relatively doable? box86 also exists and could potentially be handy, but x86_64 is the biggest deal for obvious reasons.

TomJo2000 commented 2 months ago

This isn't really a problem for proot-distro to solve. Either:

#### From a packaging standpoint; Box86 was previously packaged - See: termux/termux-packages#7672 and subsequently disabled for relying heavily on Glibc internals (https://github.com/termux/termux-packages/commit/514cc2aa729f6e33c2d674eeba5c7abbf545bf82) Box64 has not been packaged so far. But has an official Termux build target in its upstream CMake file. - https://github.com/ptitSeb/box64/blob/87493a9bc9eff995680406cb56b792c4c045de95/CMakeLists.txt#L43-L45 So would presumably be fairly easy to package.
ikcikoR commented 2 months ago

You can install Box64/Box86 inside whatever distribution you are using via proot-distro

I did that in the past, but then running anything more than a single binary with it is an absolute pain in the arse.

On top of that: By default if a binary starts another binary, you can't wrap that with a script since it happens using system calls. From my research, redirecting that to an emulator binary normally requires binfmt_misc kernel feature, which is either disabled or inaccessible to users on Android devices from what I'm aware, and Proot is designed specifically to provide that feature.

Or we package them on Termux in which case that still wouldn't allow you to just take an arbitrary rootfs and run it on proot-distro through Box64.

So about that, I guess my main question (as somebody not advanced enough to fully understand Proot's code) is:

Box64/86 packaging aside, is Proot support limited to only qemu and blink, or does it implementing binfmt_misc mean that any emulator binary can be passed to Proot using a launch argument (or a script, such as this very repo) after all?

I'm saying packaging aside, because as you've mentioned Termux build target is indeed already in the upstream CMake file of Box64, and I have already succesfully complied and installed it in Termux on my phone, and packaging it should be quite simple indeed and might most likely be done in future.

As I said, I'm not advanced/experienced enough with this and proot's repo, but if my question above is correct, wouldn't adding Box64 support be theoretically as simple as just copying the functionality of PROOT_DISTRO_X64_EMULATOR=BLINK feature in proot-distro and then adjusting it slightly, providing us with something like PROOT_DISTRO_X64_EMULATOR=BOX that acts as a wrapper for a simple proot + box64 setup for running those arbitrary rootfs-es?

sylirre commented 2 months ago

does it implementing binfmt_misc mean that any emulator binary can be passed to Proot using a launch argument

Proot itself supports only QEMU. blink was modified in order to be compatible with it.