aboutsummaryrefslogtreecommitdiff
path: root/samples/rust/rust_print.rs
diff options
context:
space:
mode:
authorMiguel Ojeda <[email protected]>2024-11-11 23:08:05 +0100
committerSteven Rostedt (Google) <[email protected]>2024-11-12 09:21:48 -0500
commit22193c586b43ee88d66954395885742a6e4a49a9 (patch)
tree9b5c3b8f1ca7a319e372722dac805cb9ed940454 /samples/rust/rust_print.rs
parent169484ab667788e73d1817d75c2a2c4af37dbc7f (diff)
samples: rust: fix `rust_print` build making it a combined module
The `rust_print` module, when built as a module, fails to build with: ERROR: modpost: missing MODULE_LICENSE() in samples/rust/rust_print_events.o ERROR: modpost: "__tracepoint_rust_sample_loaded" [samples/rust/rust_print.ko] undefined! ERROR: modpost: "rust_do_trace_rust_sample_loaded" [samples/rust/rust_print.ko] undefined! Fix it by building it as a combined one. Cc: Masami Hiramatsu <[email protected]> Cc: Alex Gaynor <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Boqun Feng <[email protected]> Cc: Gary Guo <[email protected]> Cc: Björn Roy Baron <[email protected]> Cc: Benno Lossin <[email protected]> Cc: Andreas Hindborg <[email protected]> Cc: Alice Ryhl <[email protected]> Cc: Trevor Gross <[email protected]> Cc: "Linux Next Mailing List" <[email protected]> Link: https://lore.kernel.org/[email protected] Reported-by: Stephen Rothwell <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Fixes: 91d39024e1b0 ("rust: samples: add tracepoint to Rust sample") Signed-off-by: Miguel Ojeda <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
Diffstat (limited to 'samples/rust/rust_print.rs')
-rw-r--r--samples/rust/rust_print.rs98
1 files changed, 0 insertions, 98 deletions
diff --git a/samples/rust/rust_print.rs b/samples/rust/rust_print.rs
deleted file mode 100644
index 6d14b08cac1c..000000000000
--- a/samples/rust/rust_print.rs
+++ /dev/null
@@ -1,98 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-//! Rust printing macros sample.
-
-use kernel::pr_cont;
-use kernel::prelude::*;
-
-module! {
- type: RustPrint,
- name: "rust_print",
- author: "Rust for Linux Contributors",
- description: "Rust printing macros sample",
- license: "GPL",
-}
-
-struct RustPrint;
-
-fn arc_print() -> Result {
- use kernel::sync::*;
-
- let a = Arc::new(1, GFP_KERNEL)?;
- let b = UniqueArc::new("hello, world", GFP_KERNEL)?;
-
- // Prints the value of data in `a`.
- pr_info!("{}", a);
-
- // Uses ":?" to print debug fmt of `b`.
- pr_info!("{:?}", b);
-
- let a: Arc<&str> = b.into();
- let c = a.clone();
-
- // Uses `dbg` to print, will move `c` (for temporary debugging purposes).
- dbg!(c);
-
- // Pretty-prints the debug formatting with lower-case hexadecimal integers.
- pr_info!("{:#x?}", a);
-
- Ok(())
-}
-
-impl kernel::Module for RustPrint {
- fn init(_module: &'static ThisModule) -> Result<Self> {
- pr_info!("Rust printing macros sample (init)\n");
-
- pr_emerg!("Emergency message (level 0) without args\n");
- pr_alert!("Alert message (level 1) without args\n");
- pr_crit!("Critical message (level 2) without args\n");
- pr_err!("Error message (level 3) without args\n");
- pr_warn!("Warning message (level 4) without args\n");
- pr_notice!("Notice message (level 5) without args\n");
- pr_info!("Info message (level 6) without args\n");
-
- pr_info!("A line that");
- pr_cont!(" is continued");
- pr_cont!(" without args\n");
-
- pr_emerg!("{} message (level {}) with args\n", "Emergency", 0);
- pr_alert!("{} message (level {}) with args\n", "Alert", 1);
- pr_crit!("{} message (level {}) with args\n", "Critical", 2);
- pr_err!("{} message (level {}) with args\n", "Error", 3);
- pr_warn!("{} message (level {}) with args\n", "Warning", 4);
- pr_notice!("{} message (level {}) with args\n", "Notice", 5);
- pr_info!("{} message (level {}) with args\n", "Info", 6);
-
- pr_info!("A {} that", "line");
- pr_cont!(" is {}", "continued");
- pr_cont!(" with {}\n", "args");
-
- arc_print()?;
-
- trace::trace_rust_sample_loaded(42);
-
- Ok(RustPrint)
- }
-}
-
-impl Drop for RustPrint {
- fn drop(&mut self) {
- pr_info!("Rust printing macros sample (exit)\n");
- }
-}
-
-mod trace {
- use core::ffi::c_int;
-
- kernel::declare_trace! {
- /// # Safety
- ///
- /// Always safe to call.
- unsafe fn rust_sample_loaded(magic: c_int);
- }
-
- pub(crate) fn trace_rust_sample_loaded(magic: i32) {
- // SAFETY: Always safe to call.
- unsafe { rust_sample_loaded(magic as c_int) }
- }
-}