-
Notifications
You must be signed in to change notification settings - Fork 54
Add Rust build system support #356
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| [workspace] | ||
| resolver = "3" | ||
|
|
||
| members = [ | ||
| "executables/referenceApp/rustHelloWorld", | ||
| ] | ||
|
|
||
| [workspace.package] | ||
| version = "0.1.0" | ||
| documentation = "https://eclipse-openbsw.github.io/openbsw/" | ||
|
|
||
| # Workspace dependencies - add new Rust crates here as they are developed | ||
| [workspace.dependencies] | ||
|
|
||
| # Similar to C++ we always build optimized (matching C++ -O2) | ||
| [profile.dev] | ||
| panic = "abort" | ||
| lto = true | ||
| opt-level = 2 | ||
| incremental = false | ||
| codegen-units = 1 | ||
| debug = true | ||
|
|
||
| [profile.release] | ||
| panic = "abort" | ||
| lto = true | ||
| opt-level = 2 | ||
| incremental = false | ||
| codegen-units = 1 | ||
| debug = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [package] | ||
| name = "rust_hello_world" | ||
| version.workspace = true | ||
| documentation.workspace = true | ||
| edition = "2024" | ||
|
|
||
| [lib] | ||
| crate-type = ["staticlib"] | ||
|
|
||
| [dependencies] | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright 2026 Accenture. | ||
|
|
||
| #ifndef RUST_HELLO_WORLD_H | ||
| #define RUST_HELLO_WORLD_H | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" | ||
| { | ||
| #endif | ||
|
|
||
| /// Adds two numbers and returns the result. | ||
| /// | ||
| /// \param a First number to add | ||
| /// \param b Second number to add | ||
| /// \return The sum of a and b | ||
| uint32_t rust_add(uint32_t a, uint32_t b); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example shows a C-only interface use case. For interfacing between C++ and Rust, would it be possible to give a more complex example, e.g. mapping between C++ class and Rust crate interface? Maybe put it on the linked agenda/Rust discussion, but we would need it at some point to support reasonably complex interfaces.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! This initial PR intentionally uses a minimal C-style interface (extern "C") to establish the basic Rust build infrastructure with Corrosion. The upcoming features in the agenda will include more interfaces between C++ and Rust. |
||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif // RUST_HELLO_WORLD_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Copyright 2026 Accenture. | ||
|
|
||
| //! A simple "Hello World" Rust library demonstrating Rust integration with OpenBSW. | ||
| //! | ||
| //! This crate provides a minimal example of how to expose Rust functions to C++ code | ||
| //! in the OpenBSW build system. | ||
| //! | ||
| //! # FFI Approach | ||
| //! | ||
| //! This example uses the **manual FFI approach**, where: | ||
| //! - Rust functions are marked with `#[no_mangle]` and `extern "C"` | ||
| //! - A corresponding C/C++ header file is written by hand | ||
| //! | ||
| //! This is not the only way to expose Rust to C++. Alternative approaches include: | ||
| //! - **[cbindgen](https://github.com/mozilla/cbindgen)**: Automatically generates C/C++ headers from Rust code | ||
| //! - **[cxx](https://cxx.rs/)**: Provides safe bidirectional interop between Rust and C++ | ||
| //! | ||
| //! The manual approach was chosen here for simplicity. | ||
| //! | ||
| //! # Target Compatibility | ||
| //! | ||
| //! Uses `no_std` for compatibility with both POSIX and embedded targets. | ||
|
|
||
| #![no_std] | ||
|
|
||
| /// Panic handler for no_std environments. | ||
| #[panic_handler] | ||
| fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
| loop {} | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /// Adds two numbers and returns the result. | ||
| /// | ||
| /// # Arguments | ||
| /// | ||
| /// * `a` - First number to add | ||
| /// * `b` - Second number to add | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// The sum of `a` and `b`. | ||
| #[unsafe(no_mangle)] | ||
| pub extern "C" fn rust_add(a: u32, b: u32) -> u32 { | ||
| a.wrapping_add(b) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| github: ["jschwe"] |
Uh oh!
There was an error while loading. Please reload this page.