fmi-export
A Rust interface to FMUs (Functional Mockup Units) that follow the FMI Standard. This crate provides necessary interfaces and utilities to construct FMUs.
This crate is part of rust-fmi.
See http://www.fmi-standard.org
Quick start: Build an FMU
- Install the
cargo-fmisubcommand:
- Create a new crate for your model using
cargo-fmi:
This will generate a cdylib crate with a sample model struct deriving FmuModel:
use FmuModel;
The export_fmu! macro will generate the required FMI-API exports.
export_fmu!;
- Build and bundle the FMU with
cargo-fmi:
Building FMUs
This repository builds FMI 3.0 FMUs from pure Rust code, and is driven by the FmuModel
derive macro.
The FMI API interfacing boilerplate is generated, and automated packaging is handled by the
cargo-fmi subcommand.
Minimal FMU setup
Your FMU crate must:
- Be a
cdylib:
[]
= ["cdylib"]
- Derive
FmuModelfor your model struct - Export FMI symbols via
export_fmu!
Example skeleton:
use FmuModel;
export_fmu!;
Build an example FMU (this repo)
From the repository root:
The FMU zip is written to:
target/fmu/<model_identifier>.fmu
<model_identifier> is the Rust cdylib target name (for can-triggered-output, this is
can_triggered_output).
Common options
- Build a release FMU:
- Build for a specific target:
Building FMUs from Modelica models
Using the rumoca crate, fmi-export can generate
Rust code from Modelica models.
The template can be used directly via Rumoca, but the primary workflow is to enable
the rumoca feature in fmi-export and call its helper API from build.rs.
Quick Start
- Add
fmi-exportwith therumocafeature to yourCargo.toml:
[]
= { = "0.1.1", = ["rumoca"] }
- Invoke the Rumoca compiler in your crates'
build.rs:
let model_path = from
.join;
println!;
write_modelica_to_out_dir
.expect;
Direct Rumoca usage is also supported (path shown is for this repo checkout):
If you're outside this repo, point --template-file at a local copy of
rust-fmi.jinja from the fmi-export/templates directory.
See templates/README.md and the examples for further details.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.