-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
Add support for WASM target #124
Comments
Not that I have tested it in any way, but did you try doing what it suggested?
|
Yes, I have but unsuccessfully. ( I also posted in the user group, in January) log dump
|
I see. Well, the current build process is targeted at using OpenCV as a native shared library which is not supported in wasm environment obviously. I do have plans to explore this direction though and any help is greatly appreciated! |
I have a simple example of how to build OpenCV into Emscripten target, but still not sure how to "glue" it properly with "rustc". https://github.com/Horki/lanelines_wasm_emscripten/blob/master/BUILD.md |
Hi @Horki @twistedfall I am also insterested in this topic. I have a bit of experience with Emscripten, and yes probably is required to link the OpenCV static libs compiled with Emscripten in the final stage of the project. I would try to dig into this, but i feel as an absolute beginner (almost) with Rust. 😢 |
Hi, well, this task is up for grabs if you feel like it. I've done a preliminary investigation and it's not an easy deal. You would need to have some javascript glue to link wasm from opencv crate with wasm from OpenCV lib. Then there is also question of mapping the data structs between them. It's a good investigative task, but not something you would do in a week. |
@twistedfall does problem solved? I tried to build my app with wasm-pack and have similar errors |
Nope, no real work has been done in that direction yet as far as I know. |
Hi @twistedfall back on this. Have you a reference example for this? Not with opencv-rust but another project that used the approach you explained. Thank you. |
Not really, I don’t think something like this has ever been done to be honest. |
Alternatively it may be possible to build OpenCV as static wasm and link it directly to the Rust wasm binary. As far as I know this will imply going around the standard OpenCV wasm build procedure and writing your own build script. |
i did already for wasm-ar project by @EdwardLu2018 see this build script https://github.com/webarkit/opencv-em it build the opencv static libs with WASM emscripten. But how can i link the static libs in Rust? |
That's a good start, I didn't realize it existed! It might be way simpler to go this way. For now I'm not sure how do you statically link another wasm library. There are some hits on google like https://users.rust-lang.org/t/how-to-static-link-c-lib-to-wasm/36558 so it seems to be doable. |
That article is a good example i think, I will try a similar approach. Thank you @twistedfall ! |
I would prefer to keep it open as a todo item if you don’t mind |
Would be nice to have wasm target added |
Is there any work being done for this? It seems to compile fine but the linker fails |
Not at the moment unfortunately. Linking is the main problem indeed. |
I was able to successfully build this repo. It was for the Following the build instructions for opencv for wasm with the # check the install dir for the list of libs built
export OPENCV_LINK_LIBS=opencv_calib3d,opencv_core,opencv_dnn,opencv_features2d,opencv_flann,opencv_imgproc,opencv_objdetect,opencv_photo,opencv_video
export OPENCV_LINK_PATHS=/path/to/install/lib/
export OPENCV_INCLUDE_PATHS=/path/to/install/include/opencv4/
export OPENCV_LINKAGE=static
cargo build --target=wasm32-unknown-emscripten You can also set these values in I don't know if its actually usable though, since |
That's great news! I will try to reproduce it, thank you for sharing!
Still, it's a step in the right direction |
Hello, @mattangus ,Thanks for sharing your method. I tried using it, but I see the following get the warnings:
and then the linking fails with
I used the following command to run the script
I also checked what these object files are:
These seem to be wasm modules.. But then why the linker is complaining.. Any help will be appreciated. |
@CeNiEi That seems to work for me. Check the build logs (
|
@CeNiEi Probably you should avoid to build opencv with extra modules as you can see from @mattangus instructions there are only a set of limited opencv libs |
@mattangus @kalwalt |
Before reporting an issue please first check the
troubleshooting guide. If
the issue you're encountering is not solved thereby please state the following in your bugreport:
5.6.10-arch1-1 GNU/Linux
via "packer" manager
4.3.0
Version
rustc 1.43.0 (4fb7144ed 2020-04-20)
Target
wasm32-unknown-unknown
CLI
cargo +stable build --release --target=wasm32-unknown-unknown
I didn't succeed to find a way of working OpenCV (rust+wasm) example on internet, is there a way to build it properly?
PS. Trivia I would like to rewrite my simple app from C++ intro rust
The text was updated successfully, but these errors were encountered: