From ecded729ad935d0812d020d17f9ac19a7bdef60c Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 18 Mar 2020 10:50:51 +0800 Subject: [PATCH] Finalize `no_std` support. --- Cargo.toml | 40 +++++++++++++++++++++------------------- README.md | 5 ++++- src/stdlib.rs | 2 ++ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 11015a39..060df2f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,27 @@ keywords = [ "scripting" ] [dependencies] num-traits = "0.2.11" +[features] +#default = ["no_function", "no_index", "no_float", "only_i32", "no_stdlib", "unchecked", "no_optimize"] +default = [ "optimize_full" ] +debug_msgs = [] # print debug messages on function registrations and calls +unchecked = [] # unchecked arithmetic +no_index = [] # no arrays and indexing +no_float = [] # no floating-point +no_function = [] # no script-defined functions +no_optimize = [] # no script optimizer +optimize_full = [] # set optimization level to Full (default is Simple) +only_i32 = [] # set INT=i32 (useful for 32-bit systems) +only_i64 = [] # set INT=i64 (default) and disable support for all other integer types + +# no standard library of utility functions +no_stdlib = [ "num-traits/libm", "hashbrown", "core-error", "libm" ] + +[profile.release] +lto = "fat" +codegen-units = 1 +#opt-level = "z" # optimize for size + [dependencies.libm] version = "0.2.1" optional = true @@ -37,22 +58,3 @@ optional = true version = "0.3.2" default-features = false optional = true - -[features] -#default = ["no_function", "no_index", "no_float", "only_i32", "no_stdlib", "unchecked", "no_optimize"] -default = [ "optimize_full" ] -debug_msgs = [] # print debug messages on function registrations and calls -unchecked = [] # unchecked arithmetic -no_stdlib = ["num-traits/libm", "hashbrown", "core-error", "libm"] # no standard library of utility functions -no_index = [] # no arrays and indexing -no_float = [] # no floating-point -no_function = [] # no script-defined functions -no_optimize = [] # no script optimizer -optimize_full = [] # set optimization level to Full (default is Simple) -only_i32 = [] # set INT=i32 (useful for 32-bit systems) -only_i64 = [] # set INT=i64 (default) and disable support for all other integer types - -[profile.release] -lto = "fat" -codegen-units = 1 -#opt-level = "z" # optimize for size diff --git a/README.md b/README.md index 5032e531..7ed77c0f 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,9 @@ Rhai - Embedded Scripting for Rust Rhai is an embedded scripting language and evaluation engine for Rust that gives a safe and easy way to add scripting to any application. -Rhai's current feature set: +Rhai's current features set: +* `no-std` support * Easy integration with Rust functions and data types, supporting getter/setter methods * Easily call a script-defined function from Rust * Fairly efficient (1 million iterations in 0.75 sec on my 5 year old laptop) @@ -52,6 +53,7 @@ Optional features | `no_optimize` | Disable the script optimizer. | | `only_i32` | Set the system integer type to `i32` and disable all other integer types. `INT` is set to `i32`. | | `only_i64` | Set the system integer type to `i64` and disable all other integer types. `INT` is set to `i64`. | +| `no_std` | Build for `no-std`. Notice that additional dependencies will be pulled in to replace `std` features. | By default, Rhai includes all the standard functionalities in a small, tight package. Most features are here to opt-**out** of certain functionalities that are not needed. Excluding unneeded functionalities can result in smaller, faster builds as well as less bugs due to a more restricted language. @@ -1477,6 +1479,7 @@ engine.set_optimization_level(rhai::OptimizationLevel::None); [`no_optimize`]: #optional-features [`only_i32`]: #optional-features [`only_i64`]: #optional-features +[`no_std`]: #optional-features [`Engine`]: #hello-world [`Scope`]: #initializing-and-maintaining-state diff --git a/src/stdlib.rs b/src/stdlib.rs index fa147c7d..2bffb4c2 100644 --- a/src/stdlib.rs +++ b/src/stdlib.rs @@ -1,3 +1,5 @@ +//! Helper module which defines most of the needed features from `std` for `no-std` builds. + #[cfg(feature = "no_stdlib")] mod inner { pub use core::{