MagicMirror module to access your todo-entries from Things and display them in MM. It was a learning project for me where I learnt about how to interact between Rust and Node.
The module looks like this:
- Publish version of neon-serde2 that works (neon10.1, unwrap instead of ?)
git clone https://github.com/piceaTech/MMM-rusty-things.git
cd MMM-rusty-things.git
npm install
mv example.env .env
Edit the .env
and insert your hist_id.
After that either compile the native module locally on the pi or cross-compile from your desktop.
- Build the build-Container
git clone https://github.com/piceaTech/rust-on-raspberry-docker
cd rust-on-raspberry-docker
git checkout neon
- If you need another node version than the current LTS-Version: Edit the Dockerfile and switch to correct BaseImage.
docker build --tag "neon-pi-cross:latest" .
- Copy the following dependencies as
.deb
s intonative/pi_deps
- ssl: http://ftp.debian.org/debian/pool/main/o/openssl1.0/libssl1.0-dev_1.0.2r-1~deb9u1_armhf.deb
- sqlite: http://ftp.debian.org/debian/pool/main/s/sqlite3/libsqlite3-dev_3.16.2-5+deb9u1_armhf.deb
- Inside your neon-folder run
native/build.sh
. This should create anative/index.node
which should be compatible with arm. - Deploy this artifact to the pi!
- Done
- Install cross compiler needed:
https://github.com/messense/homebrew-macos-cross-toolchains
brew tap messense/macos-cross-toolchains
brew install armv7-unknown-linux-gnueabihf
- Add rust target
rustup target add arm-unknown-linux-gnueabihf
- Copy the following dependencies as
.deb
s into/pi_deps
(Make sure the version installed on pi are the same as these downloaded versions or else errors might occur) - ssl: http://ftp.debian.org/debian/pool/main/o/openssl1.0/libssl1.0-dev_1.0.2r-1~deb9u1_armhf.deb
- sqlite: http://ftp.debian.org/debian/pool/main/s/sqlite3/libsqlite3-dev_3.27.2-3+deb10u1_armhf.deb
- gcc: http://ftp.debian.org/debian/pool/main/g/gcc-12/libgcc-12-dev_12.1.0-2_armhf.deb
- unpack all deps into folders
cd pi_deps
ar x libssl1.0-dev_1.0.2r-1_deb9u1_armhf.deb
tar -xvf data.tar.xz
ar x libsqlite3-dev_3.16.2-5+deb9u1_armhf.deb
tar -xvf data.tar.xz
ar x libgcc-12-dev_12.1.0-2_armhf.deb
tar -xvf data.tar.xz
- copy opensslconf.h into correct folder
cp usr/include/arm-linux-gnueabihf/openssl/opensslconf.h usr/include/openssl/
- run
./build-pi.sh
. This should create aindex.node
which should be compatible with arm. - Deploy this artifact to the pi!
- Done
This project was bootstrapped by create-neon.
Installing rusty-things requires a supported version of Node and Rust.
You can install the project with npm. In the project directory, run:
$ npm install
This fully installs the project, including installing any dependencies and running the build.
If you have already installed the project and only want to run the build, run:
$ npm run build
This command uses the cargo-cp-artifact utility to run the Rust build and copy the built library into ./index.node
.
In the project directory, you can run:
Installs the project, including running npm run build
.
Builds the Node addon (index.node
) from source.
Additional cargo build
arguments may be passed to npm build
and npm build-*
commands. For example, to enable a cargo feature:
npm run build -- --feature=beetle
Alias for npm build
.
Same as npm build
but, builds the module with the release
profile. Release builds will compile slower, but run faster.
Runs the unit tests by calling cargo test
. You can learn more about adding tests to your Rust code from the Rust book.
The directory structure of this project is:
rusty-things/
├── Cargo.toml
├── README.md
├── index.node
├── package.json
├── src/
| └── lib.rs
└── target/
The Cargo manifest file, which informs the cargo
command.
This file.
The Node addon—i.e., a binary Node module—generated by building the project. This is the main module for this package, as dictated by the "main"
key in package.json
.
Under the hood, a Node addon is a dynamically-linked shared object. The "build"
script produces this file by copying it from within the target/
directory, which is where the Rust build produces the shared object.
The npm manifest file, which informs the npm
command.
The directory tree containing the Rust source code for the project.
The Rust library's main module.
Binary artifacts generated by the Rust build.
To learn more about Neon, see the Neon documentation.
To learn more about Rust, see the Rust documentation.
To learn more about Node, see the Node documentation.