-
Notifications
You must be signed in to change notification settings - Fork 48
rust: Add a Rust compatible API implementation. #141
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
base: next
Are you sure you want to change the base?
Conversation
7a556b5 to
f86a047
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, looking forward to see this grow! 🥳 🤗
Kconfig
Outdated
| imply CBPRINTF_FP_SUPPORT | ||
| imply RING_BUFFER | ||
| select UART_INTERRUPT_DRIVEN | ||
| select RUST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should currently be an optional feature, to avoid adding the strong dependency right away.
We will gradually add a Rust compatible API implementation conforming to Apache-2. This PR adds an alternative implementation of Common.cpp. Signed-off-by: TOKITA Hiroshi <[email protected]>
Adding Rust architecture modules for ensure compilation. Signed-off-by: TOKITA Hiroshi <[email protected]>
| run: | | ||
| git clone https://github.com/arduino/ArduinoCore-API.git $MODULE_PATH/../ArduinoCore-API | ||
| cp -rfp $MODULE_PATH/../ArduinoCore-API/api $MODULE_PATH/cores/arduino/ | ||
| apt install rustup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recommended way to install Rust is via the rustup.rs installer script, Ubuntu's rustup package from apt is often outdated and may not work correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also,
All initialization is lumped into one "Initialize" step mixing unrelated concerns (cloning API, copying files, Rust setup)...
Better structure:
- name: Clone ArduinoCore-API
[...]
- name: Install Rust toolchain
[...]
| rustup target add thumbv6m-none-eabi | ||
| rustup target add thumbv7em-none-eabihf | ||
| rustup target add thumbv7em-none-eabi | ||
| rustup target add thumbv7m-none-eabi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Installing targets one-by-one is slower. Rustup supports installing multiple targets in one command
| rustup target add thumbv6m-none-eabi | ||
| rustup target add thumbv7em-none-eabihf | ||
| rustup target add thumbv7em-none-eabi | ||
| rustup target add thumbv7m-none-eabi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| rustup target add thumbv7m-none-eabi | |
| rustup target add thumbv6m-none-eabi thumbv7em-none-eabihf thumbv7em-none-eabi thumbv7m-none-eabi |
| let num = x.wrapping_sub(in_min).wrapping_mul(out_max.wrapping_sub(out_min)); | ||
| let den = in_max.wrapping_sub(in_min); | ||
| // Note: To keep compatibility, the panic when den=0 is left as is. | ||
| num / den.wrapping_add(out_min) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to operator precedence, this evaluates as:
num / (den + out_min) // Division happens AFTER adding out_min to den!
Original C++ code:
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;Can we just follow similar arithmetic syntax in rust too, the code using wrapping_* is making the logic really confusing to understand, and with rust already being a new addition I feel like we should make an effort to keep things simple where possible.
| config USE_ARDUINO_API_RUST_IMPLEMENTATION | ||
| bool "Use Rust implementation API core" | ||
| default y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to be nitpicky, but I asked this before and I'm still confused. 🙂
Is Rust expected to be installed by anyone trying to use the core at this stage?
If not, I would expect this to be manually set somehow (via the west command line, using snippets, etc) and not being default y-ed.
We will gradually add a Rust compatible API implementation conforming to Apache-2.
This PR adds an alternative implementation of Common.cpp.