Message ID | 20230109204520.539080-4-ojeda@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> 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 <rfc822;syz17693488234@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <ojeda@kernel.org> To: Masahiro Yamada <masahiroy@kernel.org> Cc: linux-kbuild@vger.kernel.org, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Nicolas Schier <nicolas@fjasle.eu>, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Miguel Ojeda <ojeda@kernel.org>, Alex Gaynor <alex.gaynor@gmail.com>, Wedson Almeida Filho <wedsonaf@gmail.com>, Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>, =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com> 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 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: <linux-kernel.vger.kernel.org> 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?= |
Series |
[1/6] docs: rust: add paragraph about finding a suitable `libclang`
|
|
Commit Message
Miguel Ojeda
Jan. 9, 2023, 8:45 p.m. UTC
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 <ojeda@kernel.org>
---
scripts/rust_is_available.sh | 10 ++++++++++
1 file changed, 10 insertions(+)
Comments
On Tue, Jan 10, 2023 at 5:46 AM Miguel Ojeda <ojeda@kernel.org> wrote: > > 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 <ojeda@kernel.org> > --- > 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 I do not like this. We do not need to cater to every oddity. Checking MAKEFLAGS is too much. You can check RUSTC/BINDGEN/CC if you persist in this. diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index a6f84dd2f71c..524aee03384a 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -34,7 +34,7 @@ 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 +if ! command -v "${RUSTC:?RUSTC is not set}" >/dev/null; then echo >&2 "***" echo >&2 "*** Rust compiler '$RUSTC' could not be found." echo >&2 "***" @@ -42,7 +42,7 @@ if ! command -v "$RUSTC" >/dev/null; then fi # Check that the Rust bindings generator exists. -if ! command -v "$BINDGEN" >/dev/null; then +if ! command -v "${BINDGEN:?BINDGEN is not set}" >/dev/null; then echo >&2 "***" echo >&2 "*** Rust bindings generator '$BINDGEN' could not be found." echo >&2 "***" @@ -150,7 +150,7 @@ fi # # In the future, we might be able to perform a full version check, see # https://github.com/rust-lang/rust-bindgen/issues/2138. -cc_name=$($(dirname $0)/cc-version.sh "$CC" | cut -f1 -d' ') +cc_name=$($(dirname $0)/cc-version.sh ${CC:?CC is not set} | cut -f1 -d' ') if [ "$cc_name" = Clang ]; then clang_version=$( \ LC_ALL=C "$CC" --version 2>/dev/null \
On Thu, Jan 12, 2023 at 6:29 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > I do not like this. > We do not need to cater to every oddity. > > Checking MAKEFLAGS is too much. I agree we should not attempt to catch every possible mistake in the script, but there have been several people hitting precisely this case (the latest is in the linked thread in the commit message), i.e. some people read the `Makefile` and notice the script invocation, and go execute it, but they are unlikely to be aware of the target in that case. > You can check RUSTC/BINDGEN/CC if you persist in this. This is fine, and actually we should do it regardless of `MAKEFLAGS`. I can add it to v2. However, that does not cover the same thing as `MAKEFLAGS` is trying to here. The reason is that even if they see e.g. "RUSTC is not set", they will not know about how to call the script properly, i.e. through the `Makefile` target. For `RUSTC` and `BINDGEN`, it does not really matter (and we could give a default to the variable, since the name rarely would be different). However, for `CC`, the logic that Kbuild uses is more complex, so it seems best to me to let Kbuild tell us what the actual compiler is. Cheers, Miguel
On Sat, Jan 14, 2023 at 8:12 AM Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote: > > On Thu, Jan 12, 2023 at 6:29 AM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > I do not like this. > > We do not need to cater to every oddity. > > > > Checking MAKEFLAGS is too much. > > I agree we should not attempt to catch every possible mistake in the > script, but there have been several people hitting precisely this case > (the latest is in the linked thread in the commit message), i.e. some > people read the `Makefile` and notice the script invocation, and go > execute it, but they are unlikely to be aware of the target in that > case. > > > You can check RUSTC/BINDGEN/CC if you persist in this. > > This is fine, and actually we should do it regardless of `MAKEFLAGS`. > I can add it to v2. > > However, that does not cover the same thing as `MAKEFLAGS` is trying > to here. The reason is that even if they see e.g. "RUSTC is not set", > they will not know about how to call the script properly, i.e. through > the `Makefile` target. > > For `RUSTC` and `BINDGEN`, it does not really matter (and we could > give a default to the variable, since the name rarely would be > different). However, for `CC`, the logic that Kbuild uses is more > complex, so it seems best to me to let Kbuild tell us what the actual > compiler is. > > Cheers, > Miguel OK, you maintain this script, so it is up to you.
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 "***"