Replies: 4 comments 2 replies
-
Thanks for looking into this! I think it was worthwhile to look into, but due to the difficulties you mentioned it might be best to revisit at a later point. If we ever look into trying to compile OR-Tools to WASM again, this will be a really helpful resource to start with. Please get some well deserved rest! |
Beta Was this translation helpful? Give feedback.
-
DO NOT DO THIS. COMPILING OR-TOOLS TO WASM IS INSANELY DIFFICULT AND WILL BE IMPOSSIBLE TO MAINTAIN. PLEASE USE Rust and rs-graph. Create wasm bindings on a library that uses rs-graph as a dependency. Compiling rs-graph to wasm directly does not work. |
Beta Was this translation helpful? Give feedback.
-
(Accidentally put this comment on a different discussion previously) I got the algo to compile to wasm but after talking to Eric and @ZzRanger today, I think the consensus was to keep it in Python. Issues with using wasm
If you think about the pros and cons, the debt we’d take in heavily outweighs the benefits. |
Beta Was this translation helpful? Give feedback.
-
I also ended up looking at node-gyp thanks to Pelumi. The issue with that is we'd have to write a wrapper using NodeJS's addon API (which is in C++). It's not bad, but it's definitely harder to make and maintain than getting wasm to build. I looked into Bindings/Build: https://github.com/thekevinge/maxflow-wasm Usage: import { SimpleMaxFlow } from "./pkg/maxflow_wasm";
const smf = new SimpleMaxFlow();
const [SOURCE, SINK] = smf.add_nodes(2);
const [C1, C2] = smf.add_nodes(2);
const [R1, R2] = smf.add_nodes(2);
const test_arc = smf.add_arc_with_capacity(SOURCE, C1, 3);
smf.add_arc_with_capacity(SOURCE, C2, 3);
smf.add_arc_with_capacity(C1, R1, 1000);
smf.add_arc_with_capacity(C1, R2, 1000);
smf.add_arc_with_capacity(C2, R2, 1000);
smf.add_arc_with_capacity(R1, SINK, 3);
smf.add_arc_with_capacity(R2, SINK, 3);
const { max_flow, flow } = smf.solve_maxflow(SOURCE, SINK);
console.log(max_flow); // 6
console.log(smf.tail(test_arc)); // 0
console.log(smf.head(test_arc)); // 2 |
Beta Was this translation helpful? Give feedback.
-
Why
Issues
If there is a PR, why not just use the fork?
Trust me... I tried. For some reason, the fork only compiled the host tools such as Google's protoc to WASM.
This is what I tried:
This only produced binaries (such as tests, samples, and host tools as mentioned before, in
build/bin
). The OR-Tools library itself gets compiled to a library file (.so
or.a
, see: static vs dynamic libraries). I'm not entirely sure why it does this, but you could try looking into how the fork usesemcmake
and howemcmake
works with CMake projects.Ok fine, since it only produces WASM binaries, why not expose the bindings via sample files? If you're planning on attempting this, I would highly recommend trying this as a last resort. This method is quite janky and feels like a workaround (if it even works).
One thing that threw me way off is a Medium post, Kjartan - the creator of the fork, made.
See it here: https://12ft.io/medium.com/swlh/a-suduko-solving-serverless-endpoint-using-webassembly-and-or-tools-df9f7bb10044
This lead me to a PoC he made compiling OR-Tools to WASM: https://github.com/kjartanm/sudoku-solver
Awsome!! A working example!
Not so fast D:
How did he get the header files for OR-Tool dependencies in
deps/include
? OR-Tools does not produce these. How did he get the library files indeps/lib
? He must have copied/manually downloaded them. If his fork should work, why did he do this?We could also do this - manually build OR-Tools, copy the library files over, and download header files from its dependencies, but this would be terrible for maintainability. It would ruin the code transparency of Planner because OR-Tools would need to be built separately. You could write a script to manually copy them over, but that's even more jank.
It is definitely possible to output header files during the build. But whether it is worth a graph-only fork, understanding and modifying OR-Tools cmake files, and potentially destroying the maintainability of the validator is a question to stop and think on.
Summary
I tried
If you're going to try this. I would highly recommend reexamining the fork.
Useful links:
My findings after 14 hours. Forgive me for the typos. Gn ya'll 💤
Beta Was this translation helpful? Give feedback.
All reactions