New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use with no-std #19
Comments
(unfortunately this repo is largely unmaintained at this point, sadly... though I'd love to have time to work on it) I'm not familiar with xargo, but it may be possible to move rhai over to no-std in the future. I know there are some efforts to make this easier in the future. In theory, most of it should be pretty portable. |
I'm new too, but my thoughts: xargo should build the std crate for the target, at least some tutorials say it will. I think " the |
In the future, we may provide a no-std feature, though. Interesting idea |
I'm in need of a |
We also have a project that will run on a microcontroller and has need for a scripting language. For our case we would be okay with a |
Started working on this here: https://github.com/VictorKoenders/rhai/tree/no_std I ran into 2 big issues:
Furthermore I've disabled everything depending on Edit: added Edit 2: core::intrinsics did have the math functions, so I added those and updated the travis build to also test |
@VictorKoenders I have pushed a large amount of changes recently. Can you see if it is easy to for you to update your branch? |
It was easier to re-do my changes. I've updated my branch to the latest master version. One thing I ran into is that I've added an alternative function let engine = Engine::custom()
.on_print(|x| println!("{}", x))
.on_debug(|x| eprintln!("{}", x))
.map_type("alloc::string::String", "string") // fills `type_names`
.map_type("alloc::vec::Vec<alloc::boxed::Box<dyn rhai::any::Any>>>", "array")
.map_type("alloc::boxed::Box<dyn rhai::any::Any>", "dynamic")
.build(); |
The would be nice, especially some API to do function registrations and setup the initial scope with variables. |
Maybe in Or make them no-op's by default for all targets? If someone wants to print them, it'd be easy to register a callback with |
I added a new Go clone from https://github.com/schungx/rhai to check it out. |
I should be able to do a final test tonight. One of the issues I ran into is that the microcontrollers I have only have several KB of storage space (16KB and 64KB), which needs to contain the binary and the .rhai file. Rhai is incredibly small, only about 155KB, but that's still too big for the devices I currently have. I managed to shave off 80KB by disabling the builtin functions, but that still leaves the firmware at 77KB, just over the limit of 64KB I have. Another thing that I want to do before making a PR is to update the README, as this currently (correctly) states that rhai has no dependencies, but when using no_std we'll have to use some dependencies (or writing our own hashmap, error trait and math functions). |
It is better that you base your work on my working repo so we won't have a huge headache later on trying to merge... :-) |
Did you compile release mode with If it is still large, I can see what things I can trim out. |
But I've already done all the work in my repo, and it's easy to rebase it. The project I'm trying to run is on https://github.com/victorkoenders/embedded-rhai. These are my cargo flags:
The output of
I'm looking into precompiling the |
I was reading somewhere that the recommendation is to add a feature called The problem with using |
Normally I'd agree, but in this case we actually need to add dependencies when we switch to no_std mode, and I don't know a way to include a dependency when a feature is taken away.
|
I'm about to do another PR with a large amounts of coding and documentation cleanup. I think it might be easier if you redo you changes based on what I have right now... Alternatively, I can manually redo your changes to my my repo, but then I'll have no way to test that it works and I haven't made a mistake. |
I've created a new PR #104 with the latest clean-up for reference. |
@VictorKoenders I've back ported your It almost compiles on my machine, except for Can you test if it works OK? |
My PR #103 doesn't involve Feel free to poke me to rebase my changes when you're done with yours. I can reapply these changes trivially and do another test to see if it runs on a microcontroller. |
Great! I'm a noob Git user and have no idea how to rebase something... You can see in my branch that I've spun out Also, |
@VictorKoenders I've merged the latest round of changes. You can start your rebasing. |
@VictorKoenders Commit b1b25d3 adds a dependency to I understand that the feature
|
@VictorKoenders I have been thinking about the builder style. It looks nice, but there is a problem in that it forbids changes to the engine after you build it (or you have to build a new one). If someone uses // Here we use the default engine to compile the script and optimize it
let mut engine = Engine::custom().
.set_optimization_level(OptimizationLevel::Full)
:
.build();
let ast = engine.compile("... some script ...")?;
// Here we create another Engine
engine = Engine::custom()
.set_optimization_level(OptimizationLevel::Simple)
.register_fn("my_func", some_dangerous_func_with_side_effects)
:
.build();
// or something like this
engine = engine.reopen()
.set_optimization_level(OptimizationLevel::Simple)
.register_fn("my_func", some_dangerous_func_with_side_effects)
.build();
engine.eval_ast::<i64>(&ast)?; So, is a builder style good here? |
I think builder style is perfectly fine here. I doubt people will be adding new functions to their scripts on the fly |
@VictorKoenders did you get the chance to test it out? |
I have not, I can't even compile rhai 0.11.0 or master with the latest changes. These changes seem to compile, but I don't have a working microcontroller at the moment I can test it on, and I don't know what effect this has on the diff --git a/Cargo.toml b/Cargo.toml
index 063abd0..0e2a168 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,7 +17,7 @@ keywords = [ "scripting" ]
categories = [ "no-std", "embedded", "parser-implementations" ]
[dependencies]
-num-traits = "0.2.11"
+num-traits = { version = "0.2.11", default-features = false }
[features]
#default = ["no_function", "no_index", "no_object", "no_float", "only_i32", "no_stdlib", "unchecked", "no_optimize"]
@@ -47,7 +47,7 @@ version = "*"
optional = true
[dependencies.core-error]
-version = "*"
+version = "0.0.1-rc4"
features = ["alloc"]
optional = true |
Yes, I have a habit (probably not a good one) to omit version numbers in my |
Autocurry feature
The repo now has a full dedicated |
I'm trying out rust on a cheap microcontroller following this tutorial https://polyfractal.com/post/rustl8710/
The tutorial works great and the sample echo program runs over serial.
I'd love to add in a rust scripting language and I really like the design of Rhai. But when I add the library, the compile fails because of std is missing.
I'm fairly new to rust still and am not quite clear on what this all means. Is Rhai meant to be used in such embedded use cases? It sure would be neat if it or something like it did work.
The text was updated successfully, but these errors were encountered: