[Concept,00/14] ulib: Add support for Rust main programs

Message ID 20250911214425.3687188-1-sjg@u-boot.org
Headers
Series ulib: Add support for Rust main programs |

Message

Simon Glass Sept. 11, 2025, 9:44 p.m. UTC
  From: GitLab CI Runner <trini@konsulko.com>

So far ulib only supports linking against C programs. While this is the
common case, there is no particular reason why other languages could not
be used to write the main program, so long as they can interoperate with
the libu-boot.so/.a library.

Rust provides a Foreign Function Interface feature, which makes it
possible to declare and call C functions from Rust code. It provides
memory safety without the uncertainty of garbage collection and with
less overhead. It would be nice if ulib could be used with Rust.

This series provides the necessary pieces to make this work. It adds an
example program which works just like the C one, but written in Rust. As
with the existing example, the program can be built against the static
ulib or can use dynamic linking.

Note that only sandbox is supported at present, i.e. native execution on
(for example) a Linux machine. Future work will add support for running
on other architectures.

In order to make more use of ulib features, U-Boot's headers will need
to be made available in Rust format. For now, only a very few are
provided, as a starting point.


Simon Glass (13):
  docker: Provide a rust toolchain
  CI: Switch to new docker image
  examples: Correct dependencies for ulib
  ulib: Return the full version with ulib_get_version()
  ulib: Add a way to obtain the version
  ulib: Add a very basic rust library
  ulib: Add a Rust example
  doc: Fix a few nits in the ulib docs
  doc: ulib: Clarify calling functions in any header
  doc: ulib: Add Rust examples documentation
  test: ulib: Add a test for the rust example
  doc: Provide a motivation for ulib
  CI: Build the Rust examples

Tom Rini (1):
  CI: Update to coreboot 25.03

 .gitlab-ci.yml                   |  15 ++-
 Makefile                         |  18 +++-
 doc/develop/ulib.rst             | 114 ++++++++++++++++++--
 examples/rust/.gitignore         |   5 +
 examples/rust/Cargo.lock         |  14 +++
 examples/rust/Cargo.toml         |  17 +++
 examples/rust/Makefile           |  95 +++++++++++++++++
 examples/rust/README.md          | 120 +++++++++++++++++++++
 examples/rust/build.rs           | 105 +++++++++++++++++++
 examples/rust/src/demo.rs        | 112 ++++++++++++++++++++
 examples/rust/src/rust_helper.rs |  59 +++++++++++
 examples/ulib/demo.c             |   2 +-
 examples/ulib/rules.mk           |  13 +--
 include/u-boot-lib.h             |   9 +-
 lib/rust/.gitignore              |   1 +
 lib/rust/Cargo.lock              |   7 ++
 lib/rust/Cargo.toml              |  17 +++
 lib/rust/src/lib.rs              | 173 +++++++++++++++++++++++++++++++
 lib/ulib/ulib.c                  |   3 +-
 test/py/tests/test_ulib.py       |  65 ++++++++++++
 tools/docker/Dockerfile          |  10 +-
 21 files changed, 947 insertions(+), 27 deletions(-)
 create mode 100644 examples/rust/.gitignore
 create mode 100644 examples/rust/Cargo.lock
 create mode 100644 examples/rust/Cargo.toml
 create mode 100644 examples/rust/Makefile
 create mode 100644 examples/rust/README.md
 create mode 100644 examples/rust/build.rs
 create mode 100644 examples/rust/src/demo.rs
 create mode 100644 examples/rust/src/rust_helper.rs
 create mode 100644 lib/rust/.gitignore
 create mode 100644 lib/rust/Cargo.lock
 create mode 100644 lib/rust/Cargo.toml
 create mode 100644 lib/rust/src/lib.rs