Issues With C# Preprocessor Defines
Your Godot version: ~~4.2~~ 4.4
Issue description: The wiki page on conditional compilation for C# has a number of issues:
- ~~It says
GODOT_SERVERis defined for dedicated server exports, but it's never defined.~~ - ~~It says
GODOT_64orGODOT_32is defined in the editor and exports, but they're never defined.~~ - It says
GODOT_PCis defined only when exporting, but it's also defined in the editor. - It says the platform defines are "created from the
get_name()method of the OS singleton" which is not true, asget_name()values have different casing, separate Linux and BSD, and uses "Web" rather than HTML5.
Additionally, there are some design problems:
- No guarantee that the names won't change in the future.
- Duplicate definitions such as
GODOT_MACOS/GODOT_OSX,GODOT_WEB/GODOT_HTML5. - ~~
GODOT_32andGODOT_64are ambiguous between the OS architecture and the floating point accuracy.~~
There's no clear consensus on determining which export the game is running on, so I suggest a dedicated wiki page is created for this purpose.
URL to the documentation page: https://docs.godotengine.org/en/stable/tutorials/scripting/c_sharp/c_sharp_features.html
GODOT_32 and GODOT_64 were removed in 4.0 as per https://github.com/godotengine/godot-docs/pull/10846.
- Duplicate definitions such as
GODOT_MACOS/GODOT_OSX,GODOT_WEB/GODOT_HTML5.
We can't remove any of these without breaking existing projects, but we should deprecate GODOT_OSX and GODOT_HTML5 if possible (as these are the 3.x platform names).
@raulsntos Does C# have a way to mark defines as deprecated?
GODOT_SERVER was also removed in 4.0 and from the documentation in https://github.com/godotengine/godot-docs/pull/9793.
As mentioned by @Calinou, removing GODOT_HTML5 and GODOT_OSX from the SDK would break compatibility, but we can remove them from the documentation. We did that for GODOT_HTML5 in https://github.com/godotengine/godot-docs/pull/9793.
I wonder how many users actually rely on the preprocessor defines. For checking the platform it'd be preferable to use the OperatingSystem.Is* APIs which have better tooling support and the trimmer can remove unused code (although we technically don't support trimming yet).
Does C# have a way to mark defines as deprecated?
No, but we can remove them from the documentation as mentioned above.
Besides that, there are other points that are still valid:
It says
GODOT_PCis defined only when exporting, but it's also defined in the editor.
This is true, but the C# editor only supports desktop platforms anyway, so that may be why the documentation mentions these defines with emphasis on exporting. It was probably not intended to say GODOT_PC is only available when exporting, but it may not be relevant to mention it's also available in the editor.
It says the platform defines are "created from the
get_name()method of the OS singleton" which is not true, asget_name()values have different casing, separate Linux and BSD, and uses "Web" rather than HTML5.
I think this may be outdated documentation from when we used to generate these defines from the Godot features in 3.x. But we no longer do that (not even in 3.x).
No guarantee that the names won't change in the future.
As mentioned above, we no longer generate the platform defines so we can guarantee they won't change and we have no plans of changing/removing them.
To track the resolved issues:
GODOT_32&GODOT_64&GODOT_SERVER&GODOT_HTML5have been removed from the documentation.- The pre-processor names can now be guaranteed not to change (but this is not reflected in the documentation).
Remaining issues:
- The documentation incorrectly states that pre-processor names are created from
OS.get_name(). - The documentation still mentions
GODOT_OSXdespite being superseded byGODOT_MACOS. - The documentation is incorrect/unclear about which pre-processor names only exist when exporting and not in the editor.