godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.7k stars 525 forks source link

Add hot reload support when building with GCC and CMake #1548

Closed ytnuf closed 2 weeks ago

ytnuf commented 1 month ago

This is a small continuation to PR #1330 which adds hot reloading options for CMake

However when compiling with GCC, the option -fno-gnu-unique must also be enabled to allow hot reloading. This is done in the SCons script: https://github.com/godotengine/godot-cpp/blob/9b98377a62ae456b0ee082062dbe98d1a13e7bda/tools/linux.py#L20

jpxaraujo commented 1 month ago

Even with this, it still does not work for me. Maybe i'm missing something? image

dsnopek commented 1 month ago

@jpxaraujo:

Even with this, it still does not work for me. Maybe i'm missing something?

That error is usually caused by not having HOT_RELOAD_ENABLED defined, which I think is set via calling cmake with -DGODOT_ENABLE_HOT_RELOAD.

jpxaraujo commented 1 month ago

@jpxaraujo:

Even with this, it still does not work for me. Maybe i'm missing something?

That error is usually caused by not having HOT_RELOAD_ENABLED defined, which I think is set via calling cmake with -DGODOT_ENABLE_HOT_RELOAD.

@dsnopek Thanks for the reply!

So, I added the changes in this commit, added "reloadable = true" to .gdextension and added the HOT_RELOAD_ENABLED

image

But still have the same problem ...

Drahiri commented 1 month ago

Finally made it work. @jpxaraujo for hot reloading to work you also need to include HOT_RELOAD_ENABLED and -fno-gnu-unique flag when building your shared library. Adding this worked

set_property(TARGET ${LIBRARY_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS "-D HOT_RELOAD_ENABLED -fno-gnu-unique")

Where ${LIBRARY_NAME} is name of target from add_library().

jpxaraujo commented 1 month ago

@Drahiri well, I am bit confused I think. It was already working when running a scene. But I thought it would also update the scene in the editor. It would be a game changer if we could get an automatic update for scenes in the editor.

Drahiri commented 1 month ago

It's doing exactly that. After I updated CMake to match this pull request and updated mine CMake with that line. After rebuilding shared library, editor automatically updated without that message asking if hot reloading is enabled. No need to reload whole project to see changes.

jpxaraujo commented 1 month ago

@Drahiri I followed every step, It does not work for me, don't know why. I tried in two different systems, one with a 12800h and a 3050ti with fedora and another with 5800X3D and a 6950xt with gentoo ... It only updates if I run the scene, the editor does not change for me ...

Drahiri commented 1 month ago

@jpxaraujo I've added repo with working example. Also sorry to all staff if it's turning into spam (I feel like a little).

jpxaraujo commented 1 month ago

@jpxaraujo I've added repo with working example. Also sorry to all staff if it's turning into spam (I feel like a little).

Thank you for taking your time to create an example! Hopefully it can help other people. Will test it today or tomorrow. Regarding the spam, my bad, I'm sorry for that.

ytnuf commented 1 month ago

Now using the compiler_is_gnu generator expression as suggested.