![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
canpack
Package multiple libraries into one ICP canister.
canpack
is a code generation tool which makes it easier to use Rust crates in different languages (such as Motoko) on the Internet Computer.
This project is early in development; unannounced breaking changes may occur at any point.
TODO: Gitpod URL
Ensure that the following software is installed on your system:
To create a new Motoko project, run dfx new my_project
, selecting "Motoko" for the backend and "No frontend canister" for the frontend. Once complete, run cd my_project
and open in your editor of choice.
Add a new file named canpack.json
(in the same directory as dfx.json
).
Define a Rust canister named my_project_backend_rust
in your canpack.json
file:
{
"canisters": {
"my_project_backend_rust": {
"type": "rust",
"parts": [{
"package": "canpack-example-hello",
"version": "^0.0.1"
}]
}
}
}
Next, run the following command in this directory to generate all necessary files:
npx canpack
In your dfx.json
file, configure the "dependencies"
for the Motoko canister:
{
"canisters": {
"my_project_backend": {
"dependencies": ["my_project_backend_rust"],
"main": "src/my_project_backend/main.mo",
"type": "motoko"
}
},
}
Now you can call Rust functions from Motoko using a canister import:
import Rust "canister:my_project_backend_rust";
actor {
public func hello(name: Text) : async Text {
await Rust.canpack_example_hello(name)
}
}
Run the following commands to build and deploy the dfx
project on your local machine:
dfx start --background
dfx deploy
Add Canpack support to any IC Wasm-compatible Rust crate by exporting a top-level canpack!
macro.
For example (in your lib.rs
file):
pub fn hello(name: String) -> String {
format!("Hello, {name}!")
}
#[macro_export]
macro_rules! canpack {
() => {
#[ic_cdk::query]
#[candid::candid_method(query)]
fn canpack_example_hello(name: String) -> String {
$crate::hello(name)
}
};
}
FAQs
Package multiple libraries into one ICP canister.
The npm package canpack receives a total of 8 weekly downloads. As such, canpack popularity was classified as not popular.
We found that canpack demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.