godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.75k stars 578 forks source link

Add scons with_x86_64h option on macOS #1642

Open Ivorforce opened 1 week ago

Ivorforce commented 1 week ago

This adds an x86_64h slice, which can lead to improved performance (at the cost of binary size). It will be selected automatically on all post-2013 macs, if compiled. Pre 2013 macs will use the current x86_64 slice.

See https://github.com/godotengine/godot-proposals/issues/11150 for details about this feature.

The x86_64h slice is compiled alongside the x86_64 slice and is fully and transparently compatible with x86_64 godot. Therefore, we don't need to wait for any progress on the godot front to add this feature.

❯ scons arch=x86_64 dev_build=yes with_x86_64h=yes
...

❯ lipo -info project/bin/libgdexample.macos.template_debug.framework/libgdexample.macos.template_debug
Architectures in the fat file: project/bin/libgdexample.macos.template_debug.framework/libgdexample.macos.template_debug are: x86_64 x86_64h

godot-cpp/test x86_64h-slice-option ≡
❯ GODOT=/Applications/Godot4.4-dev4.app/Contents/MacOS/Godot  ./run-tests.sh
Godot Engine v4.4.dev4.official.36e6207bb - https://godotengine.org

 ==== TESTS FINISHED ====

   PASSES: 124
   FAILURES: 0

 ******** PASSED ********

grep: repetition-operator operand invalid

Removing the slice to see if x86_64h can be selected:

godot-cpp/test x86_64h-slice-option ≡
❯ lipo -remove x86_64 project/bin/libgdexample.macos.template_debug.framework/libgdexample.macos.template_debug -output project/bin/libgdexample.macos.template_debug.framework/libgdexample.macos.template_debug

❯ lipo -info project/bin/libgdexample.macos.template_debug.framework/libgdexample.macos.template_debug
Architectures in the fat file: project/bin/libgdexample.macos.template_debug.framework/libgdexample.macos.template_debug are: x86_64h

godot-cpp/test x86_64h-slice-option ≡
❯ GODOT=/Applications/Godot4.4-dev4.app/Contents/MacOS/Godot  ./run-tests.sh
Godot Engine v4.4.dev4.official.36e6207bb - https://godotengine.org

 ==== TESTS FINISHED ====

   PASSES: 124
   FAILURES: 0

 ******** PASSED ********

grep: repetition-operator operand invalid

godot-cpp/test x86_64h-slice-option ≡
Ivorforce commented 1 week ago

It may be nice to have an option to build only for x86_64h (instead of x86_64), to kill compatibility to older macs by choice. I opted not to add that because gdextensions should probably be fully compatible to everything godot is compatible with.