Skip to content

Experiment: Devicetree and device driver access in Rust #76199

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

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a0611a1
rust: Initial config option
d3zd3z Jul 15, 2024
79eb8a2
rust: Simple main wrapper
d3zd3z Jul 15, 2024
6646068
rust: Basic `zephyr` crate
d3zd3z Jul 15, 2024
62af97a
rust: Add cmake support for building rust apps
d3zd3z Jul 15, 2024
775a3a0
rust: Simple rust hello_world application
d3zd3z Jul 15, 2024
564d96d
MAINTAINERS: Add Rust to maintainers file
d3zd3z Jul 15, 2024
191eca3
rust: Move Kconfig bool values into crate
d3zd3z Jul 15, 2024
98f0291
rust: Make Kconfig values available to Rust code
d3zd3z Jul 15, 2024
62770bf
samples: rust: Access CONFIG_BOARD
d3zd3z Jul 15, 2024
6f55e18
doc: languages: Add Rust documentation
d3zd3z Jul 16, 2024
cf88e6f
samples: rust: Rename hello
d3zd3z Jul 16, 2024
6052ca4
doc: Use proper quote block for shell
d3zd3z Jul 16, 2024
c95dc43
rust: Support negative Kconfig int values
d3zd3z Jul 17, 2024
db90a84
rust: Mark RUST support as experimental
d3zd3z Jul 17, 2024
285c9d5
cmake: rust: Use proper FPU config
d3zd3z Jul 18, 2024
a8d1745
doc: rust: Fix code block
d3zd3z Jul 18, 2024
2f39272
doc: rust: Use real config settings
d3zd3z Jul 18, 2024
f883380
cmake: rust: Fix Cortex-M4 non-fp target
d3zd3z Jul 18, 2024
b72fdeb
rust: Fix prototype for rust_main
d3zd3z Jul 18, 2024
157448e
remove board specific options
mjaun Jul 16, 2024
98d0bf7
target mapping for cortex m7
mjaun Jul 16, 2024
680250e
first trial of providing dts information to rust
mjaun Jul 17, 2024
e3abd1c
add zephyr-sys library with bindgen
mjaun Jul 18, 2024
05652a7
control gpio from rust
mjaun Jul 18, 2024
96f4e06
call sleep directly
mjaun Jul 18, 2024
57e361e
cleaner implementation for allocator and panic handler
mjaun Jul 18, 2024
1a12f04
better print support
mjaun Jul 18, 2024
9059699
more generic way of determining clang args
mjaun Jul 19, 2024
f041979
move gpio driver
mjaun Jul 19, 2024
fe62b92
start implementing gpio driver
mjaun Jul 19, 2024
f80d219
improved errno handling
mjaun Jul 19, 2024
8f14bb7
support more types in rust dts
mjaun Jul 19, 2024
9eb9540
include generated device tree
mjaun Jul 19, 2024
74afe70
make device tree accessible in application
mjaun Jul 20, 2024
dea5646
cleanups
mjaun Jul 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/modules/rust.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function(rust_cargo_application)
# For now, hard-code the Zephyr crate directly here. Once we have
# more than one crate, these should be added by the modules
# themselves.
set(LIB_RUST_CRATES zephyr zephyr-build)
set(LIB_RUST_CRATES zephyr zephyr-build zephyr-sys)

_rust_map_target()
message(STATUS "Building Rust llvm target ${RUST_TARGET}")
Expand Down
9 changes: 9 additions & 0 deletions lib/rust/zephyr-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "zephyr-sys"
version = "0.1.0"
edition = "2021"

[dependencies]

[build-dependencies]
bindgen = { version = "0.69.4", features = ["experimental"] }
21 changes: 21 additions & 0 deletions lib/rust/zephyr-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::env;
use std::path::PathBuf;

fn main() {
let bindings = bindgen::Builder::default()
.clang_arg("-I/home/ubuntu/zephyrproject/zephyr/include")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol. I was going to try to figure out how to get the include path out of cmake. Turns out it is rather challenging to do. We do need to figure out how to do it correctly, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did figure out how to do this, I'll push some code hopefully tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you were looking at an old version. Here is the best solution I could come up with for this: https://github.com/mjaun/zephyr/blob/dea56463ebbf469118ed34ee5c9e343586bf27da/cmake/modules/rust.cmake#L42

.clang_arg("-I/home/ubuntu/zephyrproject/zephyr/build/zephyr/include/generated")
.clang_arg("-imacros/home/ubuntu/zephyrproject/zephyr/build/zephyr/include/generated/zephyr/autoconf.h")
.wrap_static_fns(true)
.allowlist_function("gpio_.*")
.header("wrapper.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Unable to generate bindings");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());

bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
5 changes: 5 additions & 0 deletions lib/rust/zephyr-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
1 change: 1 addition & 0 deletions lib/rust/zephyr-sys/wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <zephyr/drivers/gpio.h>
1 change: 1 addition & 0 deletions lib/rust/zephyr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Functionality for Rust-based applications that run on Zephyr.
# used by the core Zephyr tree, but are needed by zephyr applications.
[build-dependencies]
zephyr-build = "0.1.0"
zephyr-sys = "0.1.0"