Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2383389rwb; Fri, 2 Dec 2022 09:04:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf5PD9ivYpdYGwU2EZpo7Vf2gOnjtyfQu5eclzeyJ8LAHzwHnCggRmRFSMwot0imwK1altsS X-Received: by 2002:a17:906:544b:b0:7c0:7e90:ec98 with SMTP id d11-20020a170906544b00b007c07e90ec98mr18041282ejp.537.1670000661982; Fri, 02 Dec 2022 09:04:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670000661; cv=none; d=google.com; s=arc-20160816; b=ZGa185SktM4WkGkQVDZio+ambUFSy5aCWY3BOfdlGWktkSNO78NemRf/Hr1OjRw3OV y3OkR9ga6pZswlpGZDktlEstSqETT2ylljkgBHNPd9vho5/bJWxrZLN6Hu0EhKJXCGMf td2LXD3EBSGq63i54gYaGxfgMmSfS2LHn5k4dxvmikqclWVsSeWmmCVvhHi+93DgYW7e HqZDAQOpbiBkOMX8KrIqdbMn3EnlMz5jxm6VJKMGSjp8MrGMiduAIzSm8PMJ4T5ZwyRu MPIdAFaRPolAX1UaT9XGwlcuhgAqaNtn0cUahsrNfHYx48HZb1uRdf5who8hIajZUGol lHCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SqCdk7fLDYqTKUouFEQZ1SeKBeTGRXZEAtJQ4n7vElU=; b=Z273fadleQWO5NSqiFuwlEk4UPWMEIK0/m9aRkDHehqtVr38CrvSBkpj1CHv7Xp/ut PVNbqeNOeIdV0Twi3viqkhJxf62d2kUZB9/RPERUpURhZ3oF4wZz+ouZssLuMe2RUlza r8HY8I85ERSP0C0j/tb4cB2xPlfcmnFa/spTc9VWHf/XE6YQ8WA0G6uPtmjfG/oJ6fzK x+fQ4U2G6y0nZC9nvg9kr4r7wqDwng8y9dkr6p1tYJqV+G1VbyWqHc5vrxRUTQK4P1yc 6mqmkpxi4Me0e82n7bUAEpumeWGsI6ccaD4z6tO6+1OgXpsBx/ckjy1xukVPM+N3ql0f e1oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GBYta338; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c12-20020a50d64c000000b00461be535949si6170521edj.424.2022.12.02.09.04.01; Fri, 02 Dec 2022 09:04:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GBYta338; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233824AbiLBQPz (ORCPT + 82 others); Fri, 2 Dec 2022 11:15:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233774AbiLBQPt (ORCPT ); Fri, 2 Dec 2022 11:15:49 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A03BEBBBD0; Fri, 2 Dec 2022 08:15:41 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3E208622E3; Fri, 2 Dec 2022 16:15:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E44DC433D6; Fri, 2 Dec 2022 16:15:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669997740; bh=4UfoqML4L3IukWfvADvLkrtuQak85Ze14tDrzQ5hdwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GBYta338nXNnuzZG7GDNq9PFxhM/cX92DH2AzsBGFI4iTieKuu1DUqzMRXV+nPWx5 7R/fiPYF8cjZQY36+UqacdBwgSgQQg8aQPTpxZ81tcSCjr4EUnhk3eo4ZZH9zDCkK+ 2o9va6KpTYjHgLKtiqZX8PwfW8wL5dc6ZsRkqTeyqU0fEC6mNzgZrod0nhUCv3WHrJ keudAiAD7Yx7UHhrOkYIUuYwdwQV+NaM+BFydjaZSSLC4hm0c/dQ0x97GqrkVCjo+K 4ZdmEA4t2NyS9PXASMMZYYPSd/cAu1gKw747T1i81cuvJX3084NFbeAAD2SyY0jlCC GFTdyIQCe2oqQ== From: ojeda@kernel.org To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Finn Behrens , Wei Liu , =?UTF-8?q?Sergio=20Gonz=C3=A1lez=20Collado?= Subject: [PATCH v2 04/28] rust: samples: add `rust_print` example Date: Fri, 2 Dec 2022 17:14:35 +0100 Message-Id: <20221202161502.385525-5-ojeda@kernel.org> In-Reply-To: <20221202161502.385525-1-ojeda@kernel.org> References: <20221202161502.385525-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miguel Ojeda Add example to exercise the printing macros (`pr_*!`) introduced in the previous patches. Reviewed-by: Finn Behrens Reviewed-by: Wei Liu Tested-by: Sergio González Collado Signed-off-by: Miguel Ojeda --- samples/rust/Kconfig | 10 +++++++ samples/rust/Makefile | 1 + samples/rust/rust_print.rs | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 samples/rust/rust_print.rs diff --git a/samples/rust/Kconfig b/samples/rust/Kconfig index 841e0906e943..b0f74a81c8f9 100644 --- a/samples/rust/Kconfig +++ b/samples/rust/Kconfig @@ -20,6 +20,16 @@ config SAMPLE_RUST_MINIMAL If unsure, say N. +config SAMPLE_RUST_PRINT + tristate "Printing macros" + help + This option builds the Rust printing macros sample. + + To compile this as a module, choose M here: + the module will be called rust_print. + + If unsure, say N. + config SAMPLE_RUST_HOSTPROGS bool "Host programs" help diff --git a/samples/rust/Makefile b/samples/rust/Makefile index 1daba5f8658a..03086dabbea4 100644 --- a/samples/rust/Makefile +++ b/samples/rust/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_SAMPLE_RUST_MINIMAL) += rust_minimal.o +obj-$(CONFIG_SAMPLE_RUST_PRINT) += rust_print.o subdir-$(CONFIG_SAMPLE_RUST_HOSTPROGS) += hostprogs diff --git a/samples/rust/rust_print.rs b/samples/rust/rust_print.rs new file mode 100644 index 000000000000..09f737790f3f --- /dev/null +++ b/samples/rust/rust_print.rs @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Rust printing macros sample. + +use kernel::pr_cont; +use kernel::prelude::*; + +module! { + type: RustPrint, + name: b"rust_print", + author: b"Rust for Linux Contributors", + description: b"Rust printing macros sample", + license: b"GPL", +} + +struct RustPrint; + +impl kernel::Module for RustPrint { + fn init(_module: &'static ThisModule) -> Result { + 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"); + + Ok(RustPrint) + } +} + +impl Drop for RustPrint { + fn drop(&mut self) { + pr_info!("Rust printing macros sample (exit)\n"); + } +} -- 2.38.1