opencv/platforms
Székely Gábor 6f48cb78b6
Merge pull request #25084 from EDVTAZ:emscripten-3.1.54-compat
Add compatibility with latest (3.1.54) emsdk version #25084

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake

### Details

I was following [this tutorial](https://docs.opencv.org/4.9.0/d4/da1/tutorial_js_setup.html) for building opencv with wasm target. The tutorial mentions that the last verified version of emscripten that is tested with opencv is 2.0.10, but I was curious if I could get it to work with more recent versions. I've run into a few issues with the latest version, for which fixes are included in this PR. I've found a few issues that have the same problems I encountered:

- https://github.com/opencv/opencv/issues/24620
- https://github.com/opencv/opencv/issues/20313
- https://stackoverflow.com/questions/77469603/custom-opencv-js-wasm-using-cv-matfromarray-results-in-cv-mat-is-not-a-co
- https://github.com/emscripten-core/emscripten/issues/14803
- https://github.com/opencv/opencv/issues/24572
- https://github.com/opencv/opencv/issues/19493#issuecomment-857167996

I used the docker image for building and comparing results with different emsdk versions. I tested by building with `--build_wasm` and `--build-test` flags and ran the tests in the browser. I addressed the following issues with newer versions of emscripten:

- In newer versions `EMSCRIPTEN` environemnt variable was stopped being set. I added support for deriving location based on the `EMSDK` environment variable, as suggested [here](https://github.com/emscripten-core/emscripten/issues/14803)
- In newer versions emcmake started passing `-DCMAKE...` arguments, however the opencv python script didn't know how to handle them. I added processing to the args that will forward all arguments to `cmake` that start with `-D`. I opted for this in hopes of being more futureproof, but another approach could be just ignoreing them, or explicitly forwarding them instead of matching anything starting with `-D`. These approches were suggested [here](https://github.com/opencv/opencv/issues/19493#issuecomment-855529448)
- With [version 3.1.31](https://github.com/emscripten-core/emscripten/blob/main/ChangeLog.md#3131---012623) some previously exported functions stopped being automatically exported. Because of this, `_free` and `_malloc` were no longer available and had to be explicitly exported because of breaking tests.
- With [version 3.1.42](https://github.com/emscripten-core/emscripten/compare/3.1.41...3.1.42#diff-e505aa80b2764c0197acfc9afd8179b3600f0ab5dd00ff77db01879a84515cdbL3875) the `post-js` code doesn't receive the module named as `EXPORT_NAME` anymore, but only as `moduleArg`/`Module`. This broke existing code in `helpers.js`, which was referencing exported functions through `cv.Mat`, etc. I changed all of these references to use `Module.Mat`, etc. If it is preferred, alternatively the `cv` variable could be reintroduced in `helper.js` as suggested [here](https://github.com/opencv/opencv/issues/24620)

With the above changes in place, I can successfully build and run tests with the latest emscripten/emsdk docker image (also with 2.0.10 and most of the other older tags, except for a few that contain transient issues like [this](https://github.com/emscripten-core/emscripten/issues/17700)).

This is my first time contributing to opencv, so I hope I got everything correct in this PR, but please let me know if I should change anything!
2024-02-26 10:30:56 +03:00
..
android Merge pull request #24946 from alexlyulkov:al/kotlin-tests2 2024-02-22 09:30:45 +03:00
apple Merge pull request #24136 from komakai:visionos_support 2023-12-20 15:35:10 +03:00
ios Merge pull request #24136 from komakai:visionos_support 2023-12-20 15:35:10 +03:00
js Merge pull request #25084 from EDVTAZ:emscripten-3.1.54-compat 2024-02-26 10:30:56 +03:00
linux RISC-V: updated intrin_rvv071.hpp to work with modern toolchain 2.8.0 2024-01-17 20:34:12 +03:00
maven pre: OpenCV 4.9.0 (version++). 2023-12-25 15:20:10 +03:00
osx Merge pull request #20092 from komakai:disable_swift_build 2021-05-18 17:10:51 +03:00
scripts remove unsupported unsupported unicode 2023-06-11 23:02:34 +08:00
semihosting Merge pull request #20392 from fpetrogalli:aarch64-semihosting 2021-07-21 18:46:05 +03:00
wince Support building shared libraries on WINCE. 2019-08-01 15:28:04 +02:00
winpack_dldt Merge remote-tracking branch 'upstream/3.4' into merge-3.4 2022-02-11 17:32:37 +00:00
winrt Merge pull request #20493 from abhi-bhatra:patch-1 2021-08-04 20:28:59 +03:00
readme.txt fix 4.x links 2021-12-22 13:24:30 +00:00

This folder contains toolchains and additional files that are needed for cross compilation.
For more information see introduction tutorials for target platform in documentation:
https://docs.opencv.org/4.x/df/d65/tutorial_table_of_content_introduction.html