'building OR-Tools for Blazor wasm

I am developing a Blazor wasm tool that relies on Google OR-Tools for some part and im running into problems building the library and using it in .NET 6 Blazor wasm by leveraging NativeFileReference.

I have been using other C++ Libraries in my application using the same approach and they build and integrate without a hiccup see Steve Sanderson Talk. but the OR-Tools has a lot of dependencies and is way more complex in structure.

my goal is to compile to a single binary which I can use and ship in my projects, where I'll write a C++ entry file that contains all the functions I need to interact with C# as in attempt no.2 below.see also Static linking section

what have I tried ? :

  1. I took a look at the Sudoku Solver, he mentions in the article that he had to iterate over the dependencies until he got a wasm build and created patches, which I'm unsure how it was achieved. but I figured I can add the suduko example to an empty Blazor wasm project for testing, changing the emcc command to generate a single bindary using - shared and -s WASM=1 and removing any Javascript use. but I got a Json parse error on linking emscripten : error : emscript: failure to parse metadata output from wasm-emscripten-finalize which appears to be a version mismatch error according to this and the dotnet doc, if I pass the sudokus.cc file I get a file not found error on headers.

  2. I referred to this question and tried to use the example as a starting point to build wasm from and simply use the main.cpp in the same fashion but in Blazor. that also didn't quite work.

my questions:

a. What is the correct way to build a wasm single binary from OR-Tools (regardless of the size) ?
b. would attempt no.2 actually work ? if so, what is additionally required to build it as is but for wasm.

Thank you!

System Information:
Ubuntu 21.10
gcc/g++ 11.2.0
dotnet 6.0.202
Emscripten 3.1.9



Solution 1:[1]

I'll leave this here for anyone else looking to use or-tools for Blazor wasm, please note that this answer is meant for question b. in original question.

In the context of keeping the Blazor App light this method is useful if you want a certain job to be executed by a specific tool in or-tools. mind you that this uses a very old version of or-tools (for the time being).

  1. install/downgrade Emscripten v2.0.23 (current version used in .NET wasm-tools)
  2. Clone kjartanm/wasm-or-tools
  3. Follow build steps under About this fork
  4. do adjustments on emcc command on entry C++ file to produce a single binary

emcc -O3
--bind
-lm
-s LLD_REPORT_UNDEFINED
-s ERROR_ON_UNDEFINED_SYMBOLS=0
-s EXPORTED_FUNCTIONS='["method_in_entry_file"]'
-I wasmbuild/install/include
-Lwasmbuild/install/lib
-lglog
-labsl_bad_any_cast_impl
-labsl_log_severity
-labsl_bad_optional_access
. . . list too long edit the command in example build shell script
/name_of_entry_file.cc
-shared -o output/path/output_name.o

  1. Include the .o file in your blazor app. see here for details

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nofal