DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: <dev@dpdk.org>
Cc: <getelson@nvidia.com>
Subject: Re: [RFC PATCH] add rust binding support to DPDK
Date: Tue, 8 Apr 2025 16:05:51 +0100	[thread overview]
Message-ID: <Z_U7T9qFJzvhmBuP@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <20250408145838.2501034-1-bruce.richardson@intel.com>

On Tue, Apr 08, 2025 at 03:58:38PM +0100, Bruce Richardson wrote:
> Add a Cargo.toml file in the root folder and a number of other scripts
> and rust-related files into buildtools/rust, which then enables DPDK to
> be cloned and built as a rust crate - all-be-it one with only two
> functions: rte_eal_init and rte_eal_cleanup.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
> 
> This RFC is proposed as an alternative approach to enabling rust support
> in DPDK. The key difference vs previous is that we are taking the whole
> DPDK project here as a rust "crate", which can then be used by other
> higher-level crates as a dependency. Building the crate does a
> (minimal) build of DPDK and statically links it in, so there is no
> "install" step or anything needed - the Rust app just adds DPDK to their
> Cargo.toml file and then should have everything they need.
> 
> ---
>  Cargo.toml                                | 16 +++++++
>  buildtools/meson.build                    |  1 +
>  buildtools/rust/build.rs                  | 45 ++++++++++++++++++++
>  buildtools/rust/gen-cargo-bindgen-info.py | 52 +++++++++++++++++++++++
>  buildtools/rust/lib.rs                    | 25 +++++++++++
>  buildtools/rust/wrapper.h                 |  5 +++
>  meson.build                               |  3 ++
>  7 files changed, 147 insertions(+)
>  create mode 100644 Cargo.toml
>  create mode 100644 buildtools/rust/build.rs
>  create mode 100644 buildtools/rust/gen-cargo-bindgen-info.py
>  create mode 100644 buildtools/rust/lib.rs
>  create mode 100644 buildtools/rust/wrapper.h
> 

<snip>

> diff --git a/buildtools/rust/lib.rs b/buildtools/rust/lib.rs
> new file mode 100644
> index 0000000000..f99c54ac42
> --- /dev/null
> +++ b/buildtools/rust/lib.rs
> @@ -0,0 +1,25 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2025 Intel Corporation
> + */
> +
> +#![allow(non_upper_case_globals)]
> +#![allow(non_camel_case_types)]
> +#![allow(non_snake_case)]
> +
> +include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
> +
> +#[cfg(test)]
> +mod tests {
> +    use super::*;
> +
> +    #[test]
> +    fn test_helloworld() {
> +	let appname = std::ffi::CString::new("test-rs").unwrap();
> +	let mut argv = [appname.into_raw()];
> +	let ret = unsafe {
> +		rte_eal_init(argv.len().try_into().unwrap(), argv.as_mut_ptr())
> +	};
> +	assert!(ret >= 0, "rte_eal_init failed");
> +        unsafe { rte_eal_cleanup() };
> +    }
> +}

This test code is included in the patch to make it easy to verify that DPDK
can be built and run with rust - at least doing EAL init and cleanup.

To test, once rust is available on your system (e.g. using rustup), apply
this patch and then just do "cargo test" in the root of your DPDK
directory. After waiting a minute for things to build you should see the
test run output of DPDK initialization.

The whole approach for now I'm deliberately keeping extremely minimal so as
a) not to invest too much effort before we know what way we want to go and
b) to make it easier to review and comment upon.

For anyone wanting to try this out in a standalone app or play with
developing a higher-level crate, I've pushed this patch to my github
account. This is the "Cargo.toml" file entry I've used to pull this down
when investigating wrapping eal_init into a "higher-level" rust-style init
API:

[dependencies]
dpdk-c = { git = "https://github.com/bruce-richardson/dpdk", branch = "cargo-build" }

Regards,

/Bruce

  reply	other threads:[~2025-04-08 15:06 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-06 13:37 [PATCH] rust: support DPDK API Gregory Etelson
2025-03-06 19:26 ` Van Haaren, Harry
2025-03-07 16:56   ` Etelson, Gregory
2025-03-07 15:54 ` Van Haaren, Harry
2025-03-07 16:20   ` Bruce Richardson
2025-03-07 18:15     ` Etelson, Gregory
2025-03-07 18:00   ` Etelson, Gregory
2025-03-08 14:28 ` Igor Gutorov
2025-03-08 19:14   ` Etelson, Gregory
2025-03-10 15:31     ` Stephen Hemminger
2025-03-12  5:21       ` Etelson, Gregory
2025-03-08 18:50 ` [PATCH v2] rust: support raw " Gregory Etelson
2025-03-10 16:13   ` Van Haaren, Harry
2025-03-10 16:25     ` Bruce Richardson
2025-03-12 17:19       ` Thomas Monjalon
2025-03-14 19:12     ` Etelson, Gregory
2025-03-10 15:00 ` [PATCH] rust: support " Stephen Hemminger
2025-03-12  5:12   ` Etelson, Gregory
2025-03-10 16:18 ` Stephen Hemminger
2025-03-10 16:30   ` Bruce Richardson
2025-03-12 14:30   ` Etelson, Gregory
2025-03-13  7:56     ` Igor Gutorov
2025-03-12 15:29   ` Igor Gutorov
2025-03-12 17:24     ` Thomas Monjalon
2025-03-14 18:38 ` [PATCH v3] rust: support raw " Gregory Etelson
2025-03-18  8:51   ` Dariusz Sosnowski
2025-03-18  9:12     ` Dariusz Sosnowski
2025-03-22 10:59 ` [PATCH v4] " Gregory Etelson
2025-03-22 17:39   ` Bruce Richardson
2025-03-27  5:51     ` Etelson, Gregory
2025-03-27 16:22   ` Bruce Richardson
2025-03-28 18:30     ` Etelson, Gregory
2025-03-27  8:23 ` DPDK for rust Morten Brørup
2025-03-27  9:00   ` Etelson, Gregory
2025-03-27 16:17     ` Bruce Richardson
2025-03-28 18:09       ` Etelson, Gregory
2025-03-28 19:25         ` Stephen Hemminger
2025-03-31  9:11           ` Bruce Richardson
2025-03-31 10:26             ` Luca Boccassi
2025-04-01 13:08               ` Etelson, Gregory
2025-03-31  9:03       ` Thomas Monjalon
2025-03-31  9:10         ` Bruce Richardson
2025-04-08 14:58 ` [RFC PATCH] add rust binding support to DPDK Bruce Richardson
2025-04-08 15:05   ` Bruce Richardson [this message]
2025-04-10  5:28   ` Etelson, Gregory
2025-04-11 13:13     ` Van Haaren, Harry
2025-04-11 15:39       ` Etelson, Gregory
2025-04-11 16:22         ` Van Haaren, Harry
2025-04-13  8:07           ` Etelson, Gregory
2025-04-13 17:09             ` Owen Hilyard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z_U7T9qFJzvhmBuP@bricha3-mobl1.ger.corp.intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=getelson@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).