Message ID | 20230616001631.463536-7-ojeda@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp999793vqr; Thu, 15 Jun 2023 17:26:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5CzoEvitgSdPtZjtnPpmKairbo6JHnxSn5SrcLt2FkKEYw1SGY6Sbg76VNJUWMgpBp/ZIY X-Received: by 2002:a17:903:25c9:b0:1b5:694:b1a9 with SMTP id jc9-20020a17090325c900b001b50694b1a9mr500596plb.32.1686875186663; Thu, 15 Jun 2023 17:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686875186; cv=none; d=google.com; s=arc-20160816; b=pmxwvsWtulc3I6REvuLSjc9N50ezMJHKtZnJHq4JF6DP51tKMIQ/jHtplL5a0kOFiy SXY43iPfcMiGjvDQKcIZEEDvsLBntRVbO2zfdooOqT2AVYt44Kh6woz3SXA+pLKzLXqv 5J6TVz73GGVg3pmPTjmzH7Wn3HfOQZsYG5td7MQiP/0lJt7sNPP7aZ5hDLkSPKN9PO9g 2RyZNnojU4CMMHobq7MizPkOKBdLyhD+j/a+Ox8cku/Gdx6J4CLNoiO6RCaMUme6QRO+ aHefeYiQfdf+2p6BbmNeAzDlgfsrwgkEtZH7Ja6m9RkkhE+JyZpfYzeJqGOApMxic+vD UB/Q== 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=/PdUvf9y38LlACR4AVgv6c3lD3R0OxFrRRNbyeSS3zs=; b=K4bMpU68HRwr6lHsud1Yexah22d5DqyO08EZluOg6wI2QOQvjFghdCTqRQuOkafNp8 OcQ8ZOM7RFJkrp17CAa+jQI6c5TscAV5XtLPfHfiY2HPRJaucFEubG4E7+rAnZ6N6Z/P LLSw/vGd4JQOck5uRJlWy3xIkruX2a6N8sbT1iTWhtmABzNofmaAL9MSQ8OYvCr1IKOI hgdWy1wS5eRGaA2v1YWS8M/Gawm/lWs1DOXhrWAxAHa8/1c1HPMXO76+DSbjPbXxfJIa Y0SllG9Wevx3U/kcQpcZ2fpJ3Stu77LHmgHqkjr31qZX37seFwSLeJUVpzym0ZQdBvK7 iyBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="XFjIS/ya"; 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 i13-20020a17090332cd00b001addf547a59si10367418plr.0.2023.06.15.17.26.13; Thu, 15 Jun 2023 17:26:26 -0700 (PDT) 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="XFjIS/ya"; 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 S240673AbjFPARm (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Thu, 15 Jun 2023 20:17:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239772AbjFPARk (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 15 Jun 2023 20:17:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68CF72D68; Thu, 15 Jun 2023 17:17:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8806261C11; Fri, 16 Jun 2023 00:17:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E332BC433C8; Fri, 16 Jun 2023 00:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686874640; bh=aBzh/Fxzic0miW7yv3POPGW0A64Wwiniim+c1dkYLiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XFjIS/yatBcC0vfZLDmGR7QeKsj8ZbBxd2HTcqyKH23qvQNMdnvuB2gh+r4kUPNUk 4/7k93BSX25IIwWtbQtq7AXQZMsXp86kDjEZqYXgO4QnCzgSossGvhPlCZS5rmfrC5 GDqpOAAo8ueR03U93/O3j5mEiVDAZgkocmWWw5x+WDmgxa6te+mBI3A1l5f2iOSbIU b0TuST7+0xT8+kzNQ578ITVzRQg8qayrqXgmEOyItmjaSaPg2nLntH3uyV/mXLZsC6 VOj9mzgHU1iT3MlVcgRkLobHnDjp+UDFN4+hlxcP3+7h88Y0PkdbYbWl9GbGkiK90y JsLznxCiKIGWw== From: Miguel Ojeda <ojeda@kernel.org> To: Masahiro Yamada <masahiroy@kernel.org>, Miguel Ojeda <ojeda@kernel.org>, Wedson Almeida Filho <wedsonaf@gmail.com>, Alex Gaynor <alex.gaynor@gmail.com> Cc: Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Nicolas Schier <nicolas@fjasle.eu>, Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>, =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= <bjorn3_gh@protonmail.com>, Benno Lossin <benno.lossin@proton.me>, Alice Ryhl <aliceryhl@google.com>, Andreas Hindborg <nmi@metaspace.dk>, linux-kbuild@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH v2 06/11] kbuild: rust_is_available: check that environment variables are set Date: Fri, 16 Jun 2023 02:16:26 +0200 Message-ID: <20230616001631.463536-7-ojeda@kernel.org> In-Reply-To: <20230616001631.463536-1-ojeda@kernel.org> References: <20230616001631.463536-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1768816835708565893?= X-GMAIL-MSGID: =?utf-8?q?1768816835708565893?= |
Series |
`scripts/rust_is_available.sh` improvements
|
|
Commit Message
Miguel Ojeda
June 16, 2023, 12:16 a.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, explicitly check whether the expected variables
are set (`$RUSTC`, `$BINDGEN` and `$CC`). If not, print an explanation
about the fact that the script is meant to be called from Kbuild,
since that is the most likely cause for the variables not being set.
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 | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
Comments
On 6/15/23 21:16, Miguel Ojeda 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, explicitly check whether the expected variables > are set (`$RUSTC`, `$BINDGEN` and `$CC`). If not, print an explanation > about the fact that the script is meant to be called from Kbuild, > since that is the most likely cause for the variables not being set. > > Link: https://lore.kernel.org/oe-kbuild-all/Y6r4mXz5NS0+HVXo@zn.tnic/ [1] > Signed-off-by: Miguel Ojeda <ojeda@kernel.org> > --- > [...] Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
On Fri, Jun 16, 2023 at 02:16:26AM +0200, Miguel Ojeda 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, explicitly check whether the expected variables > are set (`$RUSTC`, `$BINDGEN` and `$CC`). If not, print an explanation > about the fact that the script is meant to be called from Kbuild, > since that is the most likely cause for the variables not being set. > > Link: https://lore.kernel.org/oe-kbuild-all/Y6r4mXz5NS0+HVXo@zn.tnic/ [1] > Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Reviewed-by: Nathan Chancellor <nathan@kernel.org> > --- > scripts/rust_is_available.sh | 29 +++++++++++++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh > index 1bdff4472cbe..7e0368babe64 100755 > --- a/scripts/rust_is_available.sh > +++ b/scripts/rust_is_available.sh > @@ -28,11 +28,40 @@ print_docs_reference() > echo >&2 "***" > } > > +# Print an explanation about the fact that the script is meant to be called from Kbuild. > +print_kbuild_explanation() > +{ > + 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." > + exit 1 > +} > + > # 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 expected environment variables are set. > +if [ -z "${RUSTC+x}" ]; then > + echo >&2 "***" > + echo >&2 "*** Environment variable 'RUSTC' is not set." > + print_kbuild_explanation > +fi > + > +if [ -z "${BINDGEN+x}" ]; then > + echo >&2 "***" > + echo >&2 "*** Environment variable 'BINDGEN' is not set." > + print_kbuild_explanation > +fi > + > +if [ -z "${CC+x}" ]; then > + echo >&2 "***" > + echo >&2 "*** Environment variable 'CC' is not set." > + print_kbuild_explanation > +fi > + > # Check that the Rust compiler exists. > if ! command -v "$RUSTC" >/dev/null; then > echo >&2 "***" > -- > 2.41.0 >
On Fri, Jun 16, 2023 at 9:17 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, explicitly check whether the expected variables > are set (`$RUSTC`, `$BINDGEN` and `$CC`). If not, print an explanation > about the fact that the script is meant to be called from Kbuild, > since that is the most likely cause for the variables not being set. > > 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 | 29 +++++++++++++++++++++++++++++ > 1 file changed, 29 insertions(+) > > diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh > index 1bdff4472cbe..7e0368babe64 100755 > --- a/scripts/rust_is_available.sh > +++ b/scripts/rust_is_available.sh > @@ -28,11 +28,40 @@ print_docs_reference() > echo >&2 "***" > } > > +# Print an explanation about the fact that the script is meant to be called from Kbuild. > +print_kbuild_explanation() > +{ > + 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." > + exit 1 > +} > + > # 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 expected environment variables are set. > +if [ -z "${RUSTC+x}" ]; then > + echo >&2 "***" > + echo >&2 "*** Environment variable 'RUSTC' is not set." > + print_kbuild_explanation > +fi So, you want to check whether RUSTC is set or unset. (that is, you allow a case where RUSTC is set, but empty. It will eventually fail with a different error message anyway.) $ ./scripts/rust_is_available.sh *** *** Environment variable 'RUSTC' is not set. *** *** This script is intended to be called from Kbuild. *** Please use the 'rustavailable' target to call it instead. *** Otherwise, the results may not be meaningful. *** *** Please see Documentation/rust/quick-start.rst for details *** on how to set up the Rust support. *** $ RUSTC= BINDGEN= CC= ./scripts/rust_is_available.sh *** *** Rust compiler '' could not be found. *** *** *** Please see Documentation/rust/quick-start.rst for details *** on how to set up the Rust support. *** I would rather check whether RUSTC is empty or not with simpler code. if [ -z "${RUSTC}" ]; then ... fi > + > +if [ -z "${BINDGEN+x}" ]; then > + echo >&2 "***" > + echo >&2 "*** Environment variable 'BINDGEN' is not set." > + print_kbuild_explanation > +fi > + > +if [ -z "${CC+x}" ]; then > + echo >&2 "***" > + echo >&2 "*** Environment variable 'CC' is not set." > + print_kbuild_explanation > +fi > + > # Check that the Rust compiler exists. > if ! command -v "$RUSTC" >/dev/null; then > echo >&2 "***" > -- > 2.41.0 >
diff --git a/scripts/rust_is_available.sh b/scripts/rust_is_available.sh index 1bdff4472cbe..7e0368babe64 100755 --- a/scripts/rust_is_available.sh +++ b/scripts/rust_is_available.sh @@ -28,11 +28,40 @@ print_docs_reference() echo >&2 "***" } +# Print an explanation about the fact that the script is meant to be called from Kbuild. +print_kbuild_explanation() +{ + 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." + exit 1 +} + # 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 expected environment variables are set. +if [ -z "${RUSTC+x}" ]; then + echo >&2 "***" + echo >&2 "*** Environment variable 'RUSTC' is not set." + print_kbuild_explanation +fi + +if [ -z "${BINDGEN+x}" ]; then + echo >&2 "***" + echo >&2 "*** Environment variable 'BINDGEN' is not set." + print_kbuild_explanation +fi + +if [ -z "${CC+x}" ]; then + echo >&2 "***" + echo >&2 "*** Environment variable 'CC' is not set." + print_kbuild_explanation +fi + # Check that the Rust compiler exists. if ! command -v "$RUSTC" >/dev/null; then echo >&2 "***"