Skip to content

Commit

Permalink
Merge pull request #33 from NREL/f2-release-prep
Browse files Browse the repository at this point in the history
allow for publication on crates.io
  • Loading branch information
calbaker authored Jul 27, 2023
2 parents 243df33 + 986b633 commit 7222bb6
Show file tree
Hide file tree
Showing 20 changed files with 3,517 additions and 73 deletions.
15 changes: 8 additions & 7 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
[workspace]

members = [
"fastsim-cli", # command line app
"fastsim-core", # pure rust core with optional pyo3 feature
"fastsim-py", # python module exposing fastsim-core
"fastsim-cli", # command line app
"fastsim-core", # pure rust core with optional pyo3 feature
"fastsim-py", # python module exposing fastsim-core
"fastsim-core/fastsim-proc-macros",
]

[profile.release]
# https://deterministic.space/high-performance-rust.html
opt-level = 3 # Use better optimizations.
lto = "fat" # aggressively optimize inter-crate linking
codegen-units = 1 # optimize connection between modules
opt-level = 3 # Use better optimizations.
lto = "fat" # aggressively optimize inter-crate linking
codegen-units = 1 # optimize connection between modules

[workspace.dependencies]
anyhow = "1.0.57"
pyo3 = "0.19"
pyo3-log = "*"
serde = "1.0.143"
serde_json = "1.0.83"
serde_yaml = "0.9.22"
serde_yaml = "0.9.22"
9 changes: 7 additions & 2 deletions rust/fastsim-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
name = "fastsim-cli"
version = "0.1.0"
edition = "2021"
license-file = "../../LICENSE.md"
authors = ["NREL/MTES/CIMS/MBAP Group <fastsim@nrel.gov>"]
description = "CLI app for FASTSim models for vehicle energy usage simulation"
homepage = "https://www.nrel.gov/transportation/fastsim.html"
repository = "https://github.com/NREL/fastsim"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
fastsim-core = { path = "../fastsim-core" }
serde = {workspace = true}
serde_json = {workspace = true}
serde = { workspace = true }
serde_json = { workspace = true }
project-root = "0.2.2"
clap = { version = "3.2.6", features = ["derive"] }
regex = "1"
Expand Down
20 changes: 10 additions & 10 deletions rust/fastsim-cli/src/bin/fastsim-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ pub fn main() {
.unwrap();

#[cfg(not(windows))]
macro_rules! main_separator {
macro_rules! path_separator {
() => {
"/"
};
}

#[cfg(windows)]
macro_rules! main_separator {
macro_rules! path_separator {
() => {
r#"\"#
};
Expand All @@ -294,21 +294,21 @@ pub fn main() {
} else if is_adopt_hd {
let hd_cyc_filestring = include_str!(concat!(
"..",
main_separator!(),
path_separator!(),
"..",
main_separator!(),
path_separator!(),
"..",
main_separator!(),
path_separator!(),
"..",
main_separator!(),
path_separator!(),
"python",
main_separator!(),
path_separator!(),
"fastsim",
main_separator!(),
path_separator!(),
"resources",
main_separator!(),
path_separator!(),
"cycles",
main_separator!(),
path_separator!(),
"HHDDTCruiseSmooth.csv"
));
let cyc = if adopt_hd_has_cycle {
Expand Down
33 changes: 26 additions & 7 deletions rust/fastsim-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
[package]
name = "fastsim-core"
version = "0.1.0"
version = "0.1.2"
edition = "2021"
license-file = "../../LICENSE.md"
authors = ["NREL/MTES/CIMS/MBAP Group <fastsim@nrel.gov>"]
description = "Core FASTSim models for vehicle energy usage simulation"
homepage = "https://www.nrel.gov/transportation/fastsim.html"
readme = "../../README.md"
repository = "https://github.com/NREL/fastsim"

[dependencies]
pyo3 = { workspace = true, features = ["extension-module", "anyhow"], optional = true }
proc-macros = { package = "fastsim-proc-macros", version = "~0" }
pyo3 = { workspace = true, features = [
"extension-module",
"anyhow",
], optional = true }
anyhow = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_yaml = {workspace = true}
ndarray = { version = "0.15.4", features=["serde"] }
serde_yaml = { workspace = true }
ndarray = { version = "0.15.4", features = ["serde"] }
csv = "1.1"
proc-macros = { path = "proc-macros" }
serde_json = "1.0.81"
bincode = "1.3.3"
log = "0.4.17"
polynomial = "0.2.4"
argmin = "0.7.0"
argmin-math = { version = "0.2.1", features = ["ndarray_latest-nolinalg-serde"] }
argmin-math = { version = "0.2.1", features = [
"ndarray_latest-nolinalg-serde",
] }
validator = { version = "0.16", features = ["derive"] }
lazy_static = "1.4.0"
regex = "1.7.1"

[package.metadata]
include = [
"resources/longparams.json",
"resources/udds.csv",
"resources/hwfet.csv",
"build.rs",
]

[package.metadata.docs.rs]
rustdoc-args = [ "--html-in-header", "./src/html/docs-header.html" ]
rustdoc-args = ["--html-in-header", "./src/html/docs-header.html"]

[features]
pyo3 = ["dep:pyo3"]
68 changes: 68 additions & 0 deletions rust/fastsim-core/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//! Ensures that files that are duplicated in Python resources folder
//! and locally in this crate are identical
use std::env;
use std::fs;
use std::path::PathBuf;

fn main() {
// path when running `cargo publish` in fastsim-core/
let publish_path = "../../../../python/fastsim/resources".to_string();
// path when building using build_and_test.sh
let build_path = "../../python/fastsim/resources".to_string();

let prepath: String = match PathBuf::from(publish_path.clone()).exists() {
true => publish_path,
false => build_path,
};

if !PathBuf::from(prepath.clone()).exists() {
// no need for further checks since this indicates that it's
// likely that python fastsim is not available and thus
// fastsim-core is likely being compiled as a dependency
return;
}

let truth_files = [
format!(
"{}/{}/longparams.json",
env::current_dir().unwrap().as_os_str().to_str().unwrap(),
prepath
),
format!(
"{}/{}/cycles/udds.csv",
env::current_dir().unwrap().as_os_str().to_str().unwrap(),
prepath
),
format!(
"{}/{}/cycles/hwfet.csv",
env::current_dir().unwrap().as_os_str().to_str().unwrap(),
prepath
),
];

let compare_files = [
format!(
"{}/resources/longparams.json",
env::current_dir().unwrap().as_os_str().to_str().unwrap()
),
format!(
"{}/resources/udds.csv",
env::current_dir().unwrap().as_os_str().to_str().unwrap()
),
format!(
"{}/resources/hwfet.csv",
env::current_dir().unwrap().as_os_str().to_str().unwrap()
),
];

for (tf, cf) in truth_files.iter().zip(compare_files) {
let tfc = fs::read_to_string(tf).unwrap_or_else(|_| panic!("{tf} does not exist."));

let cfc = fs::read_to_string(cf.clone()).unwrap_or_else(|_| panic!("{cf} does not exist."));

if tfc != cfc {
panic!("Reference file {tf} does not match file being compared: {cf}. Copy {tf} to {cf} to fix this.")
}
}
}
File renamed without changes.
22 changes: 22 additions & 0 deletions rust/fastsim-core/fastsim-proc-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
authors = ["NREL/MTES/CIMS/MBAP Group <fastsim@nrel.gov>"]
name = "fastsim-proc-macros"
version = "0.1.2"
edition = "2021"
license-file = "../../../LICENSE.md"
readme = "../../../README.md"
description = "Procedural macros for FASTSim"
homepage = "https://www.nrel.gov/transportation/fastsim.html"
repository = "https://github.com/NREL/fastsim"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
proc-macro-error = "1.0.4"
proc-macro2 = "1.0.37"
quote = "1.0.18"
regex = "1.6.0"
syn = { version = "1.0.92", features = ["full"] }

[lib]
proc-macro = true
File renamed without changes.
17 changes: 0 additions & 17 deletions rust/fastsim-core/proc-macros/Cargo.toml

This file was deleted.

Loading

0 comments on commit 7222bb6

Please sign in to comment.