godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.17k stars 98 forks source link

Generate gdextension_interface.h from a machine-readable format #9560

Open HuntJSparra opened 7 months ago

HuntJSparra commented 7 months ago

Describe the project you are working on

Language bindings with GDExtension

Describe the problem or limitation you are having in your project

Since the GDExtension interface gdextension_interface.h is not in a machine-readable format, language bindings need to create wrappers by hand.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

GDExtension would maintain a machine-readable file describing the interface that could be used to automatically generate the appropriate language wrappers.

While generating gdextension_interface.h from this file is not strictly required, it would make sense to ensure the interface description matches the actual interface.

This change may affect the generation of the deflated encoding of gdextension_interface.h stored in _gdextension_interface_data_compressed and used by GDExtensionInterfaceDump::generate_gdextension_interface_file().

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

The meaching-readable description of the GDExtension interface could be part of extension_api.json or a separate file. Similar to extension_api.json, this file should describe the data types and C functions used by the GDExtension interface.

For example:

{
  "name": "GDExtensionInterfaceGlobalGetSingleton",
  "return_type": "GDExtensionObjectPtr",
  "arguments": [
    {
      "name": "p_name",
      "type": "GDExtensionConstStringNamePtr"
    }
  ]
}

If this enhancement will not be used often, can it be worked around with a few lines of script?

No. Currently, GDExtension-based language bindings need to maintain their wrappers by hand or through tooling that can read C headers.

Is there a reason why this should be core and not an add-on in the asset library?

While this "interface description" could be maintained by a 3rd party, this is a generally useful feature for language bindings using GDExtension and seems like a natural part of documenting the GDExtension interface. Additionally, GDExtension already auto-generates a number of its files, so auto-generating gdextension_interface.h would not be out of place.

HuntJSparra commented 7 months ago

Based on #9524. @timothyqiu let me know if this captures your use case or not.

@adamscott Summarizing from the 2023-04-19 GDExtension meeting (notes).

timothyqiu commented 7 months ago

@HuntJSparra Yes it captures my use case. Thanks for making this a proper proposal :)