Skip to content

Conversation

@brendan-duncan
Copy link
Contributor

@brendan-duncan brendan-duncan commented Oct 19, 2025

Add support for compiling cesium-native with Emscripten.

Unity Web currently uses Wasm32 so there are a number of changes to remove warnings related to compiling cesium-native as a 32-bit library. These typically were mis-matching of size_t to uint64_t, so I changed the variable types to be compatible with both 64-bit and 32-bit, to remove those warnings.

I added a CESIUM_WASM64 option to build for Wasm64, for when Unity supports it, or for any other platform that wants to build for Wasm64.

Many of the changes, including the ktx vcpkg port, came from Ashley's original PR, #1212.
See that PR for more detailed notes, Ashley wrote some very nice notes.

Building with Emscripten:
Make sure the Emscripten environment is setup with emsdk_env. Make sure ninja is in the executable path.

Setup Emsdk:

Download EMSDK: git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
emsdk install 3.1.39
emsdk activate 3.1.39

Before building, make sure the emsdk environment is set up with emsdk_env

Build and run tests:

emcmake cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug
cmake --build build-wasm --config Debug --target cesium-native-tests-data
cmake --build build --config debug --parallel
node build/CesiumNativeTests/cesium-native-tests.js

brendan-duncan and others added 30 commits August 4, 2025 11:37
# Conflicts:
#	CMakeLists.txt
# Conflicts:
#	CHANGES.md
#	Cesium3DTilesSelection/src/RasterOverlayCollection.cpp
#	CesiumRasterOverlays/include/CesiumRasterOverlays/RasterOverlayTileProvider.h
#	CesiumRasterOverlays/src/RasterOverlayTileProvider.cpp
@j9liu j9liu added this to the December 2025 Release milestone Nov 6, 2025
@kring
Copy link
Member

kring commented Nov 10, 2025

I'm going to merge this. Thanks so much for all your work on it @brendan-duncan! And @azrogers as well!

@kring kring merged commit e876c13 into CesiumGS:main Nov 10, 2025
14 checks passed
@brendan-duncan
Copy link
Contributor Author

Woot! Thanks for doing so much cleaning up!

@Jason-EXP
Copy link

Have you successfully built this in Release?

@kring
Copy link
Member

kring commented Nov 24, 2025

Possibly not recently @Jason-EXP. Is it not working for you?

@Jason-EXP
Copy link

Possibly not recently @Jason-EXP. Is it not working for you?

@kring , I tried using a clean VM and it does work. It seems my dev machine has conflicting installations that caused an issue with Release builds. (i.e. Strawberry Perl)

I have additional questions if you don't mind:

  • Do HTTP Accessors work in wasm/browser? Or do I have to delegate HTTP requests to the JS side?
  • Is it possible to build a wasm + js file from a library(static)? So far I can only make it work if it's an executable.

@kring
Copy link
Member

kring commented Nov 24, 2025

We had the same issue with Strawberry Perl's ccache on GitHub Actions for cesium-unity, @Jason-EXP. ada-url seems to be buggy in its (attempted) use of ccache. Our workaround was just to delete it:
https://github.com/brendan-duncan/cesium-unity/blob/824113a308a778e602aa81245b8e0877c49e7522/.github/workflows/build.yml#L399

Do HTTP Accessors work in wasm/browser?

Brendan wrote a custom IAssetAccessor implementation for the web in cesium-unity:
https://github.com/brendan-duncan/cesium-unity/blob/824113a308a778e602aa81245b8e0877c49e7522/native~/Shared/src/UnityAssetAccessor.cpp#L37

The one in CesiumCurl will certainly not work well (unless libcurl has a custom wasm implementation, which I'm assuming it does not).

Is it possible to build a wasm + js file from a library(static)?

I'm not sure. I'm not really an expert here. What problems are you running into when you try?

@Jason-EXP
Copy link

We had the same issue with Strawberry Perl's ccache on GitHub Actions for cesium-unity, @Jason-EXP. ada-url seems to be buggy in its (attempted) use of ccache. Our workaround was just to delete it: https://github.com/brendan-duncan/cesium-unity/blob/824113a308a778e602aa81245b8e0877c49e7522/.github/workflows/build.yml#L399

Do HTTP Accessors work in wasm/browser?

Brendan wrote a custom IAssetAccessor implementation for the web in cesium-unity: https://github.com/brendan-duncan/cesium-unity/blob/824113a308a778e602aa81245b8e0877c49e7522/native~/Shared/src/UnityAssetAccessor.cpp#L37

The one in CesiumCurl will certainly not work well (unless libcurl has a custom wasm implementation, which I'm assuming it does not).

This is a gold mine! Thanks for for this as it has the implementation I was looking for.

Is it possible to build a wasm + js file from a library(static)?

I'm not sure. I'm not really an expert here. What problems are you running into when you try?
Not an expert either but seems using CMake I can't generate a wasm build if I target a library. Maybe it's still missing some config to generate one.

Though I can successfully create one if I use emcc directly, I just have to figure out how to link Cesium libs properly along with other library dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants