mgba-emu / mgba

mGBA Game Boy Advance Emulator
https://mgba.io/
Mozilla Public License 2.0
5.59k stars 769 forks source link

Unable to Compile Python Bindings (Linux) #2057

Open phoneticsushi opened 3 years ago

phoneticsushi commented 3 years ago

I'm having multiple issues compiling the Python Bindings:

My setup:

First Attempt:

Second Attempt:

Third Attempt:

tl;dr:

I've tried this entire process on both of the following commits with the same effect:

Is there some setting/documentation I've missed? Happy to try alternate configurations/post full output if that would be helpful in troubleshooting.

endrift commented 3 years ago

That's...not how you're supposed to change those settings, but that shouldn't matter here.

That said, it looks like you're definitely missing something but I have no idea what. I've never seen problems like this. Your second attempt looks closer to what you're supposed to do than the first, but still...

endrift commented 3 years ago

Following these steps inside a docker container based on the bionic image seems to work (when started with --user root):

# apt update && apt install libpython3-dev python3-venv
# su - mgba
$ bash
$ mkdir -p ~/src/build-bionic
$ cd ~/src/build-bionic
$ python3 -m venv venv
$ . ./venv/bin/activate
$ pip install cffi pytest-runner cached-property
$ cmake .. -DBUILD_PYTHON=ON
$ make

That's not really documented but the bindings aren't particularly supported at the moment and the virtualenv probably isn't needed, but this was what I tried.

phoneticsushi commented 3 years ago

First, thank you for getting back to me so quickly. Second, could you tell me the recommended way to change those settings? Figured there was a proper way to do so but didn't see it in the documentation - that may resolve the entire issue.

In the meantime, I'll try the steps you posted above within the Docker container on my end and report back shortly.

endrift commented 3 years ago

The proper way is what I did here: -D[setting name]=[value]. That's just how to use CMake from the command line. You can't do that directly to the Docker command (you need to pass it through an environment variable) but given the image doesn't have Python installed anyway that doesn't hugely affect that command anyway.

phoneticsushi commented 3 years ago

Apologies for the delay - first time using Docker.

That builds all targets without error, including mgba-pylib and mgba-py, but doesn't generate a setup.py file as described here.

Is this the expected output?

(venv) mgba@353894b8533f: ~/src/build-bionic$ ls python/ CMakeFiles CTestTestfile.cmake Makefile cmake_install.cmake lib.c lib.linux-x86_64-3.6 libmgba-pylib.a temp.linux-x86_64-3.6 (venv) mgba@353894b8533f: ~/src/build-bionic$ find . -name "setup.py" (venv) mgba@353894b8533f: ~/src/build-bionic$

endrift commented 3 years ago

Yes, it's a bit complicated, unfortunately. If you want to install it into the virtualenv you should use make mgba-py-install, though that does seem to be broken right now. I suppose I'm curious what your use case for the bindings is, because it might not currently be supported.

phoneticsushi commented 3 years ago

The goal is to be able to replace the soundtrack of a Game Boy (Color) game while it's being played. Put another way, a playable version of what's shown in this video (incidentally, the inspiration for the project - would highly recommend this album in particular; the composer's orchestration is amazing).

To accomplish that goal, would need to be able to do the following:

Setting breakpoints and receiving callbacks on them would be ideal, but I'm not above polling the emulated PC on every step so long as I can read the registers.

Planning to publish a playable toy example to GitHub when it works. Might eventually become a framework for replacing game music in arbitrary games/platforms somewhere in the far future... but first things first.

endrift commented 3 years ago

These bindings cannot interact with the existing Qt frontend at this point, so I'm not sure you'll be able to do what you want.

phoneticsushi commented 3 years ago

If you say it can't be done (yet), I believe you 100%. Confused by that description though - seeing the functions raw_read and raw_write in the MemoryView as well as set_breakpoint and add_callback in the NativeDebugger, I was under the impression that the bindings would interact directly with emulated state in the Core, which would be controlled/rendered separately in other threads by Qt/SDL (e.g.).

Is this sort of thing possible/intended via C/C++, and the Python bindings are WIP, or do I just completely misunderstand the application's architecture? Assuming it's the last of those

endrift commented 3 years ago

The problem is that the bindings are mostly useful for running the core directly, not as part of the existing frontends. You can load scripts in the SDL frontend (maybe, I'm not sure how well that works), but you absolutely cannot do it in the Qt frontend yet. The bindings are very WIP and are likely to change dramatically in the future.

phoneticsushi commented 3 years ago

Quite understandable and thanks for answering all my questions. Please let me know if you'd like any help on that front - can't promise anything of course but would love to contribute if possible.

Feel free to close this ticket or leave it open as a reminder to look at the mgba-py-install target at some point.

I hope this thread is useful to anyone else who encounters the project looking for Python bindings.