-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix emscripten (webassembly) support #23515
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
Conversation
I will take a look at this next week |
I'm not really a huge fan of all the macro guarded code, I'm not going to get this PR blocked but we should definitely aim to better separate this so that no one has to look at essentially dead code. |
I chose this approach since I'm not familiar enough with the codebase to move anything to a general "utility" class. However, if you'd like for me to give this a shot (with some information on where things would need to go) I would take a look. I'm going to wait until this PR is approved/rejected before resolving merge conflicts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I like the changes. There's a bit of setup that needs to be improved, but the thing that worries me is how to reliably create assets and ensure we get the correct version
Emscripten docker builder is merged in OpenRCT2/openrct2-docker-build#20 now. I've taken liberty to add ccache to the builder image, emscripten should cache well |
Is there anything that you would like changed in this PR? For clarification, the reason the |
The final missing piece is the GitHub actions job that uses the new builder image |
Ah right, I do ask if you can be the one to do it, just because I'm not super familiar with the way deploys are done in this project. If you'd like me to take a shot I'll do that too |
OK, I'll probably take a look tomorrow. But it should be what you already had in the script, just executed in the container. This is a fairly concise example: OpenRCT2/.github/workflows/ci.yml Lines 545 to 560 in a935084
Note the container field, which makes github worker execute every following step inside said container.
|
I went ahead and moved the dependency import/export functions to a JavaScript library, so that anyone wanting to just use the wasm in their project doesn't need to mess with module dependencies. Forgot I could do this when initially adding these functions |
I finally got some time to do this and my branch is here: https://github.com/janisozaur/OpenRCT2/tree/refs/heads/emscripten-test with the script in question: https://github.com/janisozaur/OpenRCT2/blob/79484aff77c065e843d62d4de7e533b0310274e2/scripts/build-emscripten But I run into an issue not present in this PR:
Could you take a look? |
I'll take a look |
@janisozaur Managed to fix this. This appears to be some really stange (bug?)/issue with emscripten that seems to cause threads to not be found with certian ldflags set. I got around this by adding the variables after instead of before the pthread check |
I have pushed the script to build in CI, just need to verify if the uploaded assets work as expected. @ethanaobrien thanks a lot for sticking with us and seeing this PR until completion and sorry once again it took so long on our end. We require at least one more approval from the team member to PRs from external contributors, I've already asked folks to take a look. Some notes after testing this, which IMO can be addressed in future PR(s):
Would you be able to look into some of those? |
For anyone who'd like to test it: # cd to repository root
docker run -p 8000:8000 -v $(pwd):/openrct2 -it openrct2/openrct2-build:19-emscripten
git config --global --add safe.directory /openrct2
cd /openrct2
. scripts/setenv
build-emscripten
cd /openrct2/build/www
# you need to get assets.zip, you can download (an old) one from https://rct.ethanthesleepy.one/assets.zip or use the `data` directory from a portable build
cors_serve.py # this script is included in docker image What do you guys think of moving the data inside |
Are you saying to just return
This should be fixed now.
This should be possible. We'd need to
As a note, GitHub pages wont work (unless behind Cloudflare) You need these headers set to expose the
This should be possible and fairly simple. This library should work: https://github.com/httptoolkit/brotli-wasm
I can definitely look into some of these when I get the time. I also plan to eventually add networking support for emscripten, and I plan to fix the fullscreen option |
Pretty much, but with some counter if we change it mid-release
Some interesting discussion here: libsdl-org/SDL#7840 If I read that correctly, they suggest storing the cursor position, entering
We no longer host https://openrct2.io from github pages, but thanks for the tip. I'll see how can we host it now. |
One more comment on usability: there should some way to upload and download saves. For Endless Sky (https://play-endless-web.com/), this is how we handled it: thomasballinger/endless-web@0a1597a#diff-73b43b8cad5b4f26858d32ba065f423c6774b87cd6083ddfd5faf83e4b2f73ee |
The issue here is, unless I'm missing something, we can't alter the position of a cursor in the web browser without locking the cursor
I do also want this. At the moment there is the import/export buttons in settings which will download all saves but this is inconvenient for just wanting to download one map. I want to add a simple upload file/download file to the save/load dialogs, but couldn't figure out how to get a pointer to a save data rather than writing it to the disk. Do you know how I could go about this, since I assume you know more about how OpenRCT2 saves than I do |
@janisozaur Would you rather pull in that brotli-wasm library, rely on the server to compress and decompress it, or zip the files and rely on JSZip for decompression which is already pulled for handling of assets and saves? |
Either way is fine, can they both be pre-compressed server-side? I tested with deflate and it produces slightly larger binary, at around 4.5MB, but this is still ok. |
Yes, both the JS and WASM could be compressed together |
This PR fixes up the (broken) emscripten support, and adds a bash script that will download and compile all dependencies
Originally: #23392
You can try the demo here: https://rct.ethanthesleepy.one/
Overall changes, all having to do with emscripten:
OPENRCT2_ARCHITECTURE
define when targeting webassemblyprompt
dialog, when trying to read from stdinNO_TTF