Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2992262rwd; Fri, 16 Jun 2023 10:43:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7tlMNchxTREIY/VZ3V6AXVdMGlU7jKWwQnmc8nRLstPUpPQmgAI+2jzUI1ya5mP8pxdB5v X-Received: by 2002:a05:6a20:938f:b0:10c:322:72d5 with SMTP id x15-20020a056a20938f00b0010c032272d5mr3289318pzh.23.1686937415679; Fri, 16 Jun 2023 10:43:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686937415; cv=none; d=google.com; s=arc-20160816; b=zsx3y806MoPmaR6YyDKupwX8whz+dDRENu9/9wlopoNmYQnu7v9Wsr4KAJzDV3eSaY 2pzKXn8ZJYAWxr+DeQzCLsa71Lz7gAdzX3a8mx1sDfjdSQHvWS4WzQ9hziIblO2k2e/U d0aW3QqKzd4Ezrk/VTgy9+ii0Gn2aFjHYwu+8EA3W3Hud6USkP5xJIALWuQzF7ayv4gT iyygERU4cB7uJJeCxyiFsimI48AS63AeAJ2Wu0OA5ETPEHpBQBW3ER9AxGAnwGaSB4qW QnNg5ZGv147dCbof7vI6znrxAntZo1jV7eqKn3YkgjvC/q9bp5ScFXlD+qpkwSgKziYJ 3fGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=JvnGamZe2/Ev0ZQlnBRzxPhY5AIQULeFfuYQFVlOFG8=; b=L/TWwla4/fu5jzHRP6ZGHc4vhf33So/f8SAesOB+zKG5I3AwgzrElW8rsYlr1KpdS1 RQVEqVYfrBokJsZ/ldK4L6pJFy3BoJMZ6e7chVMunzqKP4XSZC2piU2oLN/kkPAsFScP gazkCGXM67TJBrNRfDYWKS21xiIg0Rvbxj1CBqY9n4F4fqZF8pkcbeWPkbHSUjcVvGpV nr8Kpp4OjTGaiWgEix1YjijJqLIi23SP4dPpaI2WVFih+MmdhUEdDu3TQ7DWt8NeWLXg cxyOswsNW/Xwe4dkFvVuFGFJkR2L56GmeWFCMHNublTr17DESg+KHlMZOldBJy8Dj8Vh M9Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="A5y/6F1W"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o29-20020a63731d000000b0055337ca9ce9si448612pgc.248.2023.06.16.10.43.24; Fri, 16 Jun 2023 10:43:35 -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="A5y/6F1W"; 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 S1346032AbjFPRNR (ORCPT + 99 others); Fri, 16 Jun 2023 13:13:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230327AbjFPRNQ (ORCPT ); Fri, 16 Jun 2023 13:13:16 -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 06BEDC5; Fri, 16 Jun 2023 10:13:15 -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 8F46761D3B; Fri, 16 Jun 2023 17:13:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2034EC433C0; Fri, 16 Jun 2023 17:13:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686935594; bh=CG0pIcow6H0crZQ3zE03Q7kny6rgdaTUlNK0ehlZr+M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=A5y/6F1WLHflgWpO/RYKbZZlKuxyJvRu6f55iCUWWhyIcyfp0jYkBnnB+SijlwJ6y R5fyU3JVx4E1QHwnbHSAoO9eJ24Pt5pyDC2pi1oRPK2+j7i4jHSEzFzNL4if8EqqTa gkmgmEaZ93hiPEjRA60cTrCpaS5GbE8JG8U5r8GcVzSb/ljh/NGkXW/dKaKpV5+HIG bsNjKIJT8Ybk0+Nf/Xe1Kl9uvDNnepKgxVvs1qmoo5sDyh3BmryroJoUBa/shXnoNo hPR2xeQqY/hxtVM8uaAPD4SMO+3JwBf5cqLVaItxieDYUXGsz2rW16Xro1/gUTLB3T gIc+tkhn96n5w== Date: Fri, 16 Jun 2023 10:13:11 -0700 From: Nathan Chancellor To: Miguel Ojeda Cc: Masahiro Yamada , Wedson Almeida Filho , Alex Gaynor , Nick Desaulniers , Nicolas Schier , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Alice Ryhl , Andreas Hindborg , linux-kbuild@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: Re: [PATCH v2 06/11] kbuild: rust_is_available: check that environment variables are set Message-ID: <20230616171311.GE3474164@dev-arch.thelio-3990X> References: <20230616001631.463536-1-ojeda@kernel.org> <20230616001631.463536-7-ojeda@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230616001631.463536-7-ojeda@kernel.org> 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Nathan Chancellor > --- > 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 >