-
Notifications
You must be signed in to change notification settings - Fork 75
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
Have a guide for Wasm compilation #259
Comments
Seems correct, but I have to check because in one hand, I never have used |
ok. edit the draft as you find convenient and use the tools you find more helpful for the task; if you think it can be easier to use the tools you mentioned, add them as alternatives maybe. |
Have a brief guide that describe how Frontend developers can easily compile and load
smartcore
in the browser, with a simple example:This example has been generated with ChatGPT, please @morenol take a look if the procedure is correct and works as expected.
Example
How frontend developers can compile and load the smartcore library in the browser using WebAssembly, along with a simple example of running k-means algorithm in the browser.
Step 1: Install Rustup
Rustup is the recommended toolchain manager for Rust programming language. You can install it by following the instructions at https://rustup.rs/. Rustup provides easy management of Rust compiler and associated tools. Install the Rust toolchain target
wasm32-unknown-unknown
to compile to WebAssembly.Step 2: Create a Project with SmartCore
After installing Rustup, you can create a new Rust project that uses smartcore library as a dependency. You can do this by running the following command in your terminal:
This will create a new Rust project with the name
my_smartcore_project
.Step 3: Compile SmartCore into a WebAssembly Package
Inside your my_smartcore_project directory, you can now add smartcore as a dependency in your
Cargo.toml
file:Next, you can build smartcore as a WebAssembly package by running the following command in your terminal:
This will compile smartcore into a WebAssembly package with the target wasm32-unknown-unknown and the release mode for optimization.
Step 4: Create Bindings in JS
After building smartcore as a WebAssembly package, you need to create bindings in JavaScript to interact with it from the browser. You can use a tool like wasm-bindgen to generate the bindings. Install wasm-bindgen by running the following command:
Then, generate the bindings by running the following command:
wasm-bindgen target/wasm32-unknown-unknown/release/my_smartcore_project.wasm --out-dir .
This will generate a JavaScript file with the bindings in the current directory.
Step 5: Run K-Means in the Browser
Now that you have the bindings, you can load the WebAssembly package and run k-means algorithm in the browser. Here's an example using a simple HTML file and JavaScript:
The text was updated successfully, but these errors were encountered: