I've been busy over the last few weeks rearchitecting the internals of graphics.gd (Go + Godot), with the goal of bringing web support up to scratch, as well as making it easier to develop projects for Android. I'm pleased to report that this is looking to be a success!
Web
Here's the command that will launch the current graphics.gd project in your web browser:
$ GOOS=web gd run
Once the build is complete, you can then open the localhost URL printed to the console to visit the exported page.
Here's the shader sample running in the browser, showcasing simple shaders written in Go, these are compiled to WASM, which generates a .gdshader at runtime which is translated by Godot to WebGL GLSL 🤯
Click the image to see it running in your browser!
Behind the Scenes
Supporting web has actually been quite the challenge! One might think that since both Godot and GDExtension already support web exports, it would be as easy as compiling Go to WASM and calling it day. It's not that simple! GDExtension has only been designed with Emscripten's non-standard dynamic-linking in mind (Emscripten is a C/C++ to WASM compiler). This works for C++ and Rust which both support Emscripten but not for Go which has it's own builtin compiler for WASM with entirely different calling convention and Javascript runtime.
What this means in practice, is that I've had to develop an entirely new way to interface with the GDExtension API on web through Javascript. Initially as a proof-of-concept, I modified the Godot engine to export all the gdextension functions using Emscripten's binding mechanism, then partially linking to this with an entirely separate backend forgraphics.gd. The GDExtension interface is actually quite big and there was a lot of hand-crafted code here. This meant that projects often didn't work at all and would run into difficult-to-debug crashes as I had to maintain two largely separate GDExtension backends. My recent work has been to consolidate both native and web backends into a single .c file that is shared between both native builds and web builds.
This is fantastic, as now both targets are running mostly equivalent code paths, any fixes for one target, should benefit both! This also opens the door to Hot Reloading support and eventually (and easily) calling directly from Go WASM to Godot WASM without a Javascript bridge. All the samples are now running on web, including the partially completed Go port of GDQuest's third-person-controller example. Woohoo! 🎉
Android
Here's the thing, I've always had a rough time developing anything for Android, it's always a complete mess of agreeing to terms of service, downloading random SDKs, configuring everything to work... and don't get me started on Android Studio!
Probably the best experience I had was at my first Godot game jam, after I managed to install the SDK, I could just deploy any GDScript-based projects and run them on my device connected by USB, brilliant!
I wanted to capture this very experience when writing native applications for android with graphics.gd, so I am very excited to share the official process for developing an Android app with graphics.gd (Go + Godot) and Godot export templates installed:
- Plug in your Android device via a USB cable (with developer mode on).
- Run
GOOS=android gd run. - The app launches on your device.
That's it... That's the entire process!
You don't have to agree to anything, you don't need Java (at all), nor do you need to hunt down the Android SDK/NDK. You'll have an entirely native Android app running on your device. 🎉
After following these steps, here's the Go shader sample running natively on my phone:
Behind the Scenes
Go already supports GOOS=android but cross-compiling with cgo can be a challenge.. Fortunately graphics.gd bundles the minimum set of headers necessary to compile for Android and uses zig to build the native library. This works on any host machine! Godot then fills in the template .apk with the Go shared library and the gd command downloads standalone Open Source builds of apksigner and adb to sign the resulting .apk and launch it on the device.
Windows/MacOS/Linux
Don't forget, just like Godot, graphics.gd already supports natively exporting to Windows/MacOS/Linux on any machine:
GOOS=macos gd build
GOOS=windows gd build
GOOS=linux gd build
This wouldn't be possible without all the amazing work by the Zig Foundation, so do go and support them!
Disclaimer
There's a lot of different system configurations out there (I only have limited access to each platform), if you don't have the same plug and play experience, please open an issue, the goal here is to build native graphical applications for any major platform on any machine at any time - with a single command!
Thanks!
I want to thank all of the users who've had the patience and care to report the issues they've encountered with graphics.gd, I know it's been a bit of a bumpy road working through this latest internal rearchitecture, special thanks to everyone who has contributed funding to the project, which now sits at a total of $284.69NZD! The website and documentation pages are now being speedily hosted on a CDN and if you haven't had a chance to check them out yet, they have been substantially improved to provide a better introductory experience to the project.
I hope the project continues to meet your needs!
@ring-c @nii236 @mdevnull @sanikoyes @skilletfun @McMelonTV @mikolbeckwith @jonatandorozco
