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: 41098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2372296wrt; Mon, 9 Jan 2023 12:48:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXtk6Kux98nkh9+7PluhT37BVn0olFrq4BfW4fkOuc4MlPoXTeG6Ryu2PFiyBj1VxbhzjS6O X-Received: by 2002:a17:907:7d8f:b0:7c1:f63:8f66 with SMTP id oz15-20020a1709077d8f00b007c10f638f66mr29048902ejc.51.1673297326279; Mon, 09 Jan 2023 12:48:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673297326; cv=none; d=google.com; s=arc-20160816; b=jPz1udn8YezVcHG1ysGjq5wqwlzQp49num2218kDAVJKXDV50iin79eI7bNOFOd2Mi 6h9P+BiDukJLet/55msS/e2XfG5NnEUFlD7vm3Hr/eWoOSZ48mFMek3icr6W5pkBCQ+w y2iyPeMXaDqXu348nigsKej5QSRrHVyD34apySyXfcV6pfMEgnV8Ro4yAPi9FihPXC+R ukfZN9hrQo1XDf5OKzeh+wdW05A1jWw/JEoUr/q2fE7b6G76MhH1nfVyunDvg3cIZc3O cqC5RE0oeIbUtgJ64SLrm5CYgO5XQBbsihNZhN9Aq3wrtC2lAUfEFUJl0+I1SV+ikPUK HyLA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=NaSxqnXsRvl5Bhch3ZbBDYBWIfvwnRKqUqzNpWVIK1A=; b=vMSubReZxmS3AWPrsGgcZatCA9kUilEpTwBoDrbhwfJmyskPbqL9u/aBDYhN6k2KsX TFR7ahtgFXuD384H59gURZeOycNzjN8oNVWSZurqBvSkrkyS9kfji1LrhVktU1gq6p2/ X2KVuHF3SrxaA4hoBy+sd3i3IiSsCpOSAQwYf1B31F/qyz1PfgQF+GcKu63esnXAq0pm XYHKpVhPkYpfNDzWr0fpI2DfGZ5XCbxAU4m+dZ+53kOqd55SN+TjU5flAnN2XqteQce8 yGZ5Zi4xFYDNgCKaGPapv3hFhXu7bkOm/LtKAhcSnj0LMvGyLopfEzUoijCl6rRc470y n44g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="g6N3/ydS"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a20-20020a17090680d400b007a835c56b70si7674607ejx.267.2023.01.09.12.48.21; Mon, 09 Jan 2023 12:48:46 -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="g6N3/ydS"; 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 S234961AbjAIUp5 (ORCPT + 99 others); Mon, 9 Jan 2023 15:45:57 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754579417521860287?= X-GMAIL-MSGID: =?utf-8?q?1754579417521860287?= 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: 41099 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2372509wrt; Mon, 9 Jan 2023 12:49:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXsNFfstgswdEMCPzX3HhWdgQ57qv74IVnHTK613a+4kzJaygqX9LkeRflYZfg76kddrMIqd X-Received: by 2002:a17:90a:4ca7:b0:226:317f:f832 with SMTP id k36-20020a17090a4ca700b00226317ff832mr36873877pjh.39.1673297355366; Mon, 09 Jan 2023 12:49:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673297355; cv=none; d=google.com; s=arc-20160816; b=v2oLesHUHCQicVcdTM32y3g+SBLAXXmB6ngKUvEZn4C+Sj9HqUevW1o4jtXRMguMJ0 J345VZl6Jdnkg4uuhxKRFcs3AKahlUjRG5OgNVbz5N757O9tNLlMSRNmkB2inIZJX8Mn 3lJiWkbHl4sSu4JUOr1+Ra9RrVtxbo1vKR5WFME5+wUmdBck62ZV3Y1/2fQJsgBK8hDz bLiTWhLOjWw/e6odoCAZrbkhb07IhyqsO0cGYgv1Sht/EZzDIUI6XqsBevX1LbkM/Oow jgLrZJqEu4kNEQEbkek8Fny1RqmE1dduabw3noT0H+km7gTJKetr41+hhuFX5wCtI2Ij ThGw== 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=UIzHXeMh+WmxXiyMiBd962JvwNEAbvK4q/11EdNKzDg=; b=Sa9xV0t+/WsrYbiOueQ2iKMMYodQHeQQnIzWk5ZPSbuvsEVDTA7TDV6BNO5vOI5hoA tHa9LGg9OBT7U57NgEQ/8pTeLbc9vIaFiVDG8PeXC0doEujkgQ2tkhdRrvk5mpAR23Qz whNuYCyBvBcXrMRAHsCcwt3T2zNWC7AuMspOC8p7ydxNddeK99FuBf0vo1mYrWr5eDS1 fvXCXPpliZhTjF8bm13rbtjGjVlciAr7S7POkpeWrd12B4o9OCI2x537GX2zuGYAEmA2 CWH0YmNJ0rt533z8MVAb95nAYQK7hM61EZFNoj9A8q8Hb9QHgELnfoIAyZq52Gfw55Az 4b4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=joIuxGrR; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a15-20020a17090a8c0f00b0021a0bf0330esi9308808pjo.73.2023.01.09.12.49.03; Mon, 09 Jan 2023 12:49:15 -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=joIuxGrR; 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 S234687AbjAIUqC (ORCPT + 99 others); Mon, 9 Jan 2023 15:46:02 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754579447603551587?= X-GMAIL-MSGID: =?utf-8?q?1754579447603551587?= 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: 41096 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2372139wrt; Mon, 9 Jan 2023 12:48:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXsqEIfQ9YJcFWq7QIlbcrSHlOkQ98SXHzbyaLPJf0KYQcnRaVBv3zAWby6YB2kkA1Ugps6s X-Received: by 2002:a17:906:f6c5:b0:7c1:8704:80c4 with SMTP id jo5-20020a170906f6c500b007c1870480c4mr56626578ejb.47.1673297300851; Mon, 09 Jan 2023 12:48:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673297300; cv=none; d=google.com; s=arc-20160816; b=b79w7yMLaI3osWmMED38xHmzizJsKPeasRAjRpUGrIUVLMIOEqF3NsiBzxvgyQmeqx nmqGiUFSMX74KrMQhQ4uo8wS/ZJM7lVv3TJNoDvmmYwd0qhmj0V1wQRQQkdL/GN+eR5d iom+17aFcJVtDkeRCMFfcnBVWO01s715l9hu68+JibucPzYnjpD4G3NEoymLSP9MfBJm vMhE/bWHSMY8Ubz3TFRDbSC8g/zwwMt88Byhc/i4yXKLvIhy/b5MGCWCTX3ENjEFQNAs GLf5baYe4Qxu1oq8rO5IVm/HaFjAhOwghOEDaZC3H9xlhJZn6rxSZKjDuEbHJUM8cd9l iv6w== 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=ExgRow/fXtjzY4/sNs/xJc5DpTg7hISFra+/jeyvc9Y=; b=M7ypTNIoXe2DucfA/vXk+jHyLljiyH9055QjTRCg55OWzfd0S3arHQrDdVSB14Vtnx 3vklAMuD4khA8WtD2+961N7Zcabtg21D9BjDmV2rW4R/dQPY6IOm9jeIcLC19U7vvwTC 6xH+Br021X90AilyMxYVMsajpEuLNmejxZ+CsbrxAgZGezavTmXZsPxmfws/paakRWCd GKgAnuzPDt+Q25h45wNgi+rxJ3s9wsWWMgzFdUSK9AXUGuiv3avL2ngCgD32BRFGiwAt mSLYPXf2SqGSTfliw8s8KkVdd87lGRsLmWX7wEdvZDp8e8OyRL99fafV6vyGo7vvdjhz SSQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Xu9XkvS2; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hw19-20020a170907a0d300b007c0f7afccccsi7798831ejc.696.2023.01.09.12.47.56; Mon, 09 Jan 2023 12:48:20 -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=Xu9XkvS2; 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 S237345AbjAIUqT (ORCPT + 99 others); Mon, 9 Jan 2023 15:46:19 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754579390388707957?= X-GMAIL-MSGID: =?utf-8?q?1754579390388707957?= `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: 41095 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2371927wrt; Mon, 9 Jan 2023 12:47:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXv42VRtNKQW2dZj4piXlDsTEXWpf893DF2wQlg/GjcCYwWOg/qBeuLXMLtEikOY82PBtnvD X-Received: by 2002:a17:907:3888:b0:83f:757e:f182 with SMTP id sq8-20020a170907388800b0083f757ef182mr54196892ejc.65.1673297274451; Mon, 09 Jan 2023 12:47:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673297274; cv=none; d=google.com; s=arc-20160816; b=ruFPC9bNyrbqVvJT37uWvkYlWoCAwqYjij8wYlger/jEYYknSS+GqCrPg2aMp6t2XF 99oK3sQxNy9BUQ30OzH8gWXLBFzuQAwn3WeByzGiYbGzINJYAk9sPoAQQ5Rboki4QbGt NM+m9R8KlQ8CKqINpbBB4u73T3q19FVSSP+yOXgAxb5e3Gs5XUcSuVg6DAgx8/q0EN6u culPX2760dU/zzBJi4C3cypL6Al7Q+e6+NFrcFGSvg3KUSx4+BDnfBvEO5BBUEhrXpNp Kjz966dLGI0Ah32Tp6lJ45ZTjkr7tTVbDgUYmw1usNLzJSgpPLw6deRI88dq3VEXDRvx 5V2g== 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=ZWQ+MnRbIGzuWA7jC9vqyHBj2IYEPHPhMFNM/PxtaFs=; b=EHkFlmCXfROH3jAcNVd18oKa6HDO5F6AnzaeexEndrXQheGqUOasUY+87Rvw6LH2se DtezvPhnqyKTdKZnI2n5mx9j5+n25vwsvxKCoQLKmL7low2VV2Pq805OjoQ6sDkn5lC9 7joQZEoY5E67wZ7Qo08uoFdoqWdHzp+xGbHX5DBMNtNmeUbZHNRV9WvOQw+pho1jipQX uMfBCKcz8wjoqjAGw1VgnfwDNUvuKh2RSZ5iG+tXTWvMFprgQIOxRmQ4ZQCUCBudFZvI SOsTs65CzxMbxVyBYC1C5z2WPCypgytrmX73tDrGB6Ko3H79r/ogIPDGZu6bfOf3T0wZ m4ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pcpNnYrY; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc37-20020a17090716a500b007c10b6790bfsi11550213ejc.68.2023.01.09.12.47.30; Mon, 09 Jan 2023 12:47:54 -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=pcpNnYrY; 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 S237192AbjAIUqN (ORCPT + 99 others); Mon, 9 Jan 2023 15:46:13 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754579363005778129?= X-GMAIL-MSGID: =?utf-8?q?1754579363005778129?= 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: 41100 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2372793wrt; Mon, 9 Jan 2023 12:49:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXtUObgEtfqY1uT389s3PZOK4SFJ0JRd6RuVf8YQaIFcaKt3rH+DVbipz0qj85ZbKQMUu9Cb X-Received: by 2002:a17:90a:af85:b0:223:f385:bb72 with SMTP id w5-20020a17090aaf8500b00223f385bb72mr67499709pjq.49.1673297395594; Mon, 09 Jan 2023 12:49:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673297395; cv=none; d=google.com; s=arc-20160816; b=dzm+gprho7oDrY1Ya8iP6h4LYV/jSfRAW3svIFToT9hjyMWfk2KmVr9/X3bv0Bhqtu 9CQJ5scbaQddVsBCXJZ703oOdSJlD+OtUTucOUUFi338IWMaYKrBzxt6dW5sRweN99kx 4/Q3FbP1lHTNeMm0sIFpg5ImWIum8A2K97kK6+z487gCgTNmk+XGCcz0w9vQbHfakD35 +3gWDtUWabFMzpkzkoAX4bHWK77WKPCJsruEC/1/irO2zQNR0eZqyyjLAVH6nb896g7k 2186jR7oHAHlKAKwNYX4B0Z2h2aoBeZ3aQvNq9vbbhASl6HqPck/SqNCsGrkSXHqLJY0 NS/w== 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=9+W9jj4caIYbq0EH7wrqETCcuCmoDOwqCsIH3zHLq00=; b=oIrVH6u04YeZONabsG1ZQX6I0jyW/X2e4mLHfBq9gyoNh0ZpL5v5StVy3BRCTVZpmp uixEwKpmcODXjLck7Gbfis7gwi9C+XhNhkE7ahLsApLQODw+wKIC06ftY8dtGOubIOpW C7t/dvNtkktbTTOrDTzp1wVxWrOKQpG4QZhix8pHtFk5JBa+MqsvVpoRL7GvPoAsD07R gedNcIhioneIiCRhIe0TFLYoLpxE9d1j+4JxCw6rXiu3cKzePB6a5tpeK/zTy+F+yaQh kmvSSpTAk/CNZR4lQw4MCEpOkhTlTti/LozC1ZXuKWuYN53Nx1OvKBj5j2Ecc5edZvoM 64Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nU3KceGN; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s133-20020a632c8b000000b004ad1e82a3e6si8777677pgs.554.2023.01.09.12.49.43; Mon, 09 Jan 2023 12:49:55 -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=nU3KceGN; 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 S234593AbjAIUq0 (ORCPT + 99 others); Mon, 9 Jan 2023 15:46:26 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754579489520084990?= X-GMAIL-MSGID: =?utf-8?q?1754579489520084990?= `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: 41097 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2372222wrt; Mon, 9 Jan 2023 12:48:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXvBqE4roqqEoT94wSOQbISU4oTv6ERqHtnY5SXCiI4C0U/Z1sn5jLSNR44xxqEdrccQoe9f X-Received: by 2002:a05:6a20:3c91:b0:ad:5cde:8f05 with SMTP id b17-20020a056a203c9100b000ad5cde8f05mr100370622pzj.37.1673297313679; Mon, 09 Jan 2023 12:48:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673297313; cv=none; d=google.com; s=arc-20160816; b=vHBHkiDszZ2GY02lXbqUm1qj7anrbmuxkkgaNg82e9AhEgduVyqMvECZ0GhRAHPg7d JdPz8L6mzxQzjzHTtk/bA3pJwkYE5G8qjo1IfL5mivSyntdDIirPUcDcG8nfyHIwnL3M 6vSStsvWOyzPJ0pPR3vZ3K3BSFrQ06cOXX0aJgVK8Dt9KEHniU3hvaugVjMyWSjrJDrE q/E4Xe26QHC0P1m0v+sHNWO5wWF0+HB1v6bfVDHn2E7h255pAyL673rJfDUlnVBMjyJU Ryvwz1+p6W0rAbeMBq2FBH62RnXEJ1WABwlqZL/JMtyldJ4Me9cDvc6nORvQZw8ykKzR Nxag== 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=EtFaJKcTxXKYJFq4R2/6JUojLkJ+YIgcvPt2RKiRmMY=; b=PTz+CoB5DxBHQr9fSYYL/Pj+mZFtNO68BPEwqfUhaDuoMJWHkAM5+K73QCgxqtRyqU WliZT/kN1pqBGJOSe/mRBf/xNBn/6CbbkS9mJAb2IN5KHpmeZRW8z2H4CnWB9CCJ3+zC RV/TboqMVyN4kB5pPkmCgXGGn9YIUJx59Gx8YyznQvU9djF+F7Dcmd5KBS57oFcgVBcd hj9tyLSkBIQEwE+UiEsV1ABVGxjhAIhUDwqxxueI7XS4AMbH7puM7tJB2GCdiSD6fTCT oEbJnW7HEicXpc5uENN3h9gZNVfqsaK1XrofdCRGGHV56+cm9FAB6nzZECb8sZbGO8UB 2Zkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=md6E83gI; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u24-20020a63df18000000b00496731929d6si10032367pgg.780.2023.01.09.12.48.20; Mon, 09 Jan 2023 12:48:33 -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=md6E83gI; 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 S237490AbjAIUq3 (ORCPT + 99 others); Mon, 9 Jan 2023 15:46:29 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754579403625551622?= X-GMAIL-MSGID: =?utf-8?q?1754579403625551622?= 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'