Mercerenies / gdlisp

Lisp on the Godot platform
GNU General Public License v3.0
140 stars 1 forks source link

Suggestion: Extract classes from the actual godot binary #81

Closed turbohz closed 2 years ago

turbohz commented 2 years ago

Hi,

We've had trouble running the compiler and tests on our custom build of Godot.

Details

The Godot engine build script has some switches to skip features, and we strip support for mp3, vorbis, webm, and other media formats..., VR and AR, etc.

When I ran rake test, I got plenty of errors, and realized that those that broke were testing this classes we had stripped. Not only the tests were broken, the compiler failed no matter if I used those (Perhaps GDLisp.lisp is generated with that class list?)

Then I found how those classes are kind of hardcoded in src/gdscript/library/classes.rs. Reading the comments, it seems they have been put together using the Godot docs.

Solution?

I discovered this command that spits the whole godot API, and I think it could be useful to auto-generate that list:

godot --quiet --gdnative-generate-json-api api.json

This spits a very large json with all classes and methods ("primitive" types are not included).

Now with some massaging, with:

cat api.json | zq -Z 'over this => (yield this.name) | where !grep(_*) | collect(this) | yield this.collect' -

The same could be done with jq or perhaps directly from rust.

One can get a nice json array of classnames.

Suggestion

Allow to build gdlisp with any Godot build by extracting the class list from the installed binary.

In any case, I think the API export trick would be useful to you.

Keep up the good work!

turbohz commented 2 years ago

Apparently, I was wrong: The GDLisp.lisp file seems to be entirely manually put together.

Anyway, I think the api export can be useful.

EDIT: I can see that GDLisp.lisp contains also many constants that could be machine generated from the api export json.

Mercerenies commented 2 years ago

This is very helpful! Thank you! You're right that a lot of the Godot class names are hard-coded based on the online API docs, so I'll definitely want to incorporate those generating commands you suggested into GDLisp.

Mercerenies commented 2 years ago

@turbohz Thanks again for the suggestion! As of e66642f7c18e1a4f558e1e71ea09ef6c0e25f339, all of the class names and constant names in GDLisp are bootstrapped from --gdnative-generate-json-api, which, in addition to adding support for minimalist builds like yours, also makes it easier to transition between different versions of Godot 3.x.

I've run the entire GDLisp test suite against a Godot 3.5 headless build whose only enabled modules were: GDScript, GDNative, Freetype, 3D, and Advanced GUI, and that build is now in our CI pipeline.

I'm going to close this now. If you still struggle to run the test suite, feel free to reopen or reach out and share your exact build configuration, and I'm sure we can figure something out. Cheers! :)

turbohz commented 2 years ago

Awesome! Glad to be of help.

Keep up the good work.