Skip to content

Debian-Based NAPI-Rust Image and Container for Writing and Testing Rust Addon Modules for Node.js Applications.

License

Notifications You must be signed in to change notification settings

MongoExpUser/Debian-Based-NAPI-Rust-Addons-Wasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Debian-Based-NAPI-Rust-Addons-Wasm


Create a Debian-Based NAPI-Rust Image and Container for Writing and Testing NAPI-Rust Addon Modules for Node.js Applications.

NAPI-Rust is similar but different from NAPI C/C++ (https://nodejs.org/api/n-api.html)

NAPI-Rust is based on Rust toolchain and does not use node-gyp.

See NAPI C/C++ example: https://github.com/MongoExpUser/Shale-Reservoir-DNN-and-Drilling-Rare-Events-Graph/blob/master/test_addon.cc

DEPLOYING IMAGE

To deploy the image, follow these steps:

  1. Clone repo

    Clone the repo. The Repo contains the following files:
    (1) Dockerfile
    (2) Cargo.toml
    (3) package.json
    (4) index.js
    (5) ./src/build.rs
    (6) ./src/lib.rs
    (7) ./src/main.rs
    (8) ./src/utilities.rs

    Modify the above files as needed, or can keep the original contents to test.

  2. BUILD docker image:

    sudo docker build -t mongoexpuser/napi-rust-app:latest .

  3. RUN docker container and map local CWD to docker working directory: "/home/myapp" :

    sudo docker run -itd --name running-napi-rust-app -v "$PWD":/home/myapp --workdir=/home/myapp --privileged --restart unless-stopped mongoexpuser/napi-rust-app:latest

  4. INTERACT with container: start/restart, stop, shell into, and exit container instance, respectively:

    sudo docker start running-napi-rust-app
    sudo docker stop running-napi-rust-app
    sudo docker exec -it running-napi-rust-app bash
    exit

  5. RUN commands inside the Docker instance, to compile, re-compile, run node.js app and clean code artifacts, respectively:

    sudo docker exec -it running-napi-rust-app npm run build
    sudo docker exec -it running-napi-rust-app npm rebuild
    sudo docker exec -it running-napi-rust-app node index.js
    sudo docker exec -it running-napi-rust-app cargo clean

  6. TEST Node.js code inside the container in the CWD:

    sudo docker exec -it running-napi-rust-app node index.js

MISCELLANEOUS

Wasm:

  1. In addition, the repo contains miscellaneous sample Rust codes and steps on how to compile the codes to WASM (Web Assembly) file.
    See the link below.
    https://github.com/MongoExpUser/Debian-Based-NAPI-Rust-Addons/blob/main/wasm/sample.rs

  2. The repo also contains HTML file that uses the compiled WASM file on the Front-End (Browser).
    See the link below.
    https://github.com/MongoExpUser/Debian-Based-NAPI-Rust-Addons/blob/main/wasm/index.html

References

1 - https://github.com/napi-rs/napi-rs
2 - https://www.npmjs.com/package/@napi-rs/cli

License

Copyright © 2015 - present. MongoExpUser

Licensed under the MIT license.

About

Debian-Based NAPI-Rust Image and Container for Writing and Testing Rust Addon Modules for Node.js Applications.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published