Skip to content

Adding wasm support (feature) #7

@regular-citizen

Description

@regular-citizen

Hello, I'm opening this issue to discuss the option to upstream some changes we implemented to add support for HiGHS in wasm32-unkown-unknown targets.

This is a somewhat non-trivial business, but was necessary in our use case to get access to a fast LP solver from the browser. Since we have figured out how to do it, we thought we may spare someone else the trouble.

The current strategy we are using works as follows. I have a forked version of your crate (here), which intercepts the calls to highs-sys and instead runs them through wasm-bindgen to some external symbols, which are placed in the global JS scope.

We then take the highs library and compile it to C++ with emscripten. Unfortunately, this means it is ABI-incompatible with wasm32-unknown-unknown, so we cannot directly link against our main rust binaries. But we have written some light glue code that allows us to pretend we have a JS implementation of the highs-sys functionality. Thanks to the architecture of your crate, the shim is not too extensive.

The full nix derivation for buildings highs with emscripten and adding our bindings can be found here.

Overall, this works reliably in practice. There is a subtle memory corruption bug, for which we would appreciate help with debugging, but we have been successful in avoiding it by slightly padding the LP problems. Aside from this, it is pretty much done and good to be merged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions