-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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 Godot constants to Mono project builds #28786
Conversation
Note to self, or anyone else: This will have to be changed in all of the C# source files (I think?) |
No, that will require passing |
modules/mono/editor/GodotSharpTools/Project/ProjectGenerator.cs
Outdated
Show resolved
Hide resolved
Rebuilding every time is definitely not wanted. I will look into this when I have some time. |
Interesting, though it would probably be better for the API solutions to be consistent with user code. |
adb71bc
to
2667098
Compare
Keep in mind that most platforms have several 32 and 64-bit architectures, and this "bitness" distinction is not particularly meaningful. The "bits" setting used by Godot's buildsystem is a legacy parameter but should be obsoleted and replaced by the proper architecture names (x86_64, i686 or x86, armv7, arm64v8 or aarch64, etc.). |
@akien-mga Good point, but I don't think the exact architecture matters for Mono projects. Knowing if it is 32 Bit or 64 Bit is enough as the libraries one references on the target system need to be precompiled. It's just for the correct size mapping (see https://www.mono-project.com/docs/advanced/pinvoke/ for example). |
I don't see why we can't have both. A define for ARM and a define for 64-bit could be combined to detect ARM64, etc, same with OS defines. |
@aaronfranke What would be the use case for detecting ARM64 during Mono compile time? 🤔 If we want to put in all information possible, maybe we can just use the entries of the "Feature List" of the export dialog as our source of constants? Would that be an idea? For Android, we would end up with "GODOT_ANDROID, GODOT_ARM64_V8A, GODOT_ARMEABI_V7A" etc. That might actually be the easiest solution? |
Is it possible to add custom defines for an export template instance? I want to export client builds without server-side code which is in the same godot project. If this feature exists already I simply missed it otherwise this would be a good point to introduce it. |
@zEh- That's not possible yet. Would be an argument for using the export feature list as a source for defines, though... |
It does seem to make sense to use the export feature list as the source for defines. Now Godot will build using "GODOT_OSNAME" and "GODOT_32" or "GODOT_64" for bits when building from the editor. When exporting it will use the feature list to generate defines like "GODOT_ANDROID". Since you can add custom features to an export this also allows setting up custom defines. 😄 |
This adds constants to projects build via Godot Mono which allows project to conditionally react to different operating systems and 32/64 Bit architecture. Additionally .NET libraries could support multiple engines like Unity and Godot at the same time when compiled from Godot and reacting to definitions.
Changed variable and parameters from Builds should be ok. The failed build had trouble fetching some remote stuff...
|
Thanks! :) |
Minor note: This needs to be added manually to existing projects to make it work. Also, adding to a 3.1 project doesn't seem to have any bad effects when opened in 3.1. |
Does this work with custom features? I'm trying to do the same kind of thing as @zEh-, but I haven't been able to get anything to come through that lets me distinguish between client and server builds (like adding 'Client' or 'Server' as custom features), though I do get the built-in features that show up on the export screen (GODOT, GODOT_64, GODOT_PC, etc.) I can start a new issue if need be (this could totally be something weird about my setup) but thought I'd ask for clarification here first. |
@wscalf The C# defines work with custom features in Godot 3.2.0, 3.2.1, and 3.2.2, but this was removed in Godot 3.2.3. |
Ah, I just found it. It was in the same change as adding netstandard support. All right, I have more questions but I'll open a separate thread. Thanks! |
This adds constants to projects build via Godot Mono which allows project to conditionally react to different operating systems and 32/64 Bit architecture. Additionally .NET libraries could support multiple engines like Unity and Godot at the same time when compiled from Godot and reacting to definitions.
How it works
GODOT
- Always set (is set in the actual csproj file)GODOT_REAL_T_IS_DOUBLE
- Set, if Godot was compiled withREAL_T_IS_DOUBLE
being definedWhen building from the edito, the OS defines are created using OS::get_singleton()->get_name().to_upper() so you can find all possible OS defines on the official documentation:
GODOT_WINDOWS
- Godot running on WindowsGODOT_X11
- Godot running on X11 compatible systemGODOT_OSX
- Godot running on OSXetc.
The bitness will be defined as
GODOT_64
for 64 Bit andGODOT_32
for 32 Bit.When exporting the entries in the "Feature List" shown in the export dialog will be turned into defines. For example: "Android" will turn into "GODOT_ANDROID" and "arm64-v8a" will turn into "GODOT_ARM64_V8A".
In C# you can write conditional code like
Important
has to be changed into
Closes #28517
Closes #27227