Skip to content
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

Can I use RustPython in Microcontrollers #2362

Open
jake-ke opened this issue Dec 8, 2020 · 10 comments
Open

Can I use RustPython in Microcontrollers #2362

jake-ke opened this issue Dec 8, 2020 · 10 comments

Comments

@jake-ke
Copy link

@jake-ke jake-ke commented Dec 8, 2020

Hello all,

I wonder if I can use RustPython in a microcontroller which uses the TockOS kernel developed in Rust. Tock currently just has example user applications in Rust, as explained here.

I figured I might be able to use RustPython in two ways:

  1. add the RustPython dependency to my Rust applications and embed the python codes
  2. directly load the bytecode generated by RustPython

The issue with the first option is that Tock applications are run in #![no_std] configurations. I could not build the RustPython dependency. For the second option, I am not sure if it is feasible at all.

I saw @windelbouwman mentioned in an issue that running in microcontrollers was a stretch goal. What is the status now?
How can I resolve the issue with the standard library? How much work would that be?

Thank you!

@coolreader18
Copy link
Member

@coolreader18 coolreader18 commented Dec 9, 2020

There's not really any work on this yet, but it shouldn't be too hard! I whipped up this branch for converting the parser, compiler etc to no_std, but I imagine the vm would be the main hurdle.

@coolreader18
Copy link
Member

@coolreader18 coolreader18 commented Dec 9, 2020

Looks like bincode would be the main blocker: bincode-org/bincode#265

@windelbouwman
Copy link
Contributor

@windelbouwman windelbouwman commented Dec 9, 2020

This item is still a stretch goal, but I would love to see this happen!

Things to note / to be done:

  • Be able to use rustpython in a no_std env (like @coolreader18 mentioned)
  • Performance / code size: we need to reduce code size and improve performance overall. This has many benefits: faster runtime on desktop use, faster usage on microcontrollers, less power usage, less memory usage. Good thing all the way!
  • The standard library. This boils down to being able to run rustpython with or without the standard library, and as such being able to run it on a microcontroller where there might be a flash memory restriction on amount of python files you can embed.
  • The VM is where most of the action happens, and is I guess the hardest part to get going. I would start by porting the parser crate to no_std and see if this can be used on a microcontroller. Next up would be the compiler, and final step (and most difficult) the vm crate. I have no clue about code size at this point, but I'm guessing the vm is using the biggest amount of memory.

@jake-ke
Copy link
Author

@jake-ke jake-ke commented Dec 10, 2020

Thank you for starting the no_std development again! My team is building a system which uses a RISC-V microcontroller, with a Tock kernel and a hardware accelerator, for accelerating machine learning applications. For now, we might proceed with Rust applications, but our end goal is to support Python applications. Hopefully, RustPython can help us achieve that goal.

@mental32
Copy link

@mental32 mental32 commented Jan 8, 2021

Any progress towards RustPython supporting no_std would be amazing tbh!

@coolreader18 is there anything I can do to help out?

The bincode blocker is unfortunate but I'm not sure where its needed (I'm not familiar with the RP codebase at all) there are other alternatives that support no_std for instance capnproto but again I'm not sure how viable they are to replace bincode since I dont know how or what bincode is being used for...

@allsey87
Copy link

@allsey87 allsey87 commented Jun 9, 2021

@coolreader18 regarding bincode being the main blocker, it seems that there is a repository in the same organization for a no_std-compatible bincode: bincode-org/bincode-core. Could this be a viable solution?

@coolreader18
Copy link
Member

@coolreader18 coolreader18 commented Jun 9, 2021

Possibly, though I don't think bincode-core is published yet. I think my current plan would be to rewrite rustpython-bytecode to use deku instead of bincode; it's moreso designed for custom binary formats, and might be easier to keep stable.

@leapofazzam123
Copy link

@leapofazzam123 leapofazzam123 commented Feb 28, 2022

bincode 2 should support no_std by disabling the default features or disabling the std feature

@allsey87
Copy link

@allsey87 allsey87 commented Feb 28, 2022

@leapofazzam123 what is the current relationship between pravega/bincode2 and bincode-org/bincode? At a glance, the Cargo.toml in bincode-org/bincode seems to indeed support a no_std configuration.

@coolreader18
Copy link
Member

@coolreader18 coolreader18 commented Feb 28, 2022

It looks like bincode-v2 has been merged back to bincode-org but it's still in beta? That's what I glean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants