Native Multiplatforming - Android + Web #177
Replies: 6 comments 12 replies
-
|
Thanks for your incredible work @Splizard, and giving us gophers a fighting chance in the world of game development! |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for putting this out there it really feels like you’ve given developers everywhere a shot at keeping up in a world that moves insanely fast. Makes the community stronger and the journey a lot less frustrating. |
Beta Was this translation helpful? Give feedback.
-
|
Hey, quick question. I have tried examples from samples and samples-web branch but they fail for me. terminal from the run command: errors I see in web console |
Beta Was this translation helpful? Give feedback.
-
|
I recently tried to run my project and one of the
Maybe the CI could run an android build of one of the samples in the future so that one can be certain that issues like these are related to the local system setup? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
The workflow to build for web is very convenient thanks to the prebuilt export template that is automatically downloaded from your server by the gd tool, which is great. I was wondering if there is some documentation on how to build it from source? |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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.gdproject in your web browser:$
GOOS=web gd runOnce 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
.gdshaderat 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 for
graphics.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 withgraphics.gd(Go + Godot) and Godot export templates installed:GOOS=android gd run.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=androidbut cross-compiling withcgocan be a challenge.. Fortunatelygraphics.gdbundles the minimum set of headers necessary to compile for Android and useszigto build the native library. This works on any host machine! Godot then fills in the template.apkwith the Go shared library and thegdcommand downloads standalone Open Source builds ofapksignerandadbto sign the resulting.apkand launch it on the device.Windows/MacOS/Linux
Don't forget, just like Godot,
graphics.gdalready supports natively exporting to Windows/MacOS/Linux on any machine:GOOS=macos gd buildGOOS=windows gd buildGOOS=linux gd buildThis 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
Beta Was this translation helpful? Give feedback.
All reactions