On Fri, Aug 22, 2025 at 3:30 PM Paolo Bonzini <pbonz...@redhat.com> wrote: > > From: Tanish Desai <tanishdesa...@gmail.com> > > The trace crate is a minimal container for dependencies of tracepoints > (so that they do not have to be imported in all the crates that use > tracepoints); it also contains a macro called "include_trace!" that is > able to find the right include file from the trace/ directory. > > Signed-off-by: Tanish Desai <tanishdesa...@gmail.com> > [Write commit message. - Paolo] > Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> > --- > rust/Cargo.lock | 4 ++++ > rust/Cargo.toml | 1 + > rust/meson.build | 2 +- > rust/trace/Cargo.toml | 16 ++++++++++++++++ > rust/trace/meson.build | 19 +++++++++++++++++++ > rust/trace/src/lib.rs | 23 +++++++++++++++++++++++ > trace/meson.build | 8 +++++++- > 7 files changed, 71 insertions(+), 2 deletions(-) > create mode 100644 rust/trace/Cargo.toml > create mode 100644 rust/trace/meson.build > create mode 100644 rust/trace/src/lib.rs > > diff --git a/rust/Cargo.lock b/rust/Cargo.lock > index b785c718f31..aa13ab2a99a 100644 > --- a/rust/Cargo.lock > +++ b/rust/Cargo.lock > @@ -164,6 +164,10 @@ dependencies = [ > "unicode-ident", > ] > > +[[package]] > +name = "trace" > +version = "0.1.0" > + > [[package]] > name = "unicode-ident" > version = "1.0.12" > diff --git a/rust/Cargo.toml b/rust/Cargo.toml > index 99c275f2d9f..2be9f886113 100644 > --- a/rust/Cargo.toml > +++ b/rust/Cargo.toml > @@ -4,6 +4,7 @@ members = [ > "bits", > "qemu-api-macros", > "qemu-api", > + "trace", > "hw/char/pl011", > "hw/timer/hpet", > ] > diff --git a/rust/meson.build b/rust/meson.build > index 45936a0a731..2878bd8bc8d 100644 > --- a/rust/meson.build > +++ b/rust/meson.build > @@ -23,7 +23,7 @@ genrs = [] > subdir('qemu-api-macros') > subdir('bits') > subdir('qemu-api') > - > +subdir('trace') > subdir('hw') > > cargo = find_program('cargo', required: false) > diff --git a/rust/trace/Cargo.toml b/rust/trace/Cargo.toml > new file mode 100644 > index 00000000000..913010e9787 > --- /dev/null > +++ b/rust/trace/Cargo.toml > @@ -0,0 +1,16 @@ > +[package] > +name = "trace" > +version = "0.1.0" > +authors = ["Tanish Desai<tanishdesa...@gmail.com>"]
Missing space between name and angle bracket > +description = "rust trace library" Suggestion: > +description = "QEMU tracing infrastructure support" > +resolver = "2" > +publish = false > + > +edition.workspace = true > +homepage.workspace = true > +license.workspace = true > +repository.workspace = true > +rust-version.workspace = true > + > +[lints] > +workspace = true > diff --git a/rust/trace/meson.build b/rust/trace/meson.build > new file mode 100644 > index 00000000000..adca57e5507 > --- /dev/null > +++ b/rust/trace/meson.build > @@ -0,0 +1,19 @@ > +rust = import('rust') > + > +lib_rs = configure_file( > + input: 'src/lib.rs', > + output: 'lib.rs', > + configuration: { > + 'MESON_BUILD_ROOT': meson.project_build_root(), > + }) > + > +_trace_rs = static_library( > + 'trace', # Library name, > + lib_rs, > + trace_rs_targets, # List of generated `.rs` custom targets > + override_options: ['rust_std=2021', 'build.rust_std=2021'], > + dependencies: [libc_rs], > + rust_abi: 'rust', > +) > + > +trace_rs = declare_dependency(link_with: _trace_rs) > diff --git a/rust/trace/src/lib.rs b/rust/trace/src/lib.rs > new file mode 100644 > index 00000000000..9b931ddf1de > --- /dev/null > +++ b/rust/trace/src/lib.rs > @@ -0,0 +1,23 @@ > +//! This crate provides macros that aid in using QEMU's tracepoint > +//! functionality. Missing SPDX headers > + > +#[macro_export] > +/// Define the trace-points from the named directory (which should have > slashes Pedantic: s/trace-points/tracepoints > +/// replaced by underscore characters) as functions in a module called > `trace`. > +/// > +/// ```ignore > +/// ::trace::include_trace!("hw_char"); > +/// // ... > +/// trace::trace_pl011_read_fifo_rx_full(); > +/// ``` > +macro_rules! include_trace { > + ($name:literal) => { > + mod trace { > + #[cfg(not(MESON))] > + include!(concat!(env!("MESON_BUILD_ROOT"), "/trace/", $name, > ".rs")); > + > + #[cfg(MESON)] > + include!(concat!("@MESON_BUILD_ROOT@/trace/", $name, ".rs")); > + } > + }; > +} > diff --git a/trace/meson.build b/trace/meson.build > index 9c42a57a053..d89a0db82a1 100644 > --- a/trace/meson.build > +++ b/trace/meson.build > @@ -1,5 +1,5 @@ > system_ss.add(files('control-target.c', 'trace-hmp-cmds.c')) > - > +trace_rs_targets = [] > trace_events_files = [] > foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events > if item in qapi_trace_events > @@ -24,6 +24,11 @@ foreach item : [ '.' ] + trace_events_subdirs + > qapi_trace_events > input: trace_events_file, > command: [ tracetool, group, '--format=c', > '@INPUT@', '@OUTPUT@' ], > depend_files: tracetool_depends) > + trace_rs = custom_target(fmt.format('trace', 'rs'), > + output: fmt.format('trace', 'rs'), > + input: trace_events_file, > + command: [ tracetool, group, '--format=rs', > '@INPUT@', '@OUTPUT@' ], > + depend_files: tracetool_depends) > if 'ust' in get_option('trace_backends') > trace_ust_h = custom_target(fmt.format('trace-ust', 'h'), > output: fmt.format('trace-ust', 'h'), > @@ -34,6 +39,7 @@ foreach item : [ '.' ] + trace_events_subdirs + > qapi_trace_events > genh += trace_ust_h > endif > trace_ss.add(trace_h, trace_c) > + trace_rs_targets += trace_rs > if 'dtrace' in get_option('trace_backends') > trace_dtrace = custom_target(fmt.format('trace-dtrace', 'dtrace'), > output: fmt.format('trace-dtrace', > 'dtrace'), > -- > 2.50.1 > >