-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Apple M1 #322
base: master
Are you sure you want to change the base?
Conversation
@touilleMan I tried to follow the steps you outlined in #297 ... but please let me know if I've made a mistake 😅 |
I have been trying to build this on my m1 mac and I am running into some issues :( The full error is below... but I think the issue is here I don't understand why it's trying to build for (venv) bash-3.2$ scons platform=osx-aarch64 CC=clang release
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
clang -o build/osx-aarch64/pythonscript/libpythonscript.dylib -m64 -L/Users/username/godot-python/build/osx-aarch64/platforms/osx-aarch64/cpython_build/lib -Wl,-rpath,'@loader_path/lib' -install_name @rpath/libpythonscript.dylib -dynamiclib build/osx-aarch64/pythonscript/pythonscript.os -lpython3.9
ld: warning: ignoring file /Users/username/godot-python/build/osx-aarch64/platforms/osx-aarch64/cpython_build/lib/libpython3.9.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
"_PyCapsule_GetName", referenced from:
___Pyx_ImportFunction in pythonscript.os
"_PyCapsule_GetPointer", referenced from:
___Pyx_ImportFunction in pythonscript.os
"_PyCapsule_IsValid", referenced from:
___Pyx_ImportFunction in pythonscript.os
"_PyDict_GetItemString", referenced from:
___Pyx_ImportFunction in pythonscript.os
"_PyErr_Format", referenced from:
___Pyx_ImportFunction in pythonscript.os
"_PyEval_InitThreads", referenced from:
_godot_gdnative_init in pythonscript.os
"_PyEval_RestoreThread", referenced from:
_godot_gdnative_terminate in pythonscript.os
"_PyEval_SaveThread", referenced from:
_godot_gdnative_init in pythonscript.os
"_PyExc_ImportError", referenced from:
___Pyx_ImportFunction in pythonscript.os
"_PyExc_TypeError", referenced from:
___Pyx_ImportFunction in pythonscript.os
"_PyImport_ImportModule", referenced from:
_godot_gdnative_init in pythonscript.os
"_PyModule_GetName", referenced from:
___Pyx_ImportFunction in pythonscript.os
"_PyObject_GetAttrString", referenced from:
___Pyx_ImportFunction in pythonscript.os
"_Py_FinalizeEx", referenced from:
_godot_gdnative_terminate in pythonscript.os
"_Py_InitializeEx", referenced from:
_godot_gdnative_init in pythonscript.os
"_Py_SetProgramName", referenced from:
_godot_gdnative_init in pythonscript.os
"_Py_SetPythonHome", referenced from:
_godot_gdnative_init in pythonscript.os
"__Py_Dealloc", referenced from:
_godot_gdnative_init in pythonscript.os
___Pyx_ImportFunction in pythonscript.os
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
scons: *** [build/osx-aarch64/pythonscript/libpythonscript.dylib] Error 1
scons: building terminated because of errors. |
I don't know anything about macos compilation, but I guess your issue is you have to pass the correct flag to clang to tell him the platform you want to build for (normally the compiler works for a single target, but I wouldn't be surprised if both aarch64 and x86_64 are available to support the generation of "fat binary" containing both code) |
I found this answer on (stack overflow)
How can I set these flags? I wasn't sure how to pass I tried adding Edit: My version is:
So it looks like it is "Apple clang" ? |
That's what I would do... maybe the space in your value is causing issue, can you try with I suggest you to have a look into [Godot build system] that should set the flag correctly ;-) |
@touilleMan Thanks for the help. I referenced the godot mac build config and added a few flags based on that setup. Godot makes a universal binary that supports either arm or x86 builds. However, I have no idea if that's possible with the python prebuilds... For now, I just let the target be specified by setting an additional Running |
hey @kara-todd, have you been able to add Python scripts successfully with this build workflow? i'm trying to test this locally but not seeing Python as an option when creating a new script. the build seems to complete successfully, but the godot output executable isn't runnable. i've tried using |
Hi @kara-todd, I'd also want to ask how is the developement of this support going, it would be nice to have it in the released version. I was trying to run this version on M1 laptop but ran into the same issue as @gabbydelforge here. Build runs without issues, but then Godot doesn't recognize Python scripts and |
Godot4 introduce heavy changes, so I'm currently doing a big rewrite of Godot-Python to support it 😄 I don't plan on releasing any new version of Godot-Python for Godot 3, so I can merge this PR as-is if you want, but won't do any support bug correction on my side (and the changes will need to be redo for the new Godot-Python for Godot4 in the future) what do you think ? |
@touilleMan Sorry. I was never able to fully test this. I got the build working using the command I posted, but I wasn't able to confirm that it worked correctly in Godot. I'm not able to circle back around and work through this right now. Based on what @jakzie2 @gabbydelforge are seeing... I'm not sure if the PR is good enough shape to merge. |
@touilleMan I'm trying to pick this back up again. :) I got a little farther this time... but there are a few things I'm not certain about.
I know you are busy working on Godot 4 updates... but is there any guidance you could provide here? I think some of the community would still appreciate the Godot 3 support for osx arm |
The line
Seems to indicate your dylib file is in the wrong path (I guess this is due to the framework folder being added in the path by something... I seem to recall this framework folder is somewhat a standard thing in macos so maybe the compiler add it to the rpath automatically....) Regarding the universal binary thing, I have absolutely no idea how this black magic works ^^ |
Godot and apple both recommend the approach of compiling for each architecture and then using the For example, Godot says to do something like: $ scons platform=osx arch=x86_64
$ scons platform=osx arch=arm64
$ lipo -create bin/godot.osx.tools.x86_64 bin/godot.osx.tools.arm64 -output bin/godot.osx.tools.universal Can we do something similar here? I am not exactly sure what the edit Actually... it looks like potentially multiple |
That's interesting !
To work, we must ensure it is possible to glue together two dylib. Then we should glue all the dylib in the project: pythonscript.so of course (the main entry point written in C), but also all the cython based libraries and all the libraries in the python distribution (so at least libpython.dylib) And then we should ensure the whole python distribution is the same between the two architectures (i.e. only the libraries we should glued together differs, so we can safely keep just one of the two distribution with the patched libraries)
No mater what, python-build-standalone doesn't support universal binary for now (we may want to open an issue on their repo btw), so I think the first step is to try to create an universal python distribution by gluing two python-build-standalone distribs. If we can do that, everything will come together easily enough I guess ;-) |
closes #297