From dab3be495a71723fc88f1da0d5559ebaf684ded9 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 25 Oct 2023 16:45:06 +0800 Subject: [PATCH] Handle newer versions of Rhai in build. --- Cargo.toml | 22 +++++++++++----------- build.rs | 14 ++++++++++---- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c0fb5f2..71458f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rhai-sci" -version = "0.2.0" +version = "0.2.1" edition = "2021" authors = ["Chris McComb "] description = "Scientific computing in the Rhai scripting language" @@ -22,11 +22,11 @@ rand = ["randlib"] [dependencies] rhai = ">=1.8.0" -nalgebralib = {version = "0.32.1", optional = true, package = "nalgebra" } -polars = {version = "0.27.2", optional = true } -url = {version = "2.2.2", optional = true } -temp-file = {version = "0.1.6", optional = true } -csv-sniffer = {version = "0.3.1", optional = true } +nalgebralib = { version = "0.32.1", optional = true, package = "nalgebra" } +polars = { version = "0.27.2", optional = true } +url = { version = "2.2.2", optional = true } +temp-file = { version = "0.1.6", optional = true } +csv-sniffer = { version = "0.3.1", optional = true } minreq = { version = "2.6.0", features = ["json-using-serde", "https"], optional = true } randlib = { version = "0.8", optional = true, package = "rand" } smartstring = "1.0.1" @@ -34,11 +34,11 @@ linregress = { version = "0.5.0", optional = true } [build-dependencies] rhai = ">=1.8.0" -nalgebralib = {version = "0.32.1", optional = true, package = "nalgebra" } -polars = {version = "0.27.2", optional = true } -url = {version = "2.2.2", optional = true } -temp-file = {version = "0.1.6", optional = true } -csv-sniffer = {version = "0.3.1", optional = true } +nalgebralib = { version = "0.32.1", optional = true, package = "nalgebra" } +polars = { version = "0.27.2", optional = true } +url = { version = "2.2.2", optional = true } +temp-file = { version = "0.1.6", optional = true } +csv-sniffer = { version = "0.3.1", optional = true } minreq = { version = "2.6.0", features = ["json-using-serde", "https"], optional = true } randlib = { version = "0.8", optional = true, package = "rand" } serde_json = "1.0.82" diff --git a/build.rs b/build.rs index 30eb379..e74a767 100644 --- a/build.rs +++ b/build.rs @@ -16,6 +16,11 @@ fn main() { use std::collections::HashMap; use std::io::Write; + #[derive(Serialize, Deserialize, Debug, Clone)] + struct Metadata { + #[serde(default)] + pub functions: Vec, + } #[allow(non_snake_case)] #[derive(Serialize, Deserialize, Debug, Clone)] struct Function { @@ -40,7 +45,8 @@ fn main() { std::fs::File::create(std::env::var("OUT_DIR").unwrap() + "/rhai-sci-docs.md").unwrap(); // Make a file for tests - let mut test_file = std::fs::File::create(std::env::var("OUT_DIR").unwrap() + "/rhai-sci-tests.rs").unwrap(); + let mut test_file = + std::fs::File::create(std::env::var("OUT_DIR").unwrap() + "/rhai-sci-tests.rs").unwrap(); // Build an engine for doctests let mut engine = Engine::new(); @@ -62,12 +68,12 @@ fn main() { // Extract metadata let json_fns = engine.gen_fn_metadata_to_json(false).unwrap(); println!("{json_fns}"); - let v: HashMap> = serde_json::from_str(&json_fns).unwrap(); - for function in v["functions"].clone() { + let v: Metadata = serde_json::from_str(&json_fns).unwrap(); + for function in v.functions { println!("{:?}", function); } - let function_list = v["functions"].clone(); + let function_list = v.functions; // Write functions write!(doc_file, "\n# API\n This package provides a large variety of functions to help with scientific computing:\n").expect("Cannot write to {doc_file}");