From patchwork Thu Sep 11 21:44:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 25 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757627082; bh=UQhvVrDIONvnYfHQychdkpEiGeyAYz91YawF222uyuI=; h=From:To:Date:CC:Subject:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=UAogCl+a/yVAwBxIOi6EDl8iWoe6aYZkGYuEAwLuNcQ5IcfQh4gjABtcHI8/gZGUr Rw+jrEviia7H/NihEODJnIrpW0Ub1zUoQu+PGP+2XZ/09wcGYw6psnyUdzo8ZkhEFw 8NKkVmKniRbL6TLtY6BiR5ivSpTPR7Uc2W24j/NijHGIp89tF99yai+H9Jl+vQmsWm TvZeTfFDLNHWc/grc73zN11Y/f7xk/9BR8lSIOVoylNW6W01QRqvfn6ZuFf06SeU6y AWWGriv0woY2NOBB8bXuMJ3K8umU97j09kw7TXrpXdjH6RdA6YM7VCgbUWv7rrOKXK JSroShAbOMNyA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8FC7667B0D for ; Thu, 11 Sep 2025 15:44:42 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 08rfThM-3NU1 for ; Thu, 11 Sep 2025 15:44:42 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757627082; bh=UQhvVrDIONvnYfHQychdkpEiGeyAYz91YawF222uyuI=; h=From:To:Date:CC:Subject:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=UAogCl+a/yVAwBxIOi6EDl8iWoe6aYZkGYuEAwLuNcQ5IcfQh4gjABtcHI8/gZGUr Rw+jrEviia7H/NihEODJnIrpW0Ub1zUoQu+PGP+2XZ/09wcGYw6psnyUdzo8ZkhEFw 8NKkVmKniRbL6TLtY6BiR5ivSpTPR7Uc2W24j/NijHGIp89tF99yai+H9Jl+vQmsWm TvZeTfFDLNHWc/grc73zN11Y/f7xk/9BR8lSIOVoylNW6W01QRqvfn6ZuFf06SeU6y AWWGriv0woY2NOBB8bXuMJ3K8umU97j09kw7TXrpXdjH6RdA6YM7VCgbUWv7rrOKXK JSroShAbOMNyA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7D25567B05 for ; Thu, 11 Sep 2025 15:44:42 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757627076; bh=Hx+AVjTT4DkRQxl632cKhND0zdB0Ss+9OTJJ6TqwH0Q=; h=From:To:Cc:Subject:Date:From; b=mjJSYIsaSrs1mgomhqLKzzh/p5vz1f2k+tEGWklY15i9O3STvw5wm68Wa+TJwWMt9 HVs6EmO6KYI2m+RQLOyyO9ynnkRH5PbIc7ZeqtSNJxEuzWUC1k9lZr3ehluqahYeXW Hx2/+nkBaO7HFdxs45obueS3lQsqiuOLm4Sv83HR/5vCfBJ1feXL650p5JiQ45PiWD Z9skoSTNEkePP+yNTSWs9qv2DRu8pqiMa5+z2EwJMavP/o8udnc88AvODgbCFT0cZa CsBK0r12yYWZC/rdkRtPFG/iHEpIkF9qaGmmcKmyfQFO8wreoI54QcXeGGYZv/IEFp mS3z1U1X6Y3Ag== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BA7D667A59; Thu, 11 Sep 2025 15:44:36 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id rGzqGVKTEcw7; Thu, 11 Sep 2025 15:44:36 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757627070; bh=1xjPEiA2hLq3cca+yT2iHLIXSJGmQnOV/uwgACalKdI=; h=From:To:Cc:Subject:Date:From; b=Jjw7/Hv21bUI00hACIPocgmEtAKGcYsjP9M0Us/UkD/U87ck/TELSTyBiL/pf/Kf4 fUerrpaQIh3YfMFhUPQg9oA5AR7jQRzZYQy4W4Ewg2Nq8dw7krR5uPDT3D02sOM+3k OEp4ZJoZLinE7IRrtNSyOEQWyiCPGliKHjDq8JZWKFNBlJxaVZJPylQWQpR0ZChLTo /KssfsX1VwKSBsTQIURbLrn51QiCcxrvueQ72wEw4HRYr0DhsecszaQQ+i/ak97goH 6xwEYeSC4gRgHHMynvg6qpKsf29VPU99XVdyS7BQyo7PCdah9A1+OLaLKmkD/ZavJN Qa5YNcoA6otVg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A2B0F67A58; Thu, 11 Sep 2025 15:44:30 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 11 Sep 2025 15:44:04 -0600 Message-ID: <20250911214425.3687188-1-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Message-ID-Hash: 324J3MC4DU6OVF5AHW2DTHHC7C7HPU2E X-Message-ID-Hash: 324J3MC4DU6OVF5AHW2DTHHC7C7HPU2E X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , GitLab CI Runner X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 00/14] ulib: Add support for Rust main programs List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: GitLab CI Runner 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