Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The boiler plate

This Cargo project contains the dependencies needed to build a plugin for physim. physim-core provides traits and types. physim-attribute provides macros that generate the code which lets physim use the plugin. serde_json is used to parse an element’s configuration at run time. The plugin needs a build.rs script and the rustc_version crate to expose compiler information which physim checks for compatibility. Because the plugin is a dynamically loaded library, you should specify crate-type = ["dylib"].

[package]
name = "example"
edition = "2024"
authors = ["Joseph Briggs"]
license = "MIT"
repository = "https://github.com/jhb123/physim"
version = "0.1.0"

[lib]
crate-type = ["dylib"]

[dependencies]
physim-core = { git = "https://github.com/jhb123/physim" }
physim-attribute = { git = "https://github.com/jhb123/physim" }
serde_json = "1.0.140"


[build-dependencies]
rustc_version = "0.4.1"

The build.rs script should contain

build.rs
use rustc_version::version;

fn main() {
    let rustc_version = version().expect("Failed to get rustc version");
    let target =
        std::env::var("TARGET").expect("Cargo did not set TARGET (this should never happen)");
    let abi_info = format!("rustc:{}|target:{}", rustc_version, target);
    println!("cargo:rustc-env=ABI_INFO={}", abi_info);
}

Your plugin project can be laid out like this

example_plugin/
├── Cargo.toml
├── build.rs
└── src/
    └── lib.rs