From patchwork Mon Jan 9 20:45:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13094255 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B9FCC54EBD for ; Mon, 9 Jan 2023 20:45:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237069AbjAIUpy (ORCPT ); Mon, 9 Jan 2023 15:45:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231290AbjAIUpx (ORCPT ); Mon, 9 Jan 2023 15:45:53 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D988240; Mon, 9 Jan 2023 12:45:50 -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 E633E613EA; Mon, 9 Jan 2023 20:45:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9624C433EF; Mon, 9 Jan 2023 20:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673297149; bh=7uir+fpWvzx/j9KVXbIqIv40RM5gM3COk4tThC15780=; h=From:To:Cc:Subject:Date:From; b=g6N3/ydSgf1ekjlEVVfHIsbM86g99kyRUChoRdZg9dF1V/YnyOisYY37+GmhiitC0 Jdi2fKYCxTR6yF2oF3U/V0kkuRBNpAVyrGOiqqVN4JpG6eGFBVbNFBPsOHQSc17+Vh lNaZxi1Dt9tvPKNvDjwQJ/6lv0fPjQGtuA3lfiiPTgOB3RZLYuYpvrrMsjEILsl8qI QuDZ0h1vJ7mq97UjXtbliAoUDQc6j8sjYcuAkg/KbYgpKCbjPb1lBS2UTe6sN8SZZ+ 83WGp3wKWYw6yURHS1NMI9AG1KA78Jh38A6ktiB7Obi8hyEL74pZ22Jywp1NEdzJtS zQWuLBcrUi58A== From: Miguel Ojeda To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Jonathan Corbet , linux-doc@vger.kernel.org Subject: [PATCH 1/6] docs: rust: add paragraph about finding a suitable `libclang` Date: Mon, 9 Jan 2023 21:45:15 +0100 Message-Id: <20230109204520.539080-1-ojeda@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Sometimes users need to tweak the finding process of `libclang` for `bindgen` via the `clang-sys`-provided environment variables. Thus add a paragraph to the setting up guide, including a reference to `clang-sys`'s relevant documentation. Link: https://lore.kernel.org/rust-for-linux/CAKwvOdm5JT4wbdQQYuW+RT07rCi6whGBM2iUAyg8A1CmLXG6Nw@mail.gmail.com/ Signed-off-by: Miguel Ojeda Reviewed-by: Nick Desaulniers --- Documentation/rust/quick-start.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Documentation/rust/quick-start.rst b/Documentation/rust/quick-start.rst index 13b7744b1e27..cae21ea7de41 100644 --- a/Documentation/rust/quick-start.rst +++ b/Documentation/rust/quick-start.rst @@ -100,6 +100,23 @@ Install it via (note that this will download and build the tool from source):: cargo install --locked --version $(scripts/min-tool-version.sh bindgen) bindgen +``bindgen`` needs to find a suitable ``libclang`` in order to work. If it is +not found (or a different ``libclang`` than the one found should be used), +the process can be tweaked using the environment variables understood by +``clang-sys`` (the Rust bindings crate that ``bindgen`` uses to access +``libclang``): + +* ``LLVM_CONFIG_PATH`` can be pointed to an ``llvm-config`` executable. + +* Or ``LIBCLANG_PATH`` can be pointed to a ``libclang`` shared library + or to the directoy containing it. + +* Or ``CLANG_PATH`` can be pointed to a ``clang`` executable. + +For details, please see ``clang-sys``'s documentation at: + + https://github.com/KyleMayes/clang-sys#environment-variables + Requirements: Developing ------------------------ From patchwork Mon Jan 9 20:45:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13094256 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BAA5C6379F for ; Mon, 9 Jan 2023 20:45:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237448AbjAIUp5 (ORCPT ); Mon, 9 Jan 2023 15:45:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237192AbjAIUpz (ORCPT ); Mon, 9 Jan 2023 15:45:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF69F62FE; Mon, 9 Jan 2023 12:45:53 -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 52BCB61382; Mon, 9 Jan 2023 20:45:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9657BC43392; Mon, 9 Jan 2023 20:45:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673297152; bh=LCRoPeTwrC31kot3bkZJTgLAtW3tVrcvr9oxCjUlPug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=joIuxGrRRHxlz/LHzLfHL8vXgqxQ5d5ue785wVNfBHRyqPn+LRHjdIKEP/HFX11g7 /aSF8I6k3f08NT1tgses8SiZIIMQGSXCfhDxlbQAIZqtOQINrG8wd5IiM6SPVu1mrY +hfesN/Di60BfYfFSuM2prNK6rRjIFadeTi2VfMk7j+BHaxsfbswTLTb/lbmOCisI9 FcsnM6mPl7jp6AESLUgAuV6GoIeZMMMZ8P0WCyJxRYQP0kHtgbu8Z2IMqfpHdpASR9 0lXi6CkryF3XQ41j4yLoxQMoYe3e56azmfKKpn7v2xNuDdfUBz8QrKn6mp4JCf52RQ pWqX0u2BBYZnA== From: Miguel Ojeda To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= Subject: [PATCH 2/6] kbuild: rust_is_available: print docs reference Date: Mon, 9 Jan 2023 21:45:16 +0100 Message-Id: <20230109204520.539080-2-ojeda@kernel.org> In-Reply-To: <20230109204520.539080-1-ojeda@kernel.org> References: <20230109204520.539080-1-ojeda@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org People trying out the Rust support in the kernel may get warnings and errors from `scripts/rust_is_available.sh` from the `rustavailable` target or the build step. Some of those users may be following the Quick Start guide, but others may not (likely those getting warnings from the build step instead of the target). While the messages are fairly clear on what the problem is, it may not be clear how to solve the particular issue, especially for those not aware of the documentation. We could add all sorts of details on the script for each one, but it is better to point users to the documentation instead, where it is easily readable in different formats. It also avoids duplication. Thus add a reference to the documentation whenever the script fails or there is at least a warning. Signed-off-by: Miguel Ojeda Reviewed-by: Finn Behrens --- Note that is based on top of patch "kbuild: rust: remove -v option of scripts/rust_is_available.sh" applied on v6.2-rc3: https://lore.kernel.org/rust-for-linux/20230109061436.3146442-1-masahiroy@kernel.org/ scripts/rust_is_available.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index eaeafebf8572..c907cf881c2c 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -21,6 +21,20 @@ get_canonical_version() echo $((100000 * $1 + 100 * $2 + $3)) } +# Print a reference to the setup guide in the documentation. +print_docs_reference() +{ + echo >&2 "***" + echo >&2 "*** Please see Documentation/rust/quick-start.rst for details" + echo >&2 "*** on how to setup Rust support." + echo >&2 "***" +} + +# If the script fails for any reason, or if there was any warning, then +# print a reference to the documentation on exit. +warning=0 +trap 'if [ $? -ne 0 ] || [ $warning -ne 0 ]; then print_docs_reference; fi' EXIT + # Check that the Rust compiler exists. if ! command -v "$RUSTC" >/dev/null; then echo >&2 "***" @@ -62,6 +76,7 @@ if [ "$rust_compiler_cversion" -gt "$rust_compiler_min_cversion" ]; then echo >&2 "*** Your version: $rust_compiler_version" echo >&2 "*** Expected version: $rust_compiler_min_version" echo >&2 "***" + warning=1 fi # Check that the Rust bindings generator is suitable. @@ -89,6 +104,7 @@ if [ "$rust_bindings_generator_cversion" -gt "$rust_bindings_generator_min_cvers echo >&2 "*** Your version: $rust_bindings_generator_version" echo >&2 "*** Expected version: $rust_bindings_generator_min_version" echo >&2 "***" + warning=1 fi # Check that the `libclang` used by the Rust bindings generator is suitable. @@ -128,6 +144,7 @@ if [ "$cc_name" = Clang ]; then echo >&2 "*** libclang version: $bindgen_libclang_version" echo >&2 "*** Clang version: $clang_version" echo >&2 "***" + warning=1 fi fi From patchwork Mon Jan 9 20:45:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13094258 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80942C5479D for ; Mon, 9 Jan 2023 20:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237678AbjAIUqM (ORCPT ); Mon, 9 Jan 2023 15:46:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237556AbjAIUqB (ORCPT ); Mon, 9 Jan 2023 15:46:01 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36C063D5D0; Mon, 9 Jan 2023 12:45:58 -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 ams.source.kernel.org (Postfix) with ESMTPS id 5ACEDB80FE1; Mon, 9 Jan 2023 20:45:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04D07C433F2; Mon, 9 Jan 2023 20:45:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673297156; bh=/mRvhEXfYmI5Ul0O7z4JhnCdPQzvBa89XuNNnjPrSOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xu9XkvS2/GRUYf6ySXBmXi7SSOMyJmp6WOLOctFABGxpIVubOVckX8L6SYSrWSn4N 7MyXNjiO1/ywsAsw98zUeh+3JBPlUlxbtx+Iv0wl0NFwsbrPNYBZ+VCqXqSoWMA1FO LlFggKuclGea/ZnE4ZkoXL+lRf2xl6H24GXw5Byv0KH2tIQQ8p+I+JMLIWoWmbQu2v WWSlSrQlCrfsAvyOnopxDa6qddozWas+Ki2iFQessU5RUvPKwyQvKurqtvK59HE9j7 Ldrv83+dNi5sziZL6B/I8Tdy+cTSzQTat0lJl97wYUNpZ8O7vrpZxURqMcADGuX0N4 5UQgwR4TQGE9w== From: Miguel Ojeda To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda , Alexandru Radovici , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= Subject: [PATCH 3/6] kbuild: rust_is_available: add check for `bindgen` invocation Date: Mon, 9 Jan 2023 21:45:17 +0100 Message-Id: <20230109204520.539080-3-ojeda@kernel.org> In-Reply-To: <20230109204520.539080-1-ojeda@kernel.org> References: <20230109204520.539080-1-ojeda@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org `scripts/rust_is_available.sh` calls `bindgen` with a special header in order to check whether the `libclang` version in use is suitable. However, the invocation itself may fail if, for instance, `bindgen` cannot locate `libclang`. This is fine for Kconfig (since the script will still fail and therefore disable Rust as it should), but it is pretty confusing for users of the `rustavailable` target given the error will be unrelated: ./scripts/rust_is_available.sh: 21: arithmetic expression: expecting primary: "100000 * + 100 * + " make: *** [Makefile:1816: rustavailable] Error 2 Instead, run the `bindgen` invocation independently in a previous step, saving its output and return code. If it fails, then show the user a proper error message. Otherwise, continue as usual with the saved output. Since the previous patch we show a reference to the docs, and the docs now explain how `bindgen` looks for `libclang`, thus the error message can leverage the documentation, avoiding duplication here (and making users aware of the setup guide in the documentation). Reported-by: Nick Desaulniers Reported-by: fvalenduc (@fvalenduc) Reported-by: Alexandru Radovici Link: https://lore.kernel.org/rust-for-linux/CAKwvOdm5JT4wbdQQYuW+RT07rCi6whGBM2iUAyg8A1CmLXG6Nw@mail.gmail.com/ Link: https://github.com/Rust-for-Linux/linux/issues/934 Link: https://github.com/Rust-for-Linux/linux/pull/921 Signed-off-by: Miguel Ojeda --- scripts/rust_is_available.sh | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index c907cf881c2c..cd87729ca3bf 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -108,8 +108,29 @@ if [ "$rust_bindings_generator_cversion" -gt "$rust_bindings_generator_min_cvers fi # Check that the `libclang` used by the Rust bindings generator is suitable. +# +# In order to do that, first invoke `bindgen` to get the `libclang` version +# found by `bindgen`. This step may already fail if, for instance, `libclang` +# is not found, thus inform the user in such a case. +set +e +bindgen_libclang_output=$(LC_ALL=C "$BINDGEN" $(dirname $0)/rust_is_available_bindgen_libclang.h 2>&1 >/dev/null) +bindgen_libclang_code=$? +set -e +if [ $bindgen_libclang_code -ne 0 ]; then + echo >&2 "***" + echo >&2 "*** Running '$BINDGEN' to check the libclang version (used by the Rust" + echo >&2 "*** bindings generator) failed with code $bindgen_libclang_code. This may be caused by" + echo >&2 "*** a failure to locate libclang. See output and docs below for details:" + echo >&2 "***" + echo >&2 "$bindgen_libclang_output" + echo >&2 "***" + exit 1 +fi + +# `bindgen` returned successfully, thus use the output to check that the version +# of the `libclang` found by the Rust bindings generator is suitable. bindgen_libclang_version=$( \ - LC_ALL=C "$BINDGEN" $(dirname $0)/rust_is_available_bindgen_libclang.h 2>&1 >/dev/null \ + echo "$bindgen_libclang_output" \ | grep -F 'clang version ' \ | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ | head -n 1 \ From patchwork Mon Jan 9 20:45:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13094257 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C84CC54EBD for ; Mon, 9 Jan 2023 20:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237628AbjAIUqL (ORCPT ); Mon, 9 Jan 2023 15:46:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235381AbjAIUqC (ORCPT ); Mon, 9 Jan 2023 15:46:02 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62038687A1; Mon, 9 Jan 2023 12:46:00 -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 27C936136C; Mon, 9 Jan 2023 20:46:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F42AC433D2; Mon, 9 Jan 2023 20:45:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673297159; bh=+4zz4idSaVuP74R5VBf82uZ0IOSqSMwHAWJZxvct/Dk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pcpNnYrYbId9bog3bv+J9Rh4LGvuYAcglUACV1lIg+8GRND1nayRRbowRjfQ3GpzQ +zOkim+iT26EYBITxs3imrZb9XTwcFPMWfOhYf4noT0oLelYtT0ZDTzuO7aEzqh4NQ YSCizcO1OwEGO/0SQ5bJ07Z1WMGAQrQqxj6Sql0C+bth7Lyu0+vQDmoVqiEJv4r00s lBZZvzF6om4TBinuPFGp0y6/q8mYIBTlcm3epoFPeqiEbL7eqv2xwR8LRfXrA9AjDY +sFUM8av4TGSSeEsYIADOdAY8z/sea/YEVg2WT3I+mAbchJFa6Qmu2ldomoBerqdet EUdi1PwK0wmMA== From: Miguel Ojeda To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= Subject: [PATCH 4/6] kbuild: rust_is_available: check if the script was invoked from Kbuild Date: Mon, 9 Jan 2023 21:45:18 +0100 Message-Id: <20230109204520.539080-4-ojeda@kernel.org> In-Reply-To: <20230109204520.539080-1-ojeda@kernel.org> References: <20230109204520.539080-1-ojeda@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Sometimes [1] users may attempt to setup the Rust support by checking what Kbuild does and they end up finding out about `scripts/rust_is_available.sh`. Inevitably, they run the script directly, but unless they setup the required variables, the result of the script is not meaningful. We could add some defaults to the variables, but that could be confusing for those that may override the defaults (compared to their kernel builds), and `$CC` would not be a simple default in any case. Therefore, instead, print a warning when the script detects the user may be invoking it, by testing `$MAKEFLAGS`. Link: https://lore.kernel.org/oe-kbuild-all/Y6r4mXz5NS0+HVXo@zn.tnic/ [1] Signed-off-by: Miguel Ojeda --- scripts/rust_is_available.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index cd87729ca3bf..0c082a248f15 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -35,6 +35,16 @@ print_docs_reference() warning=0 trap 'if [ $? -ne 0 ] || [ $warning -ne 0 ]; then print_docs_reference; fi' EXIT +# Check whether the script was invoked from Kbuild. +if [ -z "${MAKEFLAGS+x}" ]; then + echo >&2 "***" + echo >&2 "*** This script is intended to be called from Kbuild." + echo >&2 "*** Please use the 'rustavailable' target to call it instead." + echo >&2 "*** Otherwise, the results may not be meaningful." + echo >&2 "***" + warning=1 +fi + # Check that the Rust compiler exists. if ! command -v "$RUSTC" >/dev/null; then echo >&2 "***" From patchwork Mon Jan 9 20:45:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13094260 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0F1AC54EBD for ; Mon, 9 Jan 2023 20:46:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237606AbjAIUqR (ORCPT ); Mon, 9 Jan 2023 15:46:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237666AbjAIUqL (ORCPT ); Mon, 9 Jan 2023 15:46:11 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A06573E3A; Mon, 9 Jan 2023 12:46:05 -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 ams.source.kernel.org (Postfix) with ESMTPS id 2979DB80FE1; Mon, 9 Jan 2023 20:46:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F207FC433F0; Mon, 9 Jan 2023 20:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673297162; bh=v6aIwGe42UpqRaNoSLoyuLZZtQ4F5eJRx+9gWWQ/eO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nU3KceGNxWBQHIw4s9cYt/+dB4mBbRCcVDxEWhD97wuWQx1pW1cuVmiFxvPG9ovqa LxqUYYF5JfpArpnr/OW8MnFdtsjss8Ty3NY+79and96nOyJw7ZDi0QG1HW99e1fvst Gywb+jPHB/nGT9VLU29DM6/QAjgWK7ILl8TDVMoxnPgBccHuG757H4SivxGK2bBnEa 2WjPHnV4T1u27okoMT6T2s++THucuyYlW1KeKmoel2+tv4sTATR1t1zRIGjjBDDDAh Bzn8HdMYfZXbz6+btbSMvCHuYP3rH08v98r9FFecybgSZWb2IJU7KfqJ+0OynWfB7B ObscqPXnQLETw== From: Miguel Ojeda To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= Subject: [PATCH 5/6] kbuild: rust_is_available: fix confusion when a version appears in the path Date: Mon, 9 Jan 2023 21:45:19 +0100 Message-Id: <20230109204520.539080-5-ojeda@kernel.org> In-Reply-To: <20230109204520.539080-1-ojeda@kernel.org> References: <20230109204520.539080-1-ojeda@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org `bindgen`'s output for `libclang`'s version check contains paths, which in turn may contain strings that look like version numbers [1]: .../6.1.0-dev/.../rust_is_available_bindgen_libclang.h:2:9: warning: clang version 11.1.0 [-W#pragma-messages], err: false which the script will pick up as the version instead of the latter. It is also the case that versions may appear after the actual version (e.g. distribution's version text), which was the reason behind `head` [2]: .../rust-is-available-bindgen-libclang.h:2:9: warning: clang version 13.0.0 (Fedora 13.0.0-3.fc35) [-W#pragma-messages], err: false Thus instead ask for a match after the `clang version` string. Reported-by: Jordan (@jordanisaacs) Link: https://github.com/Rust-for-Linux/linux/issues/942 [1] Link: https://github.com/Rust-for-Linux/linux/pull/789 [2] Signed-off-by: Miguel Ojeda --- scripts/rust_is_available.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index 0c082a248f15..a86659410e48 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -141,9 +141,7 @@ fi # of the `libclang` found by the Rust bindings generator is suitable. bindgen_libclang_version=$( \ echo "$bindgen_libclang_output" \ - | grep -F 'clang version ' \ - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ - | head -n 1 \ + | sed -nE 's:.*clang version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) bindgen_libclang_min_version=$($min_tool_version llvm) bindgen_libclang_cversion=$(get_canonical_version $bindgen_libclang_version) From patchwork Mon Jan 9 20:45:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 13094259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E68E7C5479D for ; Mon, 9 Jan 2023 20:46:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235367AbjAIUqT (ORCPT ); Mon, 9 Jan 2023 15:46:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230179AbjAIUqM (ORCPT ); Mon, 9 Jan 2023 15:46:12 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7FC6755D7; Mon, 9 Jan 2023 12:46:08 -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 ams.source.kernel.org (Postfix) with ESMTPS id 88F6BB80FE9; Mon, 9 Jan 2023 20:46:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B2F0C433EF; Mon, 9 Jan 2023 20:46:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673297166; bh=UwE38YioG9dTqnBwoYpucHihCJ8r0LAOxRgPcDdHqlg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=md6E83gIPs0q+cIi9mPU6xAs1exMIZwpNLcjfKZj9ntwkm+sTaENDo6dkGPwVXN6U Xw/8oJ+EYwdci1GfgUC31xhejRtHJo4niR8nZRaLcU63lYtYHW2aPcchBBA+MiinxJ A4vteyRB/s7a8KGj0QknTLQlXG4ZzIfwj9M5Q2ojzSIy6b3QpJqSYhq/n4PdIKTRgy zx7ymJQbnBZb2e3VbPws2+xMh6/gQWxSkubLZcWkTk5GfZ80hQd9dIJeQpxzvS/q6q Xpg9ugardquGSdJlGp1qZTjLyy8kLpKTLvdHHON4ppoE29OE8szZZVBOPLcOeszj5N aV3yOENwkKJkQ== From: Miguel Ojeda To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= Subject: [PATCH 6/6] kbuild: rust_is_available: normalize version matching Date: Mon, 9 Jan 2023 21:45:20 +0100 Message-Id: <20230109204520.539080-6-ojeda@kernel.org> In-Reply-To: <20230109204520.539080-1-ojeda@kernel.org> References: <20230109204520.539080-1-ojeda@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org In order to match the version string, `sed` is used in a couple cases, and `grep` and `head` in a couple others. Make the script more consistent and easier to understand by using the same method, `sed`, for all of them. This makes the version matching also a bit more strict for the changed cases, since the strings `rustc ` and `bindgen ` will now be required, which should be fine since `rustc` complains if one attempts to call it with another program name, and `bindgen` uses a hardcoded string. In addition, clarify why one of the existing `sed` commands does not provide an address like the others. Signed-off-by: Miguel Ojeda --- scripts/rust_is_available.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index a86659410e48..99811842b61f 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -66,8 +66,7 @@ fi # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. rust_compiler_version=$( \ LC_ALL=C "$RUSTC" --version 2>/dev/null \ - | head -n 1 \ - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ + | sed -nE '1s:.*rustc ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) rust_compiler_min_version=$($min_tool_version rustc) rust_compiler_cversion=$(get_canonical_version $rust_compiler_version) @@ -94,8 +93,7 @@ fi # Non-stable and distributions' versions may have a version suffix, e.g. `-dev`. rust_bindings_generator_version=$( \ LC_ALL=C "$BINDGEN" --version 2>/dev/null \ - | head -n 1 \ - | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' \ + | sed -nE '1s:.*bindgen ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p' ) rust_bindings_generator_min_version=$($min_tool_version bindgen) rust_bindings_generator_cversion=$(get_canonical_version $rust_bindings_generator_version) @@ -139,6 +137,9 @@ fi # `bindgen` returned successfully, thus use the output to check that the version # of the `libclang` found by the Rust bindings generator is suitable. +# +# Unlike other version checks, note that this one does not necessarily appear +# in the first line of the output, thus no `sed` address is provided. bindgen_libclang_version=$( \ echo "$bindgen_libclang_output" \ | sed -nE 's:.*clang version ([0-9]+\.[0-9]+\.[0-9]+).*:\1:p'