Skip to content

Compile to wasm #946

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

Closed
mordv opened this issue Mar 22, 2025 · 5 comments
Closed

Compile to wasm #946

mordv opened this issue Mar 22, 2025 · 5 comments
Labels
question Further information is requested

Comments

@mordv
Copy link

mordv commented Mar 22, 2025

There is a closed issue: CadQuery/cadquery#1385 claiming that

we would need to compile OCP to wasm and that's not easy task

There is examples of opencascade running in browser, namely replicad. It's not as feature rich, but has much better DX.

I think the benefits of the ability to run the thing in browser are evident. Is that possible?

@gumyr gumyr added the question Further information is requested label Mar 22, 2025
@gumyr gumyr added this to the Not Gating Release 1.0.0 milestone Mar 22, 2025
@gumyr
Copy link
Owner

gumyr commented Mar 22, 2025

By "running in browser" do you mean on some other computer (i.e. not locally)? If so, who hosts this computer and how is security provided such that users can enter Python code (and import other packages) without the machine mining bitcoin?

@jdegenstein
Copy link
Collaborator

build123d also depends on OCP, and I agree with the prior comment that compiling to WASM is not trivial. replicad instead depends on OpenCascade.js which hasn't had a commit in about 2 years (possibly a dead project).

I agree that making things easier to run is a very important goal, and in some respects installing build123d and a viewer is very unapproachable for a python newcomer.

So in summary, I think this is a nice goal but is a huge project unto itself that would require more time than I am willing to devote to it.

@mordv
Copy link
Author

mordv commented Mar 22, 2025

@jdegenstein thanks for clarification! The issue I mentioned is 2y old, I was hoping something has changed in regards of compiling complexity. Can you elaborate where is it come from? Is that a compiling a wasm module or some after chore?

replicad instead depends on OpenCascade.js

They not just depend on it (install it) but instead make some custom build.

in some respects installing build123d and a viewer is very unapproachable for a python newcomer

It's ok for newcomers. After all it's python and they should get used to installing stuff (which often breaks)

The real benefit would be for the end user(the one who gets the model) and the developers of tools - look at example from replicad - it's a fully configurable, downloadable model, generated right in the browser (even params are taken from ulr). The thingiverse has customizer IFAIK it's based on OpenSCAD.

@gumyr
The 2 tendencies are clear - everything moves to the browser and (I much as I hate it) - python here to stay. Pyodide can run numerous of libs and optionally provide them a html canvas to draw on. So imagine something like py.cafe but for build123d - that'd be cool!

Given all that, the benefits go far beyond better newcomer experience - it spreads adoption and distribution significantly.

Thanks for your work and time!

@Jojain
Copy link
Contributor

Jojain commented Mar 23, 2025

The real issue is that pywrap that is used to build OCP is pretty much undocumented and a veritable pain to understand.
For the benefits of it we all agree that it would be great so questions about that.

If you have experience with build system you could try to take a look. We documented our journey here https://discord.com/channels/964330484911972403/1079454322221396008

@jsmnbom
Copy link

jsmnbom commented Mar 24, 2025

I did some experimentation with this with the eventual goal of getting build123d running in something like jupyterlite.
I gave up along the way - especially since I realized that the performance simply wouldn't make much sense. As far as I know pyodide runs 3-4 times slower than native, and webassembly itself is often 2 times slower. The opencascade kernel is not exactly fast in the first place.

But in case anyone is interested here's some info. I used the run_docker form pyodide to get a stable environement for tests. Then after cloning OCCT we can build it using something like:

cd OCCT
emcmake cmake -G Ninja . \
  -DUSE_FREETYPE=OFF \
  -DUSE_TK=OFF\
  -DBUILD_LIBRARY_TYPE=Static \
  -DBUILD_MODULE_ApplicationFramework=OFF \
  -DBUILD_MODULE_DETools=OFF \
  -DBUILD_MODULE_DataExchange=OFF \
  -DBUILD_MODULE_Draw=OFF \
  -DBUILD_MODULE_FoundationClasses=ON \
  -DBUILD_MODULE_ModelingAlgorithms=ON \
  -DBUILD_MODULE_ModelingData=ON \
  -DBUILD_MODULE_Visualization=ON
cmake --build .
cmake --build . -- install

OCP is unfortunately much harder to compile, and that is where I eventually gave up. But I did get pretty far by adding Emscripten as a new platform whereever it makes sense. Then running the first step of pywrap with pywrap -n 7 -l /usr/lib/llvm-19/lib/libclang.so parse ocp.toml tmp.pkl Emscripten. This process is extremely slow on my machine, and I ran out of patience. I suspect that to properly build it, the build process needs to exclude more files than it currently does, but it is too complicated for me to understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants