Pulse Engine on WebGL (Unity build)

Has anyone had success running Pulse Engine in a WebGL build (Unity), or otherwise running in a web application?

I have taken a stab at this several times, but I keep getting stuck and not knowing what to do

I first cross compile Pulse with emscripten via this dockcross container. This produces static libraries that I believe are what Unity wants.

I don’t see anything in the Unity documentation, but I believe that since these are static libraries, I have to mark the Pulse C# to Native C++ class with Internal when building for a WebGL platorm. So I changed that line to

public class PulseUnityEngine : PulseEngineBase
    private const string Attribute = "__Internal";
    private const string Attribute = "PulseC";

This is how we get iOS build support. For iOS, I also provide static libraries.

So, now when I build the Pulse VitalsMonitor scene for WebGL, the build seems to be running emscripten on the Pulse static libraries built from the docker contatiner.

But the build soon fails with

Building Library\Bee\artifacts\WebGL\build\debug_WebGL_wasm\build.js failed with output:
wasm-ld: warning: function signature mismatch: PulseHash
>>> defined as (i32) -> f64 in C:\\Users\\AARON~1.BRA\\AppData\\Local\\Temp\\tmpk80puxihGameAssembly.a(bizftqft4zrn.o)
>>> defined as (i32) -> void in C:\\Users\\AARON~1.BRA\\AppData\\Local\\Temp\\tmp9x6dm5f6PulseC.a(PulseEngineC.cpp.o)
[parse exception: attempted pop from empty stack / beyond block start boundary at 26994213 (at 0:26994213)]
Fatal: error in parsing input
emcc2: error: '"C:/Program Files/Unity/Hub/Editor/2021.3.30f1/Editor/Data/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/binaryen\bin\wasm-emscripten-finalize" --minimize-wasm-changes -g Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.wasm -o Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.wasm --detect-features' failed (1)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

It did this for a few other methods, and I just commented those methods out
I am not sure what this error is trying to tell me, and what is wrong with that method.
The method in question is:

extern "C"
C_EXPORT void C_CALL PulseHash(char** hash_str)
  std::string hash = PulseBuildInformation::Hash();
  *hash_str = c_strdup(hash.c_str(), hash.length());

Which is called from PulseUnityEngine.cs

  private static extern double PulseHash(out IntPtr version_str);

Which is not getting a double back…

Maybe I just need to clean up my interfaces…
type type type
Ok, I changed the PulseUnityEngine::PulseHash return to be void
And that got rid of that one error, but there is still other mysterious errors

I guess the next thing too google is that parse exception…

I think its becauase dockcross is on emscripen 3, and unity is using emscripten 2…

Awesome response - Thanks Aaron. I am definitely not worthy on getting this working on my own, but great base for conversation with Kitware tuesday.