There are a couple of ways to develop the Materialize plugin: either using Docker and docker-compose (much simpler, but possibly slower if you're on a non-Linux OS/architecture), or outside of Docker (faster, but requires various toolchains to be installed locally).
Running docker-compose up -d
from the repository root will start up a Grafana instance with a
pre-provisioned instance of this data source pointing to a materialized instance inside Docker. It
will also start up two processes to watch the backend and frontend directory for changes,
rebuild the plugin components, and restart the backend process inside the Grafana container.
At the repository root:
-
Install dependencies
yarn install
-
Build plugin in development mode or run in watch mode
yarn dev
or
yarn watch
-
Build plugin in production mode
yarn build
Make sure you have a recent version of Rust (run rustup update stable
), and install cargo-watch
.
Then run:
cargo xtask watch
This will run the watch
task using the cargo-xtask
pattern, which rebuilds the backend component on changes, copies the binary into the correct location, and restarts the plugin process (which Grafana subsequently restarts).
You can run a Grafana instance either by cloning the Grafana repository, or running it inside Docker. See the Grafana docs for more information.
Cross compilation is generally run in CI now because it's easier to standardize, but instructions to cross-compile from MacOS to all other Grafana-supported platforms are below.
-
Install the relevant cross compiler toolchains. Using Homebrew:
brew tap messense/macos-cross-toolchains brew install armv7-unknown-linux-musleabihf brew install aarch64-unknown-linux-musl brew install x86_64-unknown-linux-musl brew install mingw-w64
-
Install the relevant Rust targets. Using
rustup
:rustup target add armv7-unknown-linux-musleabihf rustup target add aarch64-apple-darwin rustup target add x86_64-apple-darwin rustup target add aarch64-unknown-linux-musl rustup target add x86_64-unknown-linux-musl rustup target add x86_64-pc-windows-gnu
-
Run the following to compile the plugin in release mode for each target:
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER=armv7-unknown-linux-musleabihf-ld cargo build --release --target armv7-unknown-linux-musleabihf --bin grafana-materialize-datasource cargo build --release --target aarch64-apple-darwin --bin grafana-materialize-datasource cargo build --release --target x86_64-apple-darwin --bin grafana-materialize-datasource CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-unknown-linux-musl-gcc cargo build --release --target x86_64-unknown-linux-musl --bin grafana-materialize-datasource CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-unknown-linux-musl-gcc cargo build --release --target aarch64-unknown-linux-musl --bin grafana-materialize-datasource CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc cargo build --release --target x86_64-pc-windows-gnu --bin grafana-materialize-datasource