Way forward #27
Replies: 4 comments 5 replies
-
@zalo, @Irev-Dev, @bitbybit-dev, this might be of interest to you. If you (or anyone else) have feedback or questions, please share them! 🙂. |
Beta Was this translation helpful? Give feedback.
-
@donalffons I mostly want to express appreciation. Your approach seems very well thought out and a good compromise considering. I think yml config plus docker image is a great solution. One low-priority concern I have here is the build story might be less than ideal for apps using services of the like vercel or netlify as I doubt they have the ability to run a docker image as part of the app build (I haven't checked the docs so I might be wrong). Not a big concern because the benefits of having this customisation available out weights this downside and the built files can always committed to version control or hosted separately on a CDN. |
Beta Was this translation helpful? Give feedback.
-
@donalffons Hope you don't mind. I linked to this discussion from the emscripten discord, just in case there are any Gurus that wanted to weigh in on this. |
Beta Was this translation helpful? Give feedback.
-
I started this issue over at the Emscripten repository with some benchmarks and a request for feedback. |
Beta Was this translation helpful? Give feedback.
-
WebIDL / v0.x
This was the first iteration of OpenCascade.js. The build system was mainly based on AmmoJS's build system and it was using the WebIDL syntax to generate bindings between C++ and JavaScript.
Auto-Generated Embind / v1.x
The approach of the v0.x version had some significant drawbacks, mainly:
Because of the point 1, I decided to use Embind instead of WebIDL, which resolved this issue. This also introduced the (not so pretty) syntax of having to use
_1
,_2
etc to select the respective overload. But I think completeness and correctness beats aesthetics in this case.Because of points 2 and 3, I developed a system for automatically generating the bindings. Using
libclang
(which are clang bindings for Python), the C++ code is parsed into an AST. This AST can then be traversed and several rules are used to generate the Embind bindings and typescript definitions. This worked very well to the point, that currently no manual bindings are required.These changes meant that now a large portion of OpenCascade was available from JavaScript: Probably more than 70% of OpenCascade's API (although there are certainly some bindings, which won't work, e.g. references to built-in types etc.).
Modules / v2.0.x (unreleased)
The approach of the v1.x version braught some improvements, but also more drawbacks, mainly:
To find a solution to these problems, I looked into making modularized builds of the library, as opposed to the monolithic approach of v1.x. With v2.x, a user of the library can now choose which OpenCascade modules to use when initializing the library.
Using modules improves some of the abovementioned issues. However, file sizes and instantiation times remain quite long. Therefore, I think to achieve an "optimal" result, it will be necessary to build custom versions of the library per each specific use case.
See here for some preliminary documentation.
Custom Builds / v2.1.x (unreleased)
For developing and prototyping using OpenCascade.js, I think the v2.0.x approach is a good balance between ease of use (i.e. being able to conveniently access any part of the OpenCascade API without much hassle) and speed (i.e. bundle size, startup time and memory consumption). However, the resulting builds will still not be optimal for most use cases: Most of the time, the modules will contain too much code and too many bindings, thereby "wasting" bandwitdth and resources.
To fix this issue, there must be a way to create custom builds. For those custom builds, the following information has to be provided:
For this purpose, there will be an option to generate custom builds to produce minimal / optimal builds for any specific use case. Custom builds are defined via YAML files, which contain all required information for a build. The the pre-built modules of v2.0.x are using the exact same representation as these YAML files.
To create a custom build, it should not be necessary to fork this repository. Instead, I am publishing a Docker Image, which can be pulled and then run against a YAML file to create the desired build, similarly to how Emscripten's Docker Image can be used to compile C++ projects on the Host machine.
See here for some preliminary documentation.
Full Typescript Support / v2.2.x? (unreleased)
Typescript support is currently in a beta stage. Many type definitions are missing (instead, the
any
type is used). The foundations are there, but this topic needs more attention.Improved Embind Interfaces / v2.3.x? (unreleased)
Currently, the bindings lack support for these two important use-cases
Both issues can probably resolved in a non-breaking way.
Issue 1 can be resolved with clever use of Emscripten's
val
class (and probably some C++ lambda functions to make the link).Issue 2 can also be resolved with Embind. Embind supports generating overloads by number of arguments.
This will increase the complexity in the code-generation code.
EDIT: (Memo to myself) Emscripten's
optional_override
could help to achieve these modified signatures emscripten-core/emscripten#4475Beta Was this translation helpful? Give feedback.
All reactions